Index: LMDZ5/branches/testing/DefLists/conv_param.data_NPv3.1
===================================================================
--- LMDZ5/branches/testing/DefLists/conv_param.data_NPv3.1	(revision 1707)
+++ LMDZ5/branches/testing/DefLists/conv_param.data_NPv3.1	(revision 1707)
@@ -0,0 +1,8 @@
+-40      dpbase (original: -40)
+150      pbcrit (original: 150)
+500      ptcrit (original: 500)
+0.01     sigdz (original: 0.01)
+0.15     spfac (original: 0.15)
+8000.    tau (original: 1800)
+1 flag_wb
+6. wbmax
Index: LMDZ5/branches/testing/DefLists/ep_param.data_NPv3.1
===================================================================
--- LMDZ5/branches/testing/DefLists/ep_param.data_NPv3.1	(revision 1707)
+++ LMDZ5/branches/testing/DefLists/ep_param.data_NPv3.1	(revision 1707)
@@ -0,0 +1,3 @@
+1 flag_epKEorig 
+0.0003 elcrit (original: 0.0011)
+-55         tlcrit (original: -55)
Index: LMDZ5/branches/testing/DefLists/physiq.def_L39_AR40.0
===================================================================
--- LMDZ5/branches/testing/DefLists/physiq.def_L39_AR40.0	(revision 1669)
+++ LMDZ5/branches/testing/DefLists/physiq.def_L39_AR40.0	(revision 1707)
@@ -99,6 +99,6 @@
 #ok_kzmin : calcul Kzmin dans la CL de surface
 ok_kzmin=y
-#couplage ou non avec la convection
-iflag_coupl=0 (0:AR4 et 1:nouvelle physique)
+#couplage ou non avec la convection (0:AR4 et 1:nouvelle physique)
+iflag_coupl=0 
 seuil_inversion=-0.08
 
Index: LMDZ5/branches/testing/DefLists/wake_param.data_NPv3.1
===================================================================
--- LMDZ5/branches/testing/DefLists/wake_param.data_NPv3.1	(revision 1707)
+++ LMDZ5/branches/testing/DefLists/wake_param.data_NPv3.1	(revision 1707)
@@ -0,0 +1,4 @@
+0.33        stark
+0.25        Alpk
+8.e-12      wdens
+4.          coefgw
Index: LMDZ5/branches/testing/arch/arch-CICLADifort.fcm
===================================================================
--- LMDZ5/branches/testing/arch/arch-CICLADifort.fcm	(revision 1669)
+++ LMDZ5/branches/testing/arch/arch-CICLADifort.fcm	(revision 1707)
@@ -4,5 +4,5 @@
 %MAKE                make
 %FPP_FLAGS           -P -traditional
-%FPP_DEF             NC_DOUBLE BLAS SGEMV=DGEMV SGEMM=DGEMM FFT_FFTW
+%FPP_DEF             NC_DOUBLE
 %BASE_FFLAGS         -real-size 64 -ip -mkl=parallel -fp-model precise -align common -mcmodel=large 
 %PROD_FFLAGS         -O2
@@ -12,4 +12,4 @@
 %OMP_FFLAGS          
 %BASE_LD             -mkl=parallel
-%MPI_LD              -L/usr/lib64/openmpi/1.4.3-ifort/lib -lmpi -lmkl_core -lfftw3
+%MPI_LD              -L/usr/lib64/openmpi/1.4.3-ifort/lib -lmpi -lmkl_core 
 %OMP_LD              
Index: LMDZ5/branches/testing/arch/arch-X64_ADA.fcm
===================================================================
--- LMDZ5/branches/testing/arch/arch-X64_ADA.fcm	(revision 1707)
+++ LMDZ5/branches/testing/arch/arch-X64_ADA.fcm	(revision 1707)
@@ -0,0 +1,17 @@
+%COMPILER            mpiifort
+%LINK                mpiifort
+%AR                  ar
+%MAKE                gmake
+%FPP_FLAGS           -P -traditional
+%FPP_DEF             NC_DOUBLE BLAS SGEMV=DGEMV SGEMM=DGEMM 
+%BASE_FFLAGS         -integer-size 32 -real-size 64 -align all 
+%PROD_FFLAGS         -O3 -ip 
+%DEV_FFLAGS          -p -g -O1 -fpe0 -traceback
+%DEBUG_FFLAGS        -p -g -O0 -no-ftz -traceback -ftrapuv -fp-stack-check -check -fpe0
+%MPI_FFLAGS
+%OMP_FFLAGS          -openmp
+%%%%BASE_LD             -lmkl_intel_lp64 -lmkl_sequential -lmkl_core
+%BASE_LD             -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lpthread
+%MPI_LD
+%OMP_LD              -openmp
+
Index: LMDZ5/branches/testing/arch/arch-X64_ADA.path
===================================================================
--- LMDZ5/branches/testing/arch/arch-X64_ADA.path	(revision 1707)
+++ LMDZ5/branches/testing/arch/arch-X64_ADA.path	(revision 1707)
@@ -0,0 +1,11 @@
+NETCDF_LIBDIR="${NETCDF_LDFLAGS:--L/smplocal/pub/NetCDF/4.1.3/lib -lnetcdff -lnetcdf}"
+NETCDF_INCDIR="${NETCDF_FFLAGS:--I/smplocal/pub/HDF5/1.8.9/seq/include -I/smplocal/pub/NetCDF/4.1.3/include}"
+IOIPSL_INCDIR=$LMDGCM/../../lib
+IOIPSL_LIBDIR=$LMDGCM/../../lib
+ORCH_INCDIR=$LMDGCM/../../lib
+ORCH_LIBDIR=$LMDGCM/../../lib
+OASIS_INCDIR=$LMDGCM/../../prism/X64/build/lib/psmile.$couple
+OASIS_LIBDIR=$LMDGCM/../../prism/X64/lib
+INCA_LIBDIR=$LMDGCM/../INCA/config/lib
+INCA_INCDIR=$LMDGCM/../INCA/config/lib
+
Index: LMDZ5/branches/testing/create_make_gcm
===================================================================
--- LMDZ5/branches/testing/create_make_gcm	(revision 1669)
+++ LMDZ5/branches/testing/create_make_gcm	(revision 1707)
@@ -96,5 +96,5 @@
 echo '	cd $(LOCAL_DIR); \'
 echo '	$(COMPILE90) $(LIBF)/$(DIRMAIN)/$(SOURCE) -o $(PROG).o ; \'
-echo '	$(LINK) $(PROG).o -L$(LIBO) $(L_DYN) $(L_ADJNT) $(L_COSP) $(L_FILTRE) $(L_PHY) $(L_DYN) $(L_BIBIO) $(L_DYN) $(OPLINK) $(OPTION_LINK) -o $(LOCAL_DIR)/$(PROG).e ; $(RM) $(PROG).o '
+echo '	$(LINK) $(PROG).o -L$(LIBO) $(L_DYN) $(L_ADJNT) $(L_COSP) $(L_PHY) $(L_DYN) $(L_BIBIO) $(L_DYN) $(L_FILTRE) $(OPLINK) $(OPTION_LINK) -o $(LOCAL_DIR)/$(PROG).e ; $(RM) $(PROG).o '
 echo
 echo 'dyn : $(LIBO)/libdyn$(DIM)d$(FLAG_PARA).a $(FILTRE)$(DIM)d'
@@ -224,5 +224,4 @@
          # Put generated object in library
          echo '	$(AR) r $(LIBO)/lib'$diri'.a '$fili'.o ; $(RM) '$fili'.o ; \'
-         echo '	cd $(GCM)'
 	 echo
       done
Index: LMDZ5/branches/testing/libf/bibio/new_unit.F90
===================================================================
--- LMDZ5/branches/testing/libf/bibio/new_unit.F90	(revision 1669)
+++ 	(revision )
@@ -1,25 +1,0 @@
-module new_unit_m
-
-  implicit none
-
-contains
-
-  subroutine new_unit(unit)
-
-    integer, intent(out):: unit
-
-    ! Variables local to the procedure:
-    logical opened, exist
-
-    !------------------------------------------------------
-
-    unit = 0
-    do
-       inquire(unit=unit, opened=opened, exist=exist)
-       if (exist .and. .not. opened) exit
-       unit = unit + 1
-    end do
-
-  end subroutine new_unit
-
-end module new_unit_m
Index: LMDZ5/branches/testing/libf/bibio/new_unit_m.F90
===================================================================
--- LMDZ5/branches/testing/libf/bibio/new_unit_m.F90	(revision 1707)
+++ LMDZ5/branches/testing/libf/bibio/new_unit_m.F90	(revision 1707)
@@ -0,0 +1,25 @@
+module new_unit_m
+
+  implicit none
+
+contains
+
+  subroutine new_unit(unit)
+
+    integer, intent(out):: unit
+
+    ! Variables local to the procedure:
+    logical opened, exist
+
+    !------------------------------------------------------
+
+    unit = 0
+    do
+       inquire(unit=unit, opened=opened, exist=exist)
+       if (exist .and. .not. opened) exit
+       unit = unit + 1
+    end do
+
+  end subroutine new_unit
+
+end module new_unit_m
Index: LMDZ5/branches/testing/libf/bibio/pchfe_95.F90
===================================================================
--- LMDZ5/branches/testing/libf/bibio/pchfe_95.F90	(revision 1669)
+++ 	(revision )
@@ -1,76 +1,0 @@
-module PCHFE_95_m
-
-  implicit none
-
-contains
-
-  SUBROUTINE PCHFE_95(X, F, D, SKIP, XE, FE, IERR)
-
-    ! PURPOSE  Evaluate a piecewise cubic Hermite function at an array of
-    !            points.  May be used by itself for Hermite interpolation,
-    !            or as an evaluator for PCHIM or PCHIC.
-    ! CATEGORY  E3
-    ! KEYWORDS  CUBIC HERMITE EVALUATION, HERMITE INTERPOLATION, PCHIP,
-    !             PIECEWISE CUBIC EVALUATION
-
-    !          PCHFE:  Piecewise Cubic Hermite Function Evaluator
-    ! Evaluates the cubic Hermite function defined by  X, F, D  at
-    ! the points  XE.
-
-    use assert_eq_m, only: assert_eq
-
-    REAL, intent(in):: X(:) ! real array of independent variable values
-    ! The elements of X must be strictly increasing.
-
-    REAL, intent(in):: F(:) ! real array of function values
-    ! F(I) is the value corresponding to X(I).
-
-    REAL, intent(in):: D(:) ! real array of derivative values
-    ! D(I) is the value corresponding to X(I).
-
-    LOGICAL, intent(inout):: SKIP 
-    ! request to skip checks for validity of "x"
-    ! If "skip" is false then "pchfe" will check that size(x) >= 2 and
-    ! "x" is in strictly ascending order.
-    ! Setting "skip" to true will save time in case these checks have
-    ! already been performed (say, in "PCHIM" or "PCHIC").
-    ! "SKIP" will be set to TRUE on normal return.
-
-    real, intent(in):: XE(:) ! points at which the function is to be evaluated
-    ! NOTES:
-    ! 1. The evaluation will be most efficient if the elements of XE
-    ! are increasing relative to X.
-    ! That is,   XE(J) .GE. X(I)
-    ! implies    XE(K) .GE. X(I),  all K.GE.J
-    ! 2. If any of the XE are outside the interval [X(1),X(N)], values
-    ! are extrapolated from the nearest extreme cubic, and a warning
-    ! error is returned.
-
-    real, intent(out):: FE(:) ! values of the cubic Hermite function
-    ! defined by X, F, D at the points XE
-
-    integer, intent(out):: IERR ! error flag
-    ! Normal return:
-    ! IERR = 0  no error
-    ! Warning error:
-    ! IERR > 0  means that extrapolation was performed at IERR points
-    ! "Recoverable" errors:
-    !              IERR = -1  if N < 2
-    !              IERR = -3  if the X-array is not strictly increasing
-    !              IERR = -4  if NE < 1
-    ! NOTE: The above errors are checked in the order listed, and
-    ! following arguments have **NOT** been validated.
-
-    ! Variables local to the procedure:
-
-    INTEGER  N, NE
-
-    !---------------------------------------
-
-    n = assert_eq(size(x), size(f), size(d), "PCHFE_95 n")
-    ne = assert_eq(size(xe), size(fe), "PCHFE_95 ne")
-    call PCHFE(N, X, F, D, 1, SKIP, NE, XE, FE, IERR)
-
-  end SUBROUTINE PCHFE_95
-
-end module PCHFE_95_m
Index: LMDZ5/branches/testing/libf/bibio/pchfe_95_m.F90
===================================================================
--- LMDZ5/branches/testing/libf/bibio/pchfe_95_m.F90	(revision 1707)
+++ LMDZ5/branches/testing/libf/bibio/pchfe_95_m.F90	(revision 1707)
@@ -0,0 +1,76 @@
+module PCHFE_95_m
+
+  implicit none
+
+contains
+
+  SUBROUTINE PCHFE_95(X, F, D, SKIP, XE, FE, IERR)
+
+    ! PURPOSE  Evaluate a piecewise cubic Hermite function at an array of
+    !            points.  May be used by itself for Hermite interpolation,
+    !            or as an evaluator for PCHIM or PCHIC.
+    ! CATEGORY  E3
+    ! KEYWORDS  CUBIC HERMITE EVALUATION, HERMITE INTERPOLATION, PCHIP,
+    !             PIECEWISE CUBIC EVALUATION
+
+    !          PCHFE:  Piecewise Cubic Hermite Function Evaluator
+    ! Evaluates the cubic Hermite function defined by  X, F, D  at
+    ! the points  XE.
+
+    use assert_eq_m, only: assert_eq
+
+    REAL, intent(in):: X(:) ! real array of independent variable values
+    ! The elements of X must be strictly increasing.
+
+    REAL, intent(in):: F(:) ! real array of function values
+    ! F(I) is the value corresponding to X(I).
+
+    REAL, intent(in):: D(:) ! real array of derivative values
+    ! D(I) is the value corresponding to X(I).
+
+    LOGICAL, intent(inout):: SKIP 
+    ! request to skip checks for validity of "x"
+    ! If "skip" is false then "pchfe" will check that size(x) >= 2 and
+    ! "x" is in strictly ascending order.
+    ! Setting "skip" to true will save time in case these checks have
+    ! already been performed (say, in "PCHIM" or "PCHIC").
+    ! "SKIP" will be set to TRUE on normal return.
+
+    real, intent(in):: XE(:) ! points at which the function is to be evaluated
+    ! NOTES:
+    ! 1. The evaluation will be most efficient if the elements of XE
+    ! are increasing relative to X.
+    ! That is,   XE(J) .GE. X(I)
+    ! implies    XE(K) .GE. X(I),  all K.GE.J
+    ! 2. If any of the XE are outside the interval [X(1),X(N)], values
+    ! are extrapolated from the nearest extreme cubic, and a warning
+    ! error is returned.
+
+    real, intent(out):: FE(:) ! values of the cubic Hermite function
+    ! defined by X, F, D at the points XE
+
+    integer, intent(out):: IERR ! error flag
+    ! Normal return:
+    ! IERR = 0  no error
+    ! Warning error:
+    ! IERR > 0  means that extrapolation was performed at IERR points
+    ! "Recoverable" errors:
+    !              IERR = -1  if N < 2
+    !              IERR = -3  if the X-array is not strictly increasing
+    !              IERR = -4  if NE < 1
+    ! NOTE: The above errors are checked in the order listed, and
+    ! following arguments have **NOT** been validated.
+
+    ! Variables local to the procedure:
+
+    INTEGER  N, NE
+
+    !---------------------------------------
+
+    n = assert_eq(size(x), size(f), size(d), "PCHFE_95 n")
+    ne = assert_eq(size(xe), size(fe), "PCHFE_95 ne")
+    call PCHFE(N, X, F, D, 1, SKIP, NE, XE, FE, IERR)
+
+  end SUBROUTINE PCHFE_95
+
+end module PCHFE_95_m
Index: LMDZ5/branches/testing/libf/bibio/pchsp_95.F90
===================================================================
--- LMDZ5/branches/testing/libf/bibio/pchsp_95.F90	(revision 1669)
+++ 	(revision )
@@ -1,116 +1,0 @@
-module pchsp_95_m
-
-  implicit none
-
-contains
-
-  function pchsp_95(x, f, ibeg, iend, vc_beg, vc_end)
-
-    ! PURPOSE: Set derivatives needed to determine the Hermite
-    ! representation of the cubic spline interpolant to given data,
-    ! with specified boundary conditions.
-
-    ! Part of the "pchip" package.
-
-    ! CATEGORY: E1A
-
-    ! KEYWORDS: cubic hermite interpolation, piecewise cubic
-    ! interpolation, spline interpolation
-
-    ! DESCRIPTION: "pchsp" stands for "Piecewise Cubic Hermite Spline"
-    ! Computes the Hermite representation of the cubic spline
-    ! interpolant to the data given in X and F satisfying the boundary
-    ! conditions specified by Ibeg, iend, vc_beg and VC_end.
-
-    ! The resulting piecewise cubic Hermite function may be evaluated
-    ! by "pchfe" or "pchfd".
-
-    ! NOTE: This is a modified version of C. de Boor's cubic spline
-    ! routine "cubspl".
-
-    ! REFERENCE: Carl de Boor, A Practical Guide to Splines, Springer,
-    ! 2001, pages 43-47
-
-    use assert_eq_m, only: assert_eq
-
-    real, intent(in):: x(:)
-    ! independent variable values
-    ! The elements of X must be strictly increasing:
-    !                X(I-1) < X(I),  I = 2...N.
-    !           (Error return if not.)
-    ! (error if size(x) < 2)
-
-    real, intent(in):: f(:)
-    !     dependent variable values to be interpolated
-    !  F(I) is value corresponding to X(I).
-
-    INTEGER, intent(in):: ibeg
-    !     desired boundary condition at beginning of data
-
-    !        IBEG = 0  to set pchsp_95(1) so that the third derivative is con-
-    !              tinuous at X(2).  This is the "not a knot" condition
-    !              provided by de Boor's cubic spline routine CUBSPL.
-    !              This is the default boundary condition.
-    !        IBEG = 1  if first derivative at X(1) is given in VC_BEG.
-    !        IBEG = 2  if second derivative at X(1) is given in VC_BEG.
-    !        IBEG = 3  to use the 3-point difference formula for pchsp_95(1).
-    !              (Reverts to the default boundary condition if size(x) < 3 .)
-    !        IBEG = 4  to use the 4-point difference formula for pchsp_95(1).
-    !              (Reverts to the default boundary condition if size(x) < 4 .)
-
-    !          NOTES:
-    !           1. An error return is taken if IBEG is out of range.
-    !           2. For the "natural" boundary condition, use IBEG=2 and
-    !              VC_BEG=0.
-
-    INTEGER, intent(in):: iend
-    !           IC(2) = IEND, desired condition at end of data.
-    !  IEND may take on the same values as IBEG, but applied to
-    !  derivative at X(N). In case IEND = 1 or 2, The value is given in VC_END.
-
-    !          NOTES:
-    !           1. An error return is taken if IEND is out of range.
-    !           2. For the "natural" boundary condition, use IEND=2 and
-    !              VC_END=0.
-
-    REAL, intent(in), optional:: vc_beg
-    ! desired boundary value, as indicated above.
-    !           VC_BEG need be set only if IBEG = 1 or 2 .
-
-    REAL, intent(in), optional:: vc_end
-    ! desired boundary value, as indicated above.
-    !           VC_END need be set only if Iend = 1 or 2 .
-
-    real pchsp_95(size(x))
-    ! derivative values at the data points
-    !           These values will determine the cubic spline interpolant
-    !           with the requested boundary conditions.
-    !           The value corresponding to X(I) is stored in
-    !                PCHSP_95(I),  I=1...N.
-
-    ! LOCAL VARIABLES:
-    real wk(2, size(x)) ! real array of working storage
-    INTEGER n ! number of data points
-    integer ierr, ic(2)
-    real vc(2)
-
-    !-------------------------------------------------------------------
-
-    n = assert_eq(size(x), size(f), "pchsp_95 n")
-    if ((ibeg == 1 .or. ibeg == 2) .and. .not. present(vc_beg)) then
-       print *, "vc_beg required for IBEG = 1 or 2"
-       stop 1
-    end if
-    if ((iend == 1 .or. iend == 2) .and. .not. present(vc_end)) then
-       print *, "vc_end required for IEND = 1 or 2"
-       stop 1
-    end if
-    ic = (/ibeg, iend/)
-    if (present(vc_beg)) vc(1) = vc_beg
-    if (present(vc_end)) vc(2) = vc_end
-    call PCHSP(IC, VC, N, X, F, pchsp_95, 1, WK, size(WK), IERR)
-    if (ierr /= 0) stop 1
-
-  END function pchsp_95
-
-end module pchsp_95_m
Index: LMDZ5/branches/testing/libf/bibio/pchsp_95_m.F90
===================================================================
--- LMDZ5/branches/testing/libf/bibio/pchsp_95_m.F90	(revision 1707)
+++ LMDZ5/branches/testing/libf/bibio/pchsp_95_m.F90	(revision 1707)
@@ -0,0 +1,116 @@
+module pchsp_95_m
+
+  implicit none
+
+contains
+
+  function pchsp_95(x, f, ibeg, iend, vc_beg, vc_end)
+
+    ! PURPOSE: Set derivatives needed to determine the Hermite
+    ! representation of the cubic spline interpolant to given data,
+    ! with specified boundary conditions.
+
+    ! Part of the "pchip" package.
+
+    ! CATEGORY: E1A
+
+    ! KEYWORDS: cubic hermite interpolation, piecewise cubic
+    ! interpolation, spline interpolation
+
+    ! DESCRIPTION: "pchsp" stands for "Piecewise Cubic Hermite Spline"
+    ! Computes the Hermite representation of the cubic spline
+    ! interpolant to the data given in X and F satisfying the boundary
+    ! conditions specified by Ibeg, iend, vc_beg and VC_end.
+
+    ! The resulting piecewise cubic Hermite function may be evaluated
+    ! by "pchfe" or "pchfd".
+
+    ! NOTE: This is a modified version of C. de Boor's cubic spline
+    ! routine "cubspl".
+
+    ! REFERENCE: Carl de Boor, A Practical Guide to Splines, Springer,
+    ! 2001, pages 43-47
+
+    use assert_eq_m, only: assert_eq
+
+    real, intent(in):: x(:)
+    ! independent variable values
+    ! The elements of X must be strictly increasing:
+    !                X(I-1) < X(I),  I = 2...N.
+    !           (Error return if not.)
+    ! (error if size(x) < 2)
+
+    real, intent(in):: f(:)
+    !     dependent variable values to be interpolated
+    !  F(I) is value corresponding to X(I).
+
+    INTEGER, intent(in):: ibeg
+    !     desired boundary condition at beginning of data
+
+    !        IBEG = 0  to set pchsp_95(1) so that the third derivative is con-
+    !              tinuous at X(2).  This is the "not a knot" condition
+    !              provided by de Boor's cubic spline routine CUBSPL.
+    !              This is the default boundary condition.
+    !        IBEG = 1  if first derivative at X(1) is given in VC_BEG.
+    !        IBEG = 2  if second derivative at X(1) is given in VC_BEG.
+    !        IBEG = 3  to use the 3-point difference formula for pchsp_95(1).
+    !              (Reverts to the default boundary condition if size(x) < 3 .)
+    !        IBEG = 4  to use the 4-point difference formula for pchsp_95(1).
+    !              (Reverts to the default boundary condition if size(x) < 4 .)
+
+    !          NOTES:
+    !           1. An error return is taken if IBEG is out of range.
+    !           2. For the "natural" boundary condition, use IBEG=2 and
+    !              VC_BEG=0.
+
+    INTEGER, intent(in):: iend
+    !           IC(2) = IEND, desired condition at end of data.
+    !  IEND may take on the same values as IBEG, but applied to
+    !  derivative at X(N). In case IEND = 1 or 2, The value is given in VC_END.
+
+    !          NOTES:
+    !           1. An error return is taken if IEND is out of range.
+    !           2. For the "natural" boundary condition, use IEND=2 and
+    !              VC_END=0.
+
+    REAL, intent(in), optional:: vc_beg
+    ! desired boundary value, as indicated above.
+    !           VC_BEG need be set only if IBEG = 1 or 2 .
+
+    REAL, intent(in), optional:: vc_end
+    ! desired boundary value, as indicated above.
+    !           VC_END need be set only if Iend = 1 or 2 .
+
+    real pchsp_95(size(x))
+    ! derivative values at the data points
+    !           These values will determine the cubic spline interpolant
+    !           with the requested boundary conditions.
+    !           The value corresponding to X(I) is stored in
+    !                PCHSP_95(I),  I=1...N.
+
+    ! LOCAL VARIABLES:
+    real wk(2, size(x)) ! real array of working storage
+    INTEGER n ! number of data points
+    integer ierr, ic(2)
+    real vc(2)
+
+    !-------------------------------------------------------------------
+
+    n = assert_eq(size(x), size(f), "pchsp_95 n")
+    if ((ibeg == 1 .or. ibeg == 2) .and. .not. present(vc_beg)) then
+       print *, "vc_beg required for IBEG = 1 or 2"
+       stop 1
+    end if
+    if ((iend == 1 .or. iend == 2) .and. .not. present(vc_end)) then
+       print *, "vc_end required for IEND = 1 or 2"
+       stop 1
+    end if
+    ic = (/ibeg, iend/)
+    if (present(vc_beg)) vc(1) = vc_beg
+    if (present(vc_end)) vc(2) = vc_end
+    call PCHSP(IC, VC, N, X, F, pchsp_95, 1, WK, size(WK), IERR)
+    if (ierr /= 0) stop 1
+
+  END function pchsp_95
+
+end module pchsp_95_m
Index: LMDZ5/branches/testing/libf/dyn3d/calfis.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3d/calfis.F	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3d/calfis.F	(revision 1707)
@@ -507,5 +507,5 @@
      .             debut_split,    !! firstcall 
      .             lafin_split,    !! lastcall
-     .             float(day_ini), !! pday <-- day_ini (dans temps.h)
+     .             jD_cur,         !! pday. see leapfrog
      .             jH_cur_split,   !! ptime "fraction of day"
      .             zdt_split,      !! ptimestep
Index: LMDZ5/branches/testing/libf/dyn3d/comconst.h
===================================================================
--- LMDZ5/branches/testing/libf/dyn3d/comconst.h	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3d/comconst.h	(revision 1707)
@@ -21,6 +21,7 @@
       REAL dtdiss ! (s) time step for the dissipation
       REAL rad ! (m) radius of the planet
-      REAL r ! Gas constant R=8.31 J.K-1.mol-1
-      REAL cpp   ! Cp
+      REAL r ! Reduced Gas constant r=R/mu
+             ! with R=8.31.. J.K-1.mol-1, mu: mol mass of atmosphere (kg/mol)
+      REAL cpp   ! Specific heat Cp (J.kg-1.K-1)
       REAL kappa ! kappa=R/Cp 
       REAL cotot
Index: LMDZ5/branches/testing/libf/dyn3d/comdissnew.h
===================================================================
--- LMDZ5/branches/testing/libf/dyn3d/comdissnew.h	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3d/comdissnew.h	(revision 1707)
@@ -12,8 +12,14 @@
 
       COMMON/comdissnew/ lstardis,nitergdiv,nitergrot,niterh,tetagdiv,  &
-     &                   tetagrot,tetatemp,coefdis 
+     &                   tetagrot,tetatemp,coefdis, vert_prof_dissip
 
       LOGICAL lstardis
       INTEGER nitergdiv, nitergrot, niterh
+
+      integer vert_prof_dissip ! vertical profile of horizontal dissipation
+!     Allowed values:
+!     0: rational fraction, function of pressure
+!     1: tanh of altitude
+
       REAL     tetagdiv, tetagrot,  tetatemp, coefdis
 
Index: LMDZ5/branches/testing/libf/dyn3d/conf_gcm.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3d/conf_gcm.F	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3d/conf_gcm.F	(revision 1707)
@@ -14,4 +14,6 @@
 #endif
       USE infotrac, ONLY : type_trac
+      use assert_m, only: assert
+
       IMPLICIT NONE
 c-----------------------------------------------------------------------
@@ -93,5 +95,6 @@
       CALL getin('lunout', lunout)
       IF (lunout /= 5 .and. lunout /= 6) THEN
-        OPEN(lunout,FILE='lmdz.out')
+        OPEN(UNIT=lunout,FILE='lmdz.out',ACTION='write', 
+     &          STATUS='unknown',FORM='formatted')
       ENDIF
 
@@ -173,8 +176,4 @@
 
 !Config  Key  = nsplit_phys
-!Config  Desc = nombre de pas par jour
-!Config  Def  = 1 
-!Config  Help = nombre de pas par jour (multiple de iperiod) (
-!Config          ici pour  dt = 1 min ) 
        nsplit_phys = 1 
        CALL getin('nsplit_phys',nsplit_phys)
@@ -625,5 +624,4 @@
       CALL getin('ok_dyn_ave',ok_dyn_ave) 
 
-
       write(lunout,*)' #########################################'
       write(lunout,*)' Configuration des parametres du gcm: '
@@ -635,4 +633,5 @@
       write(lunout,*)' day_step = ', day_step
       write(lunout,*)' iperiod = ', iperiod
+      write(lunout,*)' nsplit_phys = ', nsplit_phys
       write(lunout,*)' iconser = ', iconser
       write(lunout,*)' iecri = ', iecri
@@ -805,8 +804,8 @@
 !Config  Desc = sortie des transports zonaux dans la dynamique
 !Config  Def  = n 
-!Config  Help =  
+!Config  Help = Permet de mettre en route le calcul des transports 
 !Config          
-       ok_dynzon = .FALSE.
-       CALL getin('ok_dynzon',ok_dynzon) 
+      ok_dynzon = .FALSE. 
+      CALL getin('ok_dynzon',ok_dynzon) 
 
 !Config  Key  = ok_dyn_ins
@@ -838,5 +837,5 @@
         write(lunout,*)'STOP !!!'
         write(lunout,*)'use_filtre_fft n est pas implemente dans dyn3d'
-        STOP
+        STOP 1
       ENDIF
       
@@ -848,4 +847,9 @@
       ok_strato=.FALSE.
       CALL getin('ok_strato',ok_strato)
+
+      vert_prof_dissip = merge(1, 0, ok_strato .and. llm==39)
+      CALL getin('vert_prof_dissip', vert_prof_dissip)
+      call assert(vert_prof_dissip == 0 .or. vert_prof_dissip ==  1,
+     $     "bad value for vert_prof_dissip")
 
 !Config  Key  = ok_gradsfile
Index: LMDZ5/branches/testing/libf/dyn3d/etat0_netcdf.F90
===================================================================
--- LMDZ5/branches/testing/libf/dyn3d/etat0_netcdf.F90	(revision 1669)
+++ 	(revision )
@@ -1,530 +1,0 @@
-!
-! $Id$
-!
-!-------------------------------------------------------------------------------
-!
-SUBROUTINE etat0_netcdf(ib, masque, phis, letat0)
-!
-!-------------------------------------------------------------------------------
-! Purpose: Creates initial states
-!-------------------------------------------------------------------------------
-! Note: This routine is designed to work for Earth
-!-------------------------------------------------------------------------------
-  USE control_mod
-#ifdef CPP_EARTH
-  USE startvar
-  USE ioipsl
-  USE dimphy
-  USE infotrac
-  USE fonte_neige_mod
-  USE pbl_surface_mod
-  USE phys_state_var_mod
-  USE filtreg_mod
-  USE regr_lat_time_climoz_m, ONLY: regr_lat_time_climoz
-  USE conf_phys_m,            ONLY: conf_phys
-! For parameterization of ozone chemistry:
-  use regr_lat_time_coefoz_m, only: regr_lat_time_coefoz
-  use press_coefoz_m, only: press_coefoz
-  use regr_pr_o3_m, only: regr_pr_o3
-  USE netcdf, ONLY : NF90_OPEN, NF90_NOWRITE, NF90_CLOSE, NF90_NOERR
-#endif
-  IMPLICIT NONE
-!-------------------------------------------------------------------------------
-! Arguments:
-#include "dimensions.h"
-#include "paramet.h"
-#include "iniprint.h"
-  LOGICAL,                    INTENT(IN)    :: ib     ! barycentric interpolat.
-  REAL, DIMENSION(iip1,jjp1), INTENT(INOUT) :: masque ! land mask
-  REAL, DIMENSION(iip1,jjp1), INTENT(OUT)   :: phis   ! geopotentiel au sol
-  LOGICAL,                    INTENT(IN)    :: letat0 ! F: masque only required
-#ifndef CPP_EARTH
-  WRITE(lunout,*)'limit_netcdf: Earth-specific routine, needs Earth physics'
-#else
-!-------------------------------------------------------------------------------
-! Local variables:
-#include "comgeom2.h"
-#include "comvert.h"
-#include "comconst.h"
-#include "indicesol.h"
-#include "dimsoil.h"
-#include "temps.h"
-  REAL,    DIMENSION(klon)                 :: tsol, qsol
-  REAL,    DIMENSION(klon)                 :: sn, rugmer, run_off_lic_0
-  REAL,    DIMENSION(iip1,jjp1)            :: orog, rugo, psol
-  REAL,    DIMENSION(iip1,jjp1,llm+1)      :: p3d
-  REAL,    DIMENSION(iip1,jjp1,llm)        :: uvent, t3d, tpot, qsat, qd
-  REAL,    DIMENSION(iip1,jjm ,llm)        :: vvent
-  REAL,    DIMENSION(:,:,:,:), ALLOCATABLE :: q3d
-  REAL,    DIMENSION(klon,nbsrf)           :: qsolsrf, snsrf, evap
-  REAL,    DIMENSION(klon,nbsrf)           :: frugs, agesno
-  REAL,    DIMENSION(klon,nsoilmx,nbsrf)   :: tsoil
-
-!--- Local variables for sea-ice reading:
-  INTEGER                                  :: iml_lic, jml_lic, llm_tmp
-  INTEGER                                  :: ttm_tmp, iret, fid
-  INTEGER, DIMENSION(1)                    :: itaul
-  REAL,    DIMENSION(1)                    :: lev
-  REAL                                     :: date
-  REAL,    DIMENSION(:,:),   ALLOCATABLE   ::  lon_lic,  lat_lic, fraclic
-  REAL,    DIMENSION(:),     ALLOCATABLE   :: dlon_lic, dlat_lic
-  REAL,    DIMENSION(iip1,jjp1)            :: flic_tmp
-
-!--- Misc
-  CHARACTER(LEN=80)                        :: x, fmt
-  INTEGER                                  :: i, j, l, ji
-  REAL,    DIMENSION(iip1,jjp1,llm)        :: alpha, beta, pk, pls, y
-  REAL,    DIMENSION(ip1jmp1)              :: pks
-
-#include "comdissnew.h"
-#include "serre.h"
-#include "clesphys.h"
-
-  REAL,    DIMENSION(iip1,jjp1,llm)        :: masse
-  INTEGER :: itau, iday
-  REAL    :: xpn, xps, time, phystep
-  REAL,    DIMENSION(iim)                  :: xppn, xpps
-  REAL,    DIMENSION(ip1jmp1,llm)          :: pbaru, phi, w
-  REAL,    DIMENSION(ip1jm  ,llm)          :: pbarv
-  REAL,    DIMENSION(klon)                 :: fder
-
-!--- Local variables for ocean mask reading:
-  INTEGER :: nid_o2a, iml_omask, jml_omask
-  LOGICAL :: couple=.FALSE.
-  REAL,    DIMENSION(:,:), ALLOCATABLE ::  lon_omask, lat_omask, ocemask, ocetmp
-  REAL,    DIMENSION(:),   ALLOCATABLE :: dlon_omask,dlat_omask
-  REAL,    DIMENSION(klon)             :: ocemask_fi
-  INTEGER, DIMENSION(klon-2)           :: isst
-  REAL,    DIMENSION(iim,jjp1)         :: zx_tmp_2d
-  REAL    :: dummy
-  LOGICAL :: ok_newmicro, ok_journe, ok_mensuel, ok_instan, ok_hf
-  LOGICAL :: ok_LES, ok_ade, ok_aie, aerosol_couple, new_aod, callstats
-  INTEGER :: iflag_radia, flag_aerosol
-  REAL    :: bl95_b0, bl95_b1, fact_cldcon, facttemps, ratqsbas, ratqshaut
-  REAL    :: tau_ratqs
-  INTEGER :: iflag_cldcon, iflag_ratqs, iflag_coupl, iflag_clos, iflag_wake
-  INTEGER :: iflag_thermals, nsplit_thermals
-  INTEGER :: iflag_thermals_ed, iflag_thermals_optflux
-  REAL    :: tau_thermals, solarlong0,  seuil_inversion
-  INTEGER :: read_climoz ! read ozone climatology
-!  Allowed values are 0, 1 and 2
-!     0: do not read an ozone climatology
-!     1: read a single ozone climatology that will be used day and night
-!     2: read two ozone climatologies, the average day and night
-!     climatology and the daylight climatology
-!-------------------------------------------------------------------------------
-  REAL    :: alp_offset
-  logical found
-
-!--- Constants
-  pi     = 4. * ATAN(1.)
-  rad    = 6371229.
-  daysec = 86400.
-  omeg   = 2.*pi/daysec
-  g      = 9.8
-  kappa  = 0.2857143
-  cpp    = 1004.70885
-  preff  = 101325.
-  pa     = 50000.
-  jmp1   = jjm + 1
-
-!--- CONSTRUCT A GRID
-  CALL conf_phys(  ok_journe, ok_mensuel, ok_instan, ok_hf, ok_LES,     &
-                   callstats,                                           &
-                   solarlong0,seuil_inversion,                          &
-                   fact_cldcon, facttemps,ok_newmicro,iflag_radia,      &
-                   iflag_cldcon,                                        &
-                   iflag_ratqs,ratqsbas,ratqshaut,tau_ratqs,            &
-                   ok_ade, ok_aie, aerosol_couple,                      &
-                   flag_aerosol, new_aod,                               &
-                   bl95_b0, bl95_b1,                                    &
-                   read_climoz,                                         &
-                   alp_offset)
-
-! co2_ppm0 : initial value of atmospheric CO2 from .def file (co2_ppm value)
-  co2_ppm0 = co2_ppm
-
-  dtvr   = daysec/FLOAT(day_step)
-  WRITE(lunout,*)'dtvr',dtvr
-
-  CALL iniconst()
-  CALL inigeom()
-
-!--- Initializations for tracers
-  CALL infotrac_init
-  ALLOCATE(q3d(iip1,jjp1,llm,nqtot))
-
-  CALL inifilr()
-  CALL phys_state_var_init(read_climoz)
-
-  rlat(1) = ASIN(1.0)
-  DO j=2,jjm; rlat((j-2)*iim+2:(j-1)*iim+1)=rlatu(j);     END DO
-  rlat(klon) = - ASIN(1.0)
-  rlat(:)=rlat(:)*(180.0/pi)
-
-  rlon(1) = 0.0
-  DO j=2,jjm; rlon((j-2)*iim+2:(j-1)*iim+1)=rlonv(1:iim); END DO
-  rlon(klon) = 0.0
-  rlon(:)=rlon(:)*(180.0/pi)
-
-! For a coupled simulation, the ocean mask from ocean model is used to compute
-! the weights an to insure ocean fractions are the same for atmosphere and ocean
-! Otherwise, mask is created using Relief file.
-
-  WRITE(lunout,*)'Essai de lecture masque ocean'
-  iret = NF90_OPEN("o2a.nc", NF90_NOWRITE, nid_o2a)
-  IF(iret/=NF90_NOERR) THEN
-    WRITE(lunout,*)'ATTENTION!! pas de fichier o2a.nc trouve'
-    WRITE(lunout,*)'Run force'
-    x='masque'
-    masque(:,:)=0.0
-    CALL startget_phys2d(x, iip1, jjp1, rlonv, rlatu, masque, 0.0, jjm, &
-   &              rlonu, rlatv, ib)
-    WRITE(lunout,*)'MASQUE construit : Masque'
-    WRITE(lunout,'(97I1)') nINT(masque)
-    CALL gr_dyn_fi(1, iip1, jjp1, klon, masque, zmasq)
-    WHERE(   zmasq(:)<EPSFRA) zmasq(:)=0.
-    WHERE(1.-zmasq(:)<EPSFRA) zmasq(:)=1.
-  ELSE
-    WRITE(lunout,*)'ATTENTION!! fichier o2a.nc trouve'
-    WRITE(lunout,*)'Run couple'
-    couple=.true.
-    iret=NF90_CLOSE(nid_o2a)
-    CALL flininfo("o2a.nc", iml_omask, jml_omask, llm_tmp, ttm_tmp, nid_o2a)
-    IF(iml_omask/=iim .OR.jml_omask/=jjp1) THEN
-      WRITE(lunout,*)'Dimensions non compatibles pour masque ocean'
-      WRITE(lunout,*)'iim = ',iim,' iml_omask = ',iml_omask
-      WRITE(lunout,*)'jjp1 = ',jjp1,' jml_omask = ',jml_omask
-      CALL abort_gcm('etat0_netcdf','Dimensions non compatibles pour masque oc&
-     &ean',1)
-    END IF
-    ALLOCATE(   ocemask(iml_omask,jml_omask),   ocetmp(iml_omask,jml_omask))
-    ALLOCATE( lon_omask(iml_omask,jml_omask),lat_omask(iml_omask,jml_omask))
-    ALLOCATE(dlon_omask(iml_omask),         dlat_omask(jml_omask))
-    CALL flinopen("o2a.nc", .FALSE., iml_omask, jml_omask, llm_tmp, lon_omask,&
-   &              lat_omask, lev, ttm_tmp, itaul, date, dt, fid)
-    CALL flinget(fid, 'OceMask', iml_omask, jml_omask, llm_tmp, ttm_tmp, &
-   &              1, 1, ocetmp)
-    CALL flinclo(fid)
-    dlon_omask(1:iml_omask) = lon_omask(1:iml_omask,1)
-    dlat_omask(1:jml_omask) = lat_omask(1,1:jml_omask)
-    ocemask = ocetmp
-    IF(dlat_omask(1)<dlat_omask(jml_omask)) THEN
-      DO j=1,jml_omask
-        ocemask(:,j) = ocetmp(:,jml_omask-j+1)
-      END DO
-    END IF
-!
-! Ocean mask to physical grid
-!*******************************************************************************
-    WRITE(lunout,*)'ocemask '
-    WRITE(fmt,"(i4,'i1)')")iml_omask ; fmt='('//ADJUSTL(fmt)
-    WRITE(lunout,fmt)int(ocemask)
-    ocemask_fi(1)=ocemask(1,1)
-    DO j=2,jjm; ocemask_fi((j-2)*iim+2:(j-1)*iim+1)=ocemask(1:iim,j); END DO
-    ocemask_fi(klon)=ocemask(1,jjp1)
-    zmasq=1.-ocemask_fi
-  END IF
-
-  CALL gr_fi_dyn(1,klon,iip1,jjp1,zmasq,masque)
-
-  ! The startget calls need to be replaced by a call to restget to get the
-  ! values in the restart file
-  x = 'relief'; orog(:,:) = 0.0
-  CALL startget_phys2d(x,iip1,jjp1,rlonv,rlatu, orog, 0.0,jjm,rlonu,rlatv,ib,&
- &               masque)
-
-  x = 'rugosite'; rugo(:,:) = 0.0
-  CALL startget_phys2d(x,iip1,jjp1,rlonv,rlatu, rugo, 0.0,jjm, rlonu,rlatv,ib)
-!  WRITE(lunout,'(49I1)') INT(orog(:,:)*10)
-!  WRITE(lunout,'(49I1)') INT(rugo(:,:)*10)
-
-! Sub-surfaces initialization
-!*******************************************************************************
-  pctsrf=0.
-  x = 'psol'; psol(:,:) = 0.0
-  CALL startget_phys2d(x,iip1,jjp1,rlonv,rlatu,psol,0.0,jjm,rlonu,rlatv,ib)
-!  WRITE(lunout,*) 'PSOL :', psol(10,20)
-!  WRITE(lunout,*) ap(:), bp(:)
-
-! Mid-levels pressure computation
-!*******************************************************************************
-  CALL pression(ip1jmp1, ap, bp, psol, p3d)
-  if (pressure_exner) then
-    CALL exner_hyb(ip1jmp1, psol, p3d, alpha, beta, pks, pk, y)
-  else
-    CALL exner_milieu(ip1jmp1,psol,p3d,beta,pks,pk,y)
-  endif
-  pls(:,:,:)=preff*(pk(:,:,:)/cpp)**(1./kappa)
-!  WRITE(lunout,*) 'P3D :', p3d(10,20,:)
-!  WRITE(lunout,*) 'PK:',    pk(10,20,:)
-!  WRITE(lunout,*) 'PLS :', pls(10,20,:)
-
-  x = 'surfgeo'; phis(:,:) = 0.0
-  CALL startget_phys2d(x,iip1,jjp1,rlonv,rlatu,phis, 0.0,jjm, rlonu,rlatv,ib)
-
-  x = 'u';    uvent(:,:,:) = 0.0
-  CALL startget_dyn(x,rlonu,rlatu,pls,y,uvent,0.0,  &
- &                  rlonv,rlatv,ib)
-
-  x = 'v';    vvent(:,:,:) = 0.0
-  CALL startget_dyn(x, rlonv,rlatv,pls(:, :jjm, :),y(:, :jjm, :),vvent,0.0, &
- &                  rlonu,rlatu(:jjm),ib)
-
-  x = 't';    t3d(:,:,:) = 0.0
-  CALL startget_dyn(x,rlonv,rlatu,pls,y,t3d,0.0,    &
- &                  rlonu,rlatv,ib)
-
-  x = 'tpot'; tpot(:,:,:) = 0.0
-  CALL startget_dyn(x,rlonv,rlatu,pls,pk,tpot,0.0,  &
- &                  rlonu,rlatv,ib)
-
-  WRITE(lunout,*) 'T3D min,max:',minval(t3d(:,:,:)),maxval(t3d(:,:,:))
-  WRITE(lunout,*) 'PLS min,max:',minval(pls(:,:,:)),maxval(pls(:,:,:))
-
-! Humidity at saturation computation
-!*******************************************************************************
-  WRITE(lunout,*) 'avant q_sat'
-  CALL q_sat(llm*jjp1*iip1, t3d, pls, qsat)
-  WRITE(lunout,*) 'apres q_sat'
-  WRITE(lunout,*) 'QSAT min,max:',minval(qsat(:,:,:)),maxval(qsat(:,:,:))
-!  WRITE(lunout,*) 'QSAT :',qsat(10,20,:)
-
-  x = 'q';    qd (:,:,:) = 0.0
-  CALL startget_dyn(x,rlonv,rlatu,pls,qsat,qd,0.0, rlonu,rlatv,ib)
-  q3d(:,:,:,:) = 0.0 ; q3d(:,:,:,1) = qd(:,:,:)
-
-! Parameterization of ozone chemistry:
-! Look for ozone tracer:
-  i = 1
-  DO
-    found = tname(i)=="O3" .OR. tname(i)=="o3"
-    if (found .or. i == nqtot) exit
-    i = i + 1
-  end do
-  if (found) then
-    call regr_lat_time_coefoz
-    call press_coefoz
-    call regr_pr_o3(p3d, q3d(:, :, :, i))
-!   Convert from mole fraction to mass fraction:
-    q3d(:, :, :, i) = q3d(:, :, :, i)  * 48. / 29.
-  end if
-
-!--- OZONE CLIMATOLOGY
-  IF(read_climoz>=1) CALL regr_lat_time_climoz(read_climoz)
-
-  x = 'tsol'; tsol(:) = 0.0
-  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,tsol,0.0,jjm,rlonu,rlatv,ib)
-
-  x = 'qsol';  qsol(:) = 0.0
-  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,qsol,0.0,jjm,rlonu,rlatv,ib)
-
-  x = 'snow';  sn(:) = 0.0
-  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,sn,0.0,jjm,rlonu,rlatv,ib)
-
-  x = 'rads';  radsol(:) = 0.0
-  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,radsol,0.0,jjm,rlonu,rlatv,ib)
-
-  x = 'rugmer'; rugmer(:) = 0.0
-  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,rugmer,0.0,jjm,rlonu,rlatv,ib)
-
-  x = 'zmea';  zmea(:) = 0.0
-  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,zmea,0.0,jjm,rlonu,rlatv,ib)
-
-  x = 'zstd';  zstd(:) = 0.0
-  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,zstd,0.0,jjm,rlonu,rlatv,ib)
-
-  x = 'zsig';  zsig(:) = 0.0
-  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,zsig,0.0,jjm,rlonu,rlatv,ib)
-
-  x = 'zgam';  zgam(:) = 0.0
-  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,zgam,0.0,jjm,rlonu,rlatv,ib)
-
-  x = 'zthe';  zthe(:) = 0.0
-  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,zthe,0.0,jjm,rlonu,rlatv,ib)
-
-  x = 'zpic';  zpic(:) = 0.0
-  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,zpic,0.0,jjm,rlonu,rlatv,ib)
-
-  x = 'zval';  zval(:) = 0.0
-  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,zval,0.0,jjm,rlonu,rlatv,ib)
-
-!  WRITE(lunout,'(48I3)') 'TSOL :', INT(tsol(2:klon)-273)
-
-! Soil ice file reading for soil fraction and soil ice fraction
-!*******************************************************************************
-  CALL flininfo("landiceref.nc", iml_lic, jml_lic, llm_tmp, ttm_tmp, fid)
-  ALLOCATE( lat_lic(iml_lic,jml_lic),lon_lic(iml_lic, jml_lic))
-  ALLOCATE(dlat_lic(jml_lic),       dlon_lic(iml_lic))
-  ALLOCATE( fraclic(iml_lic,jml_lic))
-  CALL flinopen("landiceref.nc", .FALSE., iml_lic, jml_lic, llm_tmp,  &
- &               lon_lic, lat_lic, lev, ttm_tmp, itaul, date, dt, fid)
-  CALL flinget(fid, 'landice', iml_lic, jml_lic, llm_tmp, ttm_tmp, 1,1, fraclic)
-  CALL flinclo(fid)
-
-! Interpolation on model T-grid
-!*******************************************************************************
-  WRITE(lunout,*)'dimensions de landice iml_lic, jml_lic : ',iml_lic,jml_lic
-! conversion if coordinates are in degrees
-  IF(MAXVAL(lon_lic)>pi) lon_lic=lon_lic*pi/180.
-  IF(MAXVAL(lat_lic)>pi) lat_lic=lat_lic*pi/180.
-  dlon_lic(:)=lon_lic(:,1)
-  dlat_lic(:)=lat_lic(1,:)
-  CALL grille_m( iml_lic, jml_lic, dlon_lic, dlat_lic, fraclic, iim,jjp1,   &
- &               rlonv, rlatu, flic_tmp(1:iim,:) )
-  flic_tmp(iip1,:)=flic_tmp(1,:)
-
-!--- To the physical grid
-  CALL gr_dyn_fi(1, iip1, jjp1, klon, flic_tmp, pctsrf(:,is_lic))
-
-!--- Adequation with soil/sea mask
-  WHERE(pctsrf(:,is_lic)<EPSFRA) pctsrf(:,is_lic)=0. 
-  WHERE(zmasq(:)<EPSFRA)         pctsrf(:,is_lic)=0.
-  pctsrf(:,is_ter)=zmasq(:)
-  DO ji=1,klon
-    IF(zmasq(ji)>EPSFRA) THEN 
-      IF(pctsrf(ji,is_lic)>=zmasq(ji)) THEN
-        pctsrf(ji,is_lic)=zmasq(ji)
-        pctsrf(ji,is_ter)=0.
-      ELSE
-        pctsrf(ji,is_ter)=zmasq(ji)-pctsrf(ji,is_lic)
-        IF(pctsrf(ji,is_ter)<EPSFRA) THEN
-          pctsrf(ji,is_ter)=0.
-          pctsrf(ji,is_lic)=zmasq(ji)
-        END IF 
-      END IF 
-    END IF 
-  END DO 
-
-! sub-surface ocean and sea ice (sea ice set to zero for start)
-!*******************************************************************************
-  pctsrf(:,is_oce)=(1.-zmasq(:))
-  WHERE(pctsrf(:,is_oce)<EPSFRA) pctsrf(:,is_oce)=0.
-  IF(couple) pctsrf(:,is_oce)=ocemask_fi(:)
-  isst=0
-  WHERE(pctsrf(2:klon-1,is_oce)>0.) isst=1
-
-! It is checked that the sub-surfaces sum is equal to 1
-!*******************************************************************************
-  ji=COUNT((ABS(SUM(pctsrf(:,:),dim=2))-1.0)>EPSFRA)
-  IF(ji/=0) WRITE(lunout,*) 'pb repartition sous maille pour ',ji,' points'
-  CALL gr_fi_ecrit(1, klon, iim, jjp1, zmasq, zx_tmp_2d)
-!  WRITE(fmt,"(i3,')')")iim; fmt='(i'//ADJUSTL(fmt)
-!  WRITE(lunout,*)'zmasq = '
-!  WRITE(lunout,TRIM(fmt))NINT(zx_tmp_2d)
-  CALL gr_fi_dyn(1, klon, iip1, jjp1, zmasq, masque)
-  WRITE(fmt,"(i4,'i1)')")iip1 ; fmt='('//ADJUSTL(fmt)
-  WRITE(lunout,*) 'MASQUE construit : Masque'
-  WRITE(lunout,TRIM(fmt))NINT(masque(:,:))
-
-! Intermediate computation
-!*******************************************************************************
-  CALL massdair(p3d,masse)
-  WRITE(lunout,*)' ALPHAX ',alphax
-  DO l=1,llm
-    xppn(:)=aire(1:iim,1   )*masse(1:iim,1   ,l)
-    xpps(:)=aire(1:iim,jjp1)*masse(1:iim,jjp1,l)
-    xpn=SUM(xppn)/apoln
-    xps=SUM(xpps)/apols
-    masse(:,1   ,l)=xpn
-    masse(:,jjp1,l)=xps
-  END DO
-  q3d(iip1,:,:,:)=q3d(1,:,:,:)
-  phis(iip1,:) = phis(1,:)
-
-  IF(.NOT.letat0) RETURN
-
-! Writing
-!*******************************************************************************
-  CALL inidissip(lstardis,nitergdiv,nitergrot,niterh,tetagdiv,tetagrot,tetatemp)
-  WRITE(lunout,*)'sortie inidissip'
-  itau=0
-  itau_dyn=0
-  itau_phy=0
-  iday=dayref+itau/day_step
-  time=FLOAT(itau-(iday-dayref)*day_step)/day_step
-  IF(time>1.) THEN
-   time=time-1
-   iday=iday+1
-  END IF
-  day_ref=dayref
-  annee_ref=anneeref
-
-  CALL geopot( ip1jmp1, tpot, pk, pks, phis, phi )
-  WRITE(lunout,*)'sortie geopot'
-
-  CALL caldyn0( itau, uvent, vvent, tpot, psol, masse, pk, phis,               &
-                phi,  w, pbaru, pbarv, time+iday-dayref)
-  WRITE(lunout,*)'sortie caldyn0'     
-  CALL dynredem0( "start.nc", dayref, phis)
-  WRITE(lunout,*)'sortie dynredem0'
-  CALL dynredem1( "start.nc", 0.0, vvent, uvent, tpot, q3d, masse, psol)
-  WRITE(lunout,*)'sortie dynredem1' 
-
-! Physical initial state writting
-!*******************************************************************************
-  WRITE(lunout,*)'phystep ',dtvr,iphysiq,nbapp_rad
-  phystep   = dtvr * FLOAT(iphysiq)
-  radpas    = NINT (86400./phystep/ FLOAT(nbapp_rad) )
-  WRITE(lunout,*)'phystep =', phystep, radpas
-
-! Init: tsol, qsol, sn, evap, tsoil, rain_fall, snow_fall, solsw, sollw, frugs
-!*******************************************************************************
-  DO i=1,nbsrf; ftsol(:,i) = tsol; END DO
-  DO i=1,nbsrf; snsrf(:,i) = sn;   END DO
-  falb1(:,is_ter) = 0.08; falb1(:,is_lic) = 0.6
-  falb1(:,is_oce) = 0.5;  falb1(:,is_sic) = 0.6
-  falb2 = falb1
-  evap(:,:) = 0.
-  DO i=1,nbsrf; qsolsrf(:,i)=150.; END DO
-  DO i=1,nbsrf; DO j=1,nsoilmx; tsoil(:,j,i) = tsol; END DO; END DO
-  rain_fall = 0.; snow_fall = 0.
-  solsw = 165.;   sollw = -53.
-  t_ancien = 273.15
-  q_ancien = 0.
-  agesno = 0.
-  frugs(:,is_oce) = rugmer(:)
-  frugs(:,is_ter) = MAX(1.0e-05,zstd(:)*zsig(:)/2.0)
-  frugs(:,is_lic) = MAX(1.0e-05,zstd(:)*zsig(:)/2.0)
-  frugs(:,is_sic) = 0.001
-  fder = 0.0
-  clwcon = 0.0
-  rnebcon = 0.0
-  ratqs = 0.0
-  run_off_lic_0 = 0.0 
-  rugoro = 0.0
-
-! Before phyredem calling, surface modules and values to be saved in startphy.nc
-! are initialized
-!*******************************************************************************
-  dummy = 1.0
-  pbl_tke(:,:,:) = 1.e-8 
-  zmax0(:) = 40.
-  f0(:) = 1.e-5
-  ema_work1(:,:) = 0.
-  ema_work2(:,:) = 0.
-  wake_deltat(:,:) = 0.
-  wake_deltaq(:,:) = 0.
-  wake_s(:) = 0.
-  wake_cstar(:) = 0.
-  wake_fip(:) = 0.
-  wake_pe = 0.
-  fm_therm = 0.
-  entr_therm = 0.
-  detr_therm = 0.
-
-  CALL fonte_neige_init(run_off_lic_0)
-  CALL pbl_surface_init( qsol, fder, snsrf, qsolsrf, evap, frugs, agesno, tsoil )
-  CALL phyredem( "startphy.nc" )
-
-!  WRITE(lunout,*)'CCCCCCCCCCCCCCCCCC REACTIVER SORTIE VISU DANS ETAT0'
-!  WRITE(lunout,*)'entree histclo'
-  CALL histclo()
-
-#endif 
-!#endif of #ifdef CPP_EARTH
-  RETURN
-
-END SUBROUTINE etat0_netcdf
-!
-!-------------------------------------------------------------------------------
Index: LMDZ5/branches/testing/libf/dyn3d/fxhyp.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3d/fxhyp.F	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3d/fxhyp.F	(revision 1707)
@@ -68,4 +68,25 @@
        xzoom    = xzoomdeg * pi/180. 
 c
+       if (iim==1) then
+
+          rlonm025(1)=-pi/2.
+          rlonv(1)=0.
+          rlonu(1)=pi
+          rlonp025(1)=pi/2.
+          rlonm025(2)=rlonm025(1)+depi
+          rlonv(2)=rlonv(1)+depi
+          rlonu(2)=rlonu(1)+depi
+          rlonp025(2)=rlonp025(1)+depi
+
+          xprimm025(:)=1.
+          xprimv(:)=1.
+          xprimu(:)=1.
+          xprimp025(:)=1.
+          champmin=depi
+          champmax=depi
+          return
+
+       endif
+
            decalx   = .75
        IF( grossism.EQ.1..AND.scal180 )  THEN
@@ -286,8 +307,10 @@
 
 
+
        IF(ik.EQ.1.and.grossism.EQ.1.)  THEN
          xvrai(1)    = xvrai(iip1)-depi
          xxprim(1)   = xxprim(iip1)
        ENDIF
+
        DO i = 1 , iim
         xlon(i)     = xvrai(i)
Index: LMDZ5/branches/testing/libf/dyn3d/gcm.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3d/gcm.F	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3d/gcm.F	(revision 1707)
@@ -405,5 +405,5 @@
 
       CALL inidissip( lstardis, nitergdiv, nitergrot, niterh   ,
-     *                tetagdiv, tetagrot , tetatemp              )
+     *                tetagdiv, tetagrot , tetatemp, vert_prof_dissip)
 
 c-----------------------------------------------------------------------
@@ -433,6 +433,7 @@
 ! Physics:
 #ifdef CPP_PHYS
-         CALL iniphysiq(ngridmx,llm,daysec,day_ini,dtphys/nsplit_phys ,
-     ,                latfi,lonfi,airefi,zcufi,zcvfi,rad,g,r,cpp     )
+         CALL iniphysiq(ngridmx,llm,daysec,day_ini,dtphys/nsplit_phys,
+     &                latfi,lonfi,airefi,zcufi,zcvfi,rad,g,r,cpp,
+     &                iflag_phys)
 #endif
          call_iniphys=.false.
@@ -457,12 +458,4 @@
  301  FORMAT('1'/,15x,'run du ', i2,'/',i2,'/',i4)
  302  FORMAT('1'/,15x,'    au ', i2,'/',i2,'/',i4)
-#endif
-
-#ifdef CPP_PHYS
-! Create start file (startphy.nc) and boundary conditions (limit.nc) 
-! for the Earth verstion
-       if (iflag_phys>=100) then
-          call iniaqua(ngridmx,latfi,lonfi,iflag_phys)
-       endif
 #endif
 
Index: LMDZ5/branches/testing/libf/dyn3d/groupe.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3d/groupe.F	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3d/groupe.F	(revision 1707)
@@ -38,13 +38,21 @@
       integer i,j,l
 
-      logical firstcall
-      save firstcall
+      logical firstcall,groupe_ok
+      save firstcall,groupe_ok
 
       data firstcall/.true./
+      data groupe_ok/.true./
+
+      if (iim==1) then
+         groupe_ok=.false.
+      endif
 
       if (firstcall) then
-         if(mod(iim,2**ngroup).ne.0) stop'probleme du nombre ede point'
+         if (groupe_ok) then
+           if(mod(iim,2**ngroup).ne.0) stop'probleme du nombre de point'
+         endif
          firstcall=.false.
       endif
+
 
 c   Champs 1D
@@ -52,14 +60,12 @@
       call convflu(pbaru,pbarv,llm,zconvm)
 
-c
       call scopy(ijp1llm,zconvm,1,zconvmm,1)
       call scopy(ijmllm,pbarv,1,pbarvm,1)
 
-c
+      if (groupe_ok) then
       call groupeun(jjp1,llm,zconvmm)
       call groupeun(jjm,llm,pbarvm)
 
 c   Champs 3D
-
       do l=1,llm
          do j=2,jjm
@@ -74,4 +80,9 @@
          enddo
       enddo
+
+      else
+         pbarum(:,:,:)=pbaru(:,:,:)
+         pbarvm(:,:,:)=pbarv(:,:,:)
+      endif
 
 c    integration de la convergence de masse de haut  en bas ......
Index: LMDZ5/branches/testing/libf/dyn3d/inidissip.F90
===================================================================
--- LMDZ5/branches/testing/libf/dyn3d/inidissip.F90	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3d/inidissip.F90	(revision 1707)
@@ -3,5 +3,5 @@
 !
 SUBROUTINE inidissip ( lstardis,nitergdiv,nitergrot,niterh  , &
-     tetagdiv,tetagrot,tetatemp             )
+     tetagdiv,tetagrot,tetatemp, vert_prof_dissip)
   !=======================================================================
   !   initialisation de la dissipation horizontale
@@ -25,4 +25,10 @@
   INTEGER,INTENT(in) :: nitergdiv,nitergrot,niterh
   REAL,INTENT(in) :: tetagdiv,tetagrot,tetatemp
+
+  integer, INTENT(in):: vert_prof_dissip
+  ! Vertical profile of horizontal dissipation
+  ! Allowed values:
+  ! 0: rational fraction, function of pressure
+  ! 1: tanh of altitude
 
 ! Local variables:
@@ -167,5 +173,5 @@
   !   --------------------------------------------------
 
-  if (ok_strato .and. llm==39) then
+  if (vert_prof_dissip == 1) then
      do l=1,llm
         pseudoz=8.*log(preff/presnivs(l))
Index: LMDZ5/branches/testing/libf/dyn3d/leapfrog.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3d/leapfrog.F	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3d/leapfrog.F	(revision 1707)
@@ -383,4 +383,10 @@
            jD_cur = jD_ref + day_ini - day_ref +                        &
      &          itau/day_step
+
+           IF (planet_type .eq."generic") THEN
+              ! AS: we make jD_cur to be pday
+              jD_cur = int(day_ini + itau/day_step)
+           ENDIF
+
            jH_cur = jH_ref + start_time +                               &
      &              mod(itau,day_step)/float(day_step) 
Index: LMDZ5/branches/testing/libf/dyn3d/limit_netcdf.F90
===================================================================
--- LMDZ5/branches/testing/libf/dyn3d/limit_netcdf.F90	(revision 1669)
+++ 	(revision )
@@ -1,642 +1,0 @@
-!
-! $Id$
-!-------------------------------------------------------------------------------
-!
-SUBROUTINE limit_netcdf(interbar, extrap, oldice, masque)
-!
-!-------------------------------------------------------------------------------
-! Author : L. Fairhead, 27/01/94
-!-------------------------------------------------------------------------------
-! Purpose: Boundary conditions files building for new model using climatologies.
-!          Both grids have to be regular.
-!-------------------------------------------------------------------------------
-! Note: This routine is designed to work for Earth
-!-------------------------------------------------------------------------------
-! Modification history:
-!  * 23/03/1994: Z. X. Li
-!  *    09/1999: L. Fairhead (netcdf reading in LMDZ.3.3)
-!  *    07/2001: P. Le Van
-!  *    11/2009: L. Guez     (ozone day & night climatos, see etat0_netcdf.F90)
-!  *    12/2009: D. Cugnet   (f77->f90, calendars, files from coupled runs)
-!-------------------------------------------------------------------------------
-  USE control_mod
-#ifdef CPP_EARTH
-  USE dimphy
-  USE ioipsl,             ONLY : ioget_year_len
-  USE phys_state_var_mod, ONLY : pctsrf
-  USE netcdf,             ONLY : NF90_OPEN,    NF90_CREATE,  NF90_CLOSE,       &
-                   NF90_DEF_DIM, NF90_DEF_VAR, NF90_PUT_VAR, NF90_PUT_ATT,     &
-                   NF90_NOERR,   NF90_NOWRITE, NF90_DOUBLE,  NF90_GLOBAL,      &
-		   NF90_CLOBBER, NF90_ENDDEF,  NF90_UNLIMITED, NF90_FLOAT
-  USE inter_barxy_m, only: inter_barxy
-#endif
-  IMPLICIT NONE
-!-------------------------------------------------------------------------------
-! Arguments:
-#include "dimensions.h"
-#include "paramet.h"
-#include "iniprint.h"
-  LOGICAL,                    INTENT(IN) :: interbar ! barycentric interpolation
-  LOGICAL,                    INTENT(IN) :: extrap   ! SST extrapolation flag
-  LOGICAL,                    INTENT(IN) :: oldice   ! old way ice computation
-  REAL, DIMENSION(iip1,jjp1), INTENT(IN) :: masque   ! land mask
-#ifndef CPP_EARTH
-  CALL abort_gcm('limit_netcdf','Earth-specific routine, needs Earth physics',1)
-#else
-!-------------------------------------------------------------------------------
-! Local variables:
-#include "logic.h"
-#include "comvert.h"
-#include "comgeom2.h"
-#include "comconst.h"
-#include "indicesol.h"
-
-!--- INPUT NETCDF FILES NAMES --------------------------------------------------
-  CHARACTER(LEN=25) :: icefile, sstfile, dumstr
-  CHARACTER(LEN=25), PARAMETER :: famipsst='amipbc_sst_1x1.nc        ',        &
-                                  famipsic='amipbc_sic_1x1.nc        ',        &
-                                  fcpldsst='cpl_atm_sst.nc           ',        &
-                                  fcpldsic='cpl_atm_sic.nc           ',        &
-                                  fhistsst='histmth_sst.nc           ',        &
-                                  fhistsic='histmth_sic.nc           ',        &
-                                  frugo   ='Rugos.nc                 ',        &
-                                  falbe   ='Albedo.nc                '
-  CHARACTER(LEN=10) :: varname
-!--- OUTPUT VARIABLES FOR NETCDF FILE ------------------------------------------
-  REAL,   DIMENSION(klon)                :: fi_ice, verif
-  REAL,   DIMENSION(:,:),   POINTER      :: phy_rug=>NULL(), phy_ice=>NULL()
-  REAL,   DIMENSION(:,:),   POINTER      :: phy_sst=>NULL(), phy_alb=>NULL()
-  REAL,   DIMENSION(:,:),   ALLOCATABLE  :: phy_bil
-  REAL,   DIMENSION(:,:,:), ALLOCATABLE  :: pctsrf_t
-  INTEGER                                :: nbad
-
-!--- VARIABLES FOR OUTPUT FILE WRITING -----------------------------------------
-  INTEGER :: ierr, nid, ndim, ntim, k
-  INTEGER, DIMENSION(2) :: dims
-  INTEGER :: id_tim,  id_SST,  id_BILS, id_RUG, id_ALB
-  INTEGER :: id_FOCE, id_FSIC, id_FTER, id_FLIC
-  INTEGER :: NF90_FORMAT
-  INTEGER :: ndays                   !--- Depending on the output calendar
-
-!--- INITIALIZATIONS -----------------------------------------------------------
-#ifdef NC_DOUBLE
-  NF90_FORMAT=NF90_DOUBLE
-#else
-  NF90_FORMAT=NF90_FLOAT
-#endif
-
-  pi    = 4.*ATAN(1.)
-  rad   = 6371229.
-  daysec= 86400.
-  omeg  = 2.*pi/daysec
-  g     = 9.8
-  kappa = 0.2857143
-  cpp   = 1004.70885
-  dtvr  = daysec/REAL(day_step)
-  CALL inigeom
-
-!--- Beware: anneeref (from gcm.def) is used to determine output time sampling
-  ndays=ioget_year_len(anneeref)
-
-!--- RUGOSITY TREATMENT --------------------------------------------------------
-  IF (prt_level>1) WRITE(lunout,*) 'Traitement de la rugosite'
-  varname='RUGOS'
-  CALL get_2Dfield(frugo,varname,'RUG',interbar,ndays,phy_rug,mask=masque(1:iim,:))
-
-!--- OCEAN TREATMENT -----------------------------------------------------------
-  IF (prt_level>1) WRITE(lunout,*) 'Traitement de la glace oceanique'
-
-! Input SIC file selection
-! Open file only to test if available
-  IF ( NF90_OPEN(TRIM(famipsic),NF90_NOWRITE,nid)==NF90_NOERR ) THEN
-     icefile=TRIM(famipsic)
-     varname='sicbcs'
-  ELSE IF( NF90_OPEN(TRIM(fcpldsic),NF90_NOWRITE,nid)==NF90_NOERR ) THEN
-     icefile=TRIM(fcpldsic)
-     varname='SIICECOV'
-  ELSE IF ( NF90_OPEN(TRIM(fhistsic),NF90_NOWRITE,nid)==NF90_NOERR ) THEN
-     icefile=TRIM(fhistsic)
-     varname='pourc_sic'
-  ELSE
-     WRITE(lunout,*) 'ERROR! No sea-ice input file was found.'
-     WRITE(lunout,*) 'One of following files must be availible : ',trim(famipsic),', ',trim(fcpldsic),', ',trim(fhistsic)
-     CALL abort_gcm('limit_netcdf','No sea-ice file was found',1)
-  END IF
-  ierr=NF90_CLOSE(nid)
-  IF (prt_level>=0) WRITE(lunout,*)'Pour la glace de mer a ete choisi le fichier '//TRIM(icefile)
-
-  CALL get_2Dfield(icefile,varname, 'SIC',interbar,ndays,phy_ice,flag=oldice)
-
-  ALLOCATE(pctsrf_t(klon,nbsrf,ndays))
-  DO k=1,ndays
-     fi_ice=phy_ice(:,k)
-     WHERE(fi_ice>=1.0  ) fi_ice=1.0
-     WHERE(fi_ice<EPSFRA) fi_ice=0.0
-     pctsrf_t(:,is_ter,k)=pctsrf(:,is_ter)       ! land soil
-     pctsrf_t(:,is_lic,k)=pctsrf(:,is_lic)       ! land ice
-     IF (icefile==trim(fcpldsic)) THEN           ! SIC=pICE*(1-LIC-TER)
-        pctsrf_t(:,is_sic,k)=fi_ice(:)*(1.-pctsrf(:,is_lic)-pctsrf(:,is_ter))
-     ELSE IF (icefile==trim(fhistsic)) THEN      ! SIC=pICE
-        pctsrf_t(:,is_sic,k)=fi_ice(:)
-     ELSE ! icefile==famipsic                    ! SIC=pICE-LIC
-        pctsrf_t(:,is_sic,k)=fi_ice-pctsrf_t(:,is_lic,k)
-     END IF
-     WHERE(pctsrf_t(:,is_sic,k)<=0) pctsrf_t(:,is_sic,k)=0.
-     WHERE(1.0-zmasq<EPSFRA)
-        pctsrf_t(:,is_sic,k)=0.0
-        pctsrf_t(:,is_oce,k)=0.0
-     ELSEWHERE
-        WHERE(pctsrf_t(:,is_sic,k)>=1.0-zmasq)
-           pctsrf_t(:,is_sic,k)=1.0-zmasq
-           pctsrf_t(:,is_oce,k)=0.0
-        ELSEWHERE
-           pctsrf_t(:,is_oce,k)=1.0-zmasq-pctsrf_t(:,is_sic,k)
-           WHERE(pctsrf_t(:,is_oce,k)<EPSFRA)
-              pctsrf_t(:,is_oce,k)=0.0
-              pctsrf_t(:,is_sic,k)=1.0-zmasq
-           END WHERE
-        END WHERE
-     END WHERE
-     nbad=COUNT(pctsrf_t(:,is_oce,k)<0.0)
-     IF(nbad>0) WRITE(lunout,*) 'pb sous maille pour nb point = ',nbad
-     nbad=COUNT(abs(sum(pctsrf_t(:,:,k),dim=2)-1.0)>EPSFRA)
-     IF(nbad>0) WRITE(lunout,*) 'pb sous surface pour nb points = ',nbad
-  END DO
-  DEALLOCATE(phy_ice)
-
-!--- SST TREATMENT -------------------------------------------------------------
-  IF (prt_level>1) WRITE(lunout,*) 'Traitement de la sst'
-
-! Input SST file selection
-! Open file only to test if available
-  IF ( NF90_OPEN(TRIM(famipsst),NF90_NOWRITE,nid)==NF90_NOERR ) THEN
-     sstfile=TRIM(famipsst)
-     varname='tosbcs'
-  ELSE IF ( NF90_OPEN(TRIM(fcpldsst),NF90_NOWRITE,nid)==NF90_NOERR ) THEN
-     sstfile=TRIM(fcpldsst)
-     varname='SISUTESW'
-  ELSE IF ( NF90_OPEN(TRIM(fhistsst),NF90_NOWRITE,nid)==NF90_NOERR ) THEN
-     sstfile=TRIM(fhistsst)
-     varname='tsol_oce'
-  ELSE
-     WRITE(lunout,*) 'ERROR! No sst input file was found.'
-     WRITE(lunout,*) 'One of following files must be availible : ',trim(famipsst),trim(fcpldsst),trim(fhistsst)
-     CALL abort_gcm('limit_netcdf','No sst file was found',1)
-  END IF
-  ierr=NF90_CLOSE(nid)
-  IF (prt_level>=0) WRITE(lunout,*)'Pour la temperature de mer a ete choisi un fichier '//TRIM(sstfile)
-
-  CALL get_2Dfield(sstfile,varname,'SST',interbar,ndays,phy_sst,flag=extrap)
-
-!--- ALBEDO TREATMENT ----------------------------------------------------------
-  IF (prt_level>1) WRITE(lunout,*) 'Traitement de l albedo'
-  varname='ALBEDO'
-  CALL get_2Dfield(falbe,varname,'ALB',interbar,ndays,phy_alb)
-
-!--- REFERENCE GROUND HEAT FLUX TREATMENT --------------------------------------
-  ALLOCATE(phy_bil(klon,ndays)); phy_bil=0.0
-
-!--- OUTPUT FILE WRITING -------------------------------------------------------
-  IF (prt_level>5) WRITE(lunout,*) 'Ecriture du fichier limit : debut'
-
-  !--- File creation
-  ierr=NF90_CREATE("limit.nc",NF90_CLOBBER,nid)
-  ierr=NF90_PUT_ATT(nid,NF90_GLOBAL,"title","Fichier conditions aux limites")
-
-  !--- Dimensions creation
-  ierr=NF90_DEF_DIM(nid,"points_physiques",klon,ndim)
-  ierr=NF90_DEF_DIM(nid,"time",NF90_UNLIMITED,ntim)
-
-  dims=(/ndim,ntim/)
-
-  !--- Variables creation
-  ierr=NF90_DEF_VAR(nid,"TEMPS",NF90_FORMAT,(/ntim/),id_tim)
-  ierr=NF90_DEF_VAR(nid,"FOCE", NF90_FORMAT,dims,id_FOCE)
-  ierr=NF90_DEF_VAR(nid,"FSIC", NF90_FORMAT,dims,id_FSIC)
-  ierr=NF90_DEF_VAR(nid,"FTER", NF90_FORMAT,dims,id_FTER)
-  ierr=NF90_DEF_VAR(nid,"FLIC", NF90_FORMAT,dims,id_FLIC)
-  ierr=NF90_DEF_VAR(nid,"SST",  NF90_FORMAT,dims,id_SST)
-  ierr=NF90_DEF_VAR(nid,"BILS", NF90_FORMAT,dims,id_BILS)
-  ierr=NF90_DEF_VAR(nid,"ALB",  NF90_FORMAT,dims,id_ALB)
-  ierr=NF90_DEF_VAR(nid,"RUG",  NF90_FORMAT,dims,id_RUG)
-
-  !--- Attributes creation
-  ierr=NF90_PUT_ATT(nid,id_tim, "title","Jour dans l annee")
-  ierr=NF90_PUT_ATT(nid,id_FOCE,"title","Fraction ocean")
-  ierr=NF90_PUT_ATT(nid,id_FSIC,"title","Fraction glace de mer")
-  ierr=NF90_PUT_ATT(nid,id_FTER,"title","Fraction terre")
-  ierr=NF90_PUT_ATT(nid,id_FLIC,"title","Fraction land ice")
-  ierr=NF90_PUT_ATT(nid,id_SST ,"title","Temperature superficielle de la mer")
-  ierr=NF90_PUT_ATT(nid,id_BILS,"title","Reference flux de chaleur au sol")
-  ierr=NF90_PUT_ATT(nid,id_ALB, "title","Albedo a la surface")
-  ierr=NF90_PUT_ATT(nid,id_RUG, "title","Rugosite")
-
-  ierr=NF90_ENDDEF(nid)
-
-  !--- Variables saving
-  ierr=NF90_PUT_VAR(nid,id_tim,(/(REAL(k),k=1,ndays)/))
-  ierr=NF90_PUT_VAR(nid,id_FOCE,pctsrf_t(:,is_oce,:),(/1,1/),(/klon,ndays/))
-  ierr=NF90_PUT_VAR(nid,id_FSIC,pctsrf_t(:,is_sic,:),(/1,1/),(/klon,ndays/))
-  ierr=NF90_PUT_VAR(nid,id_FTER,pctsrf_t(:,is_ter,:),(/1,1/),(/klon,ndays/))
-  ierr=NF90_PUT_VAR(nid,id_FLIC,pctsrf_t(:,is_lic,:),(/1,1/),(/klon,ndays/))
-  ierr=NF90_PUT_VAR(nid,id_SST ,phy_sst(:,:),(/1,1/),(/klon,ndays/))
-  ierr=NF90_PUT_VAR(nid,id_BILS,phy_bil(:,:),(/1,1/),(/klon,ndays/))
-  ierr=NF90_PUT_VAR(nid,id_ALB ,phy_alb(:,:),(/1,1/),(/klon,ndays/))
-  ierr=NF90_PUT_VAR(nid,id_RUG ,phy_rug(:,:),(/1,1/),(/klon,ndays/))
-
-  ierr=NF90_CLOSE(nid)
-
-  IF (prt_level>5) WRITE(lunout,*) 'Ecriture du fichier limit : fin'
-
-  DEALLOCATE(pctsrf_t,phy_sst,phy_bil,phy_alb,phy_rug)
-
-
-!===============================================================================
-!
-  CONTAINS
-!
-!===============================================================================
-
-
-!-------------------------------------------------------------------------------
-!
-SUBROUTINE get_2Dfield(fnam, varname, mode, ibar, ndays, champo, flag, mask)
-!
-!-----------------------------------------------------------------------------
-! Comments:
-!   There are two assumptions concerning the NetCDF files, that are satisfied
-!   with files that are conforming NC convention:
-!     1) The last dimension of the variables used is the time record.
-!     2) Dimensional variables have the same names as corresponding dimensions.
-!-----------------------------------------------------------------------------
-  USE netcdf, ONLY: NF90_OPEN, NF90_INQ_VARID, NF90_INQUIRE_VARIABLE, &
-       NF90_CLOSE, NF90_INQ_DIMID, NF90_INQUIRE_DIMENSION, NF90_GET_VAR, &
-       NF90_GET_ATT
-  USE dimphy, ONLY : klon
-  USE phys_state_var_mod, ONLY : pctsrf
-  USE control_mod
-  use pchsp_95_m, only: pchsp_95
-  use pchfe_95_m, only: pchfe_95
-  use arth_m, only: arth
-
-  IMPLICIT NONE
-#include "dimensions.h"
-#include "paramet.h"
-#include "comgeom2.h"
-#include "indicesol.h"
-#include "iniprint.h"
-!-----------------------------------------------------------------------------
-! Arguments:
-  CHARACTER(LEN=*),  INTENT(IN)     :: fnam     ! NetCDF file name
-  CHARACTER(LEN=10), INTENT(IN)     :: varname  ! NetCDF variable name
-  CHARACTER(LEN=3),  INTENT(IN)     :: mode     ! RUG, SIC, SST or ALB
-  LOGICAL,           INTENT(IN)     :: ibar     ! interp on pressure levels
-  INTEGER,           INTENT(IN)     :: ndays    ! current year number of days
-  REAL,    POINTER,  DIMENSION(:, :) :: champo  ! output field = f(t)
-  LOGICAL, OPTIONAL, INTENT(IN)     :: flag     ! extrapol. (SST) old ice (SIC)
-  REAL,    OPTIONAL, DIMENSION(iim, jjp1), INTENT(IN) :: mask
-!------------------------------------------------------------------------------
-! Local variables:
-!--- NetCDF
-  INTEGER :: ncid, varid                  ! NetCDF identifiers
-  CHARACTER(LEN=30)               :: dnam       ! dimension name
-!--- dimensions
-  INTEGER,           DIMENSION(4) :: dids       ! NetCDF dimensions identifiers
-  REAL, ALLOCATABLE, DIMENSION(:) :: dlon_ini   ! initial longitudes vector
-  REAL, ALLOCATABLE, DIMENSION(:) :: dlat_ini   ! initial latitudes  vector
-  REAL, POINTER,     DIMENSION(:) :: dlon, dlat ! reordered lon/lat  vectors
-!--- fields
-  INTEGER :: imdep, jmdep, lmdep                ! dimensions of 'champ'
-  REAL, ALLOCATABLE, DIMENSION(:, :) :: champ   ! wanted field on initial grid
-  REAL, ALLOCATABLE, DIMENSION(:) :: yder, timeyear
-  REAL,              DIMENSION(iim, jjp1) :: champint   ! interpolated field
-  REAL, ALLOCATABLE, DIMENSION(:, :, :)    :: champtime
-  REAL, ALLOCATABLE, DIMENSION(:, :, :)    :: champan
-!--- input files
-  CHARACTER(LEN=20)                 :: cal_in   ! calendar
-  CHARACTER(LEN=20)                 :: unit_sic ! attribute unit in sea-ice file
-  INTEGER                           :: ndays_in ! number of days
-!--- misc
-  INTEGER :: i, j, k, l                         ! loop counters
-  REAL, ALLOCATABLE, DIMENSION(:, :) :: work     ! used for extrapolation
-  CHARACTER(LEN=25)                 :: title    ! for messages
-  LOGICAL                           :: extrp    ! flag for extrapolation
-  LOGICAL                           :: oldice   ! flag for old way ice computation 
-  REAL                              :: chmin, chmax
-  INTEGER ierr
-  integer n_extrap ! number of extrapolated points
-  logical skip
-
-!------------------------------------------------------------------------------
-!---Variables depending on keyword 'mode' -------------------------------------
-  NULLIFY(champo)
-
-  SELECT CASE(mode)
-  CASE('RUG'); title='Rugosite'
-  CASE('SIC'); title='Sea-ice'
-  CASE('SST'); title='SST'
-  CASE('ALB'); title='Albedo'
-  END SELECT
-  
-
-  extrp=.FALSE. 
-  oldice=.FALSE.
-  IF ( PRESENT(flag) ) THEN 
-    IF ( flag .AND. mode=='SST' ) extrp=.TRUE. 
-    IF ( flag .AND. mode=='SIC' ) oldice=.TRUE. 
-  END IF
-
-!--- GETTING SOME DIMENSIONAL VARIABLES FROM FILE -----------------------------
-  IF (prt_level>5) WRITE(lunout,*) ' Now reading file : ',fnam
-  ierr=NF90_OPEN(fnam, NF90_NOWRITE, ncid);             CALL ncerr(ierr, fnam)
-  ierr=NF90_INQ_VARID(ncid, trim(varname), varid);            CALL ncerr(ierr, fnam)
-  ierr=NF90_INQUIRE_VARIABLE(ncid, varid, dimids=dids); CALL ncerr(ierr, fnam)
-
-!--- Read unit for sea-ice variable only
-  IF (mode=='SIC') THEN
-     ierr=NF90_GET_ATT(ncid, varid, 'units', unit_sic)
-     IF(ierr/=NF90_NOERR) THEN
-        IF (prt_level>5) WRITE(lunout,*) 'No unit was given in sea-ice file. Take percentage as default value'
-        unit_sic='X'
-     ELSE
-        IF (prt_level>5) WRITE(lunout,*) ' Sea-ice cover has unit=',unit_sic
-     END IF
-  END IF
-
-!--- Longitude
-  ierr=NF90_INQUIRE_DIMENSION(ncid, dids(1), name=dnam, len=imdep)
-  CALL ncerr(ierr, fnam); ALLOCATE(dlon_ini(imdep), dlon(imdep))
-  ierr=NF90_INQ_VARID(ncid, dnam, varid);                CALL ncerr(ierr, fnam)
-  ierr=NF90_GET_VAR(ncid, varid, dlon_ini);              CALL ncerr(ierr, fnam)
-  IF (prt_level>5) WRITE(lunout, *) 'variable ', dnam, 'dimension ', imdep
-
-!--- Latitude
-  ierr=NF90_INQUIRE_DIMENSION(ncid, dids(2), name=dnam, len=jmdep)
-  CALL ncerr(ierr, fnam); ALLOCATE(dlat_ini(jmdep), dlat(jmdep))
-  ierr=NF90_INQ_VARID(ncid, dnam, varid);                CALL ncerr(ierr, fnam)
-  ierr=NF90_GET_VAR(ncid, varid, dlat_ini);              CALL ncerr(ierr, fnam)
-  IF (prt_level>5) WRITE(lunout, *) 'variable ', dnam, 'dimension ', jmdep
-
-!--- Time (variable is not needed - it is rebuilt - but calendar is)
-  ierr=NF90_INQUIRE_DIMENSION(ncid, dids(3), name=dnam, len=lmdep)
-  CALL ncerr(ierr, fnam); ALLOCATE(timeyear(lmdep))
-  ierr=NF90_INQ_VARID(ncid, dnam, varid);                CALL ncerr(ierr, fnam)
-  cal_in=' '
-  ierr=NF90_GET_ATT(ncid, varid, 'calendar', cal_in)
-  IF(ierr/=NF90_NOERR) THEN
-    SELECT CASE(mode)
-      CASE('RUG', 'ALB'); cal_in='360d'
-      CASE('SIC', 'SST'); cal_in='gregorian'
-    END SELECT
-    IF (prt_level>5) WRITE(lunout, *)'ATTENTION: variable "time" sans attribut "calendrier" ' &
-         // 'dans '//TRIM(fnam)//'. On choisit la valeur par defaut.'
-  END IF
-  IF (prt_level>5) WRITE(lunout, *) 'variable ', dnam, 'dimension ', lmdep, 'calendrier ', &
-       cal_in
-
-  
-!--- CONSTRUCTING THE INPUT TIME VECTOR FOR INTERPOLATION --------------------
-  !--- Determining input file number of days, depending on calendar
-  ndays_in=year_len(anneeref, cal_in)
-
-!--- Time vector reconstruction (time vector from file is not trusted)
-!--- If input records are not monthly, time sampling has to be constant !
-  timeyear=mid_months(anneeref, cal_in, lmdep)
-  IF (lmdep /= 12) WRITE(lunout,*) 'Note : les fichiers de ', TRIM(mode), &
-       ' ne comportent pas 12, mais ', lmdep, ' enregistrements.'
-
-!--- GETTING THE FIELD AND INTERPOLATING IT ----------------------------------
-  ALLOCATE(champ(imdep, jmdep), champtime(iim, jjp1, lmdep))
-  IF(extrp) ALLOCATE(work(imdep, jmdep))
-
-  IF (prt_level>5) WRITE(lunout, *)
-  IF (prt_level>5) WRITE(lunout,*)'LECTURE ET INTERPOLATION HORIZ. DE ', lmdep, ' CHAMPS.'
-  ierr=NF90_INQ_VARID(ncid, varname, varid);             CALL ncerr(ierr, fnam)
-  DO l=1, lmdep
-    ierr=NF90_GET_VAR(ncid, varid, champ, (/1, 1, l/), (/imdep, jmdep, 1/))
-    CALL ncerr(ierr, fnam)
-    CALL conf_dat2d(title, imdep, jmdep, dlon_ini, dlat_ini, dlon, dlat, &
-         champ, ibar)
-
-    IF (extrp) CALL extrapol(champ, imdep, jmdep, 999999., .TRUE., .TRUE., 2, &
-         work)
-
-    IF(ibar .AND. .NOT.oldice) THEN
-      IF(l==1 .AND. prt_level>5) THEN
-        WRITE(lunout, *) '-------------------------------------------------------------------------'
-        WRITE(lunout, *) 'Utilisation de l''interpolation barycentrique pour ',TRIM(title),' $$$'
-        WRITE(lunout, *) '-------------------------------------------------------------------------'
-      END IF
-      IF(mode=='RUG') champ=LOG(champ)
-      CALL inter_barxy(dlon, dlat(:jmdep-1), champ, rlonu(:iim),     &
-                         rlatv, champint)
-      IF(mode=='RUG') THEN
-        champint=EXP(champint)
-        WHERE(NINT(mask)/=1) champint=0.001
-      END IF
-    ELSE
-      SELECT CASE(mode)
-        CASE('RUG');       CALL rugosite(imdep, jmdep, dlon, dlat, champ,    &
-                                    iim, jjp1, rlonv, rlatu, champint, mask)
-        CASE('SIC');       CALL sea_ice (imdep, jmdep, dlon, dlat, champ,    &
-                                    iim, jjp1, rlonv, rlatu, champint)
-        CASE('SST', 'ALB'); CALL grille_m(imdep, jmdep, dlon, dlat, champ,    &
-                                    iim, jjp1, rlonv, rlatu, champint)
-      END SELECT
-    END IF
-    champtime(:, :, l)=champint
-  END DO
-  ierr=NF90_CLOSE(ncid);                                 CALL ncerr(ierr, fnam)
-
-  DEALLOCATE(dlon_ini, dlat_ini, dlon, dlat, champ)
-  IF(extrp) DEALLOCATE(work)
-
-!--- TIME INTERPOLATION ------------------------------------------------------
-  IF (prt_level>5) THEN
-     WRITE(lunout, *)
-     WRITE(lunout, *)'INTERPOLATION TEMPORELLE.'
-     WRITE(lunout, *)' Vecteur temps en entree: ', timeyear
-     WRITE(lunout, *)' Vecteur temps en sortie de 0 a ', ndays
-  END IF
-
-  ALLOCATE(yder(lmdep), champan(iip1, jjp1, ndays))
-  skip = .false.
-  n_extrap = 0
-  DO j=1, jjp1
-    DO i=1, iim
-      yder = pchsp_95(timeyear, champtime(i, j, :), ibeg=2, iend=2, &
-           vc_beg=0., vc_end=0.)
-      CALL pchfe_95(timeyear, champtime(i, j, :), yder, skip, &
-           arth(0., real(ndays_in) / ndays, ndays), champan(i, j, :), ierr)
-      if (ierr < 0) stop 1
-      n_extrap = n_extrap + ierr
-    END DO
-  END DO
-  if (n_extrap /= 0) then
-     WRITE(lunout,*) "get_2Dfield pchfe_95: n_extrap = ", n_extrap
-  end if
-  champan(iip1, :, :)=champan(1, :, :)
-  DEALLOCATE(yder, champtime, timeyear)
-
-!--- Checking the result
-  DO j=1, jjp1
-    CALL minmax(iip1, champan(1, j, 10), chmin, chmax)
-    IF (prt_level>5) WRITE(lunout, *)' ',TRIM(title),' au temps 10 ', chmin, chmax, j
-  END DO
-
-!--- SPECIAL FILTER FOR SST: SST>271.38 --------------------------------------
-  IF(mode=='SST') THEN
-    IF (prt_level>5) WRITE(lunout, *) 'Filtrage de la SST: SST >= 271.38'
-    WHERE(champan<271.38) champan=271.38
-  END IF
-
-!--- SPECIAL FILTER FOR SIC: 0.0<SIC<1.0 -------------------------------------
-  IF(mode=='SIC') THEN
-    IF (prt_level>5) WRITE(lunout, *) 'Filtrage de la SIC: 0.0 < Sea-ice < 1.0'
-
-    IF (unit_sic=='1') THEN
-       ! Nothing to be done for sea-ice field is already in fraction of 1
-       ! This is the case for sea-ice in file cpl_atm_sic.nc
-       IF (prt_level>5) WRITE(lunout,*) 'Sea-ice field already in fraction of 1'
-    ELSE
-       ! Convert sea ice from percentage to fraction of 1
-       IF (prt_level>5) WRITE(lunout,*) 'Transformt sea-ice field from percentage to fraction of 1.' 
-       champan(:, :, :)=champan(:, :, :)/100.
-    END IF
-
-    champan(iip1, :, :)=champan(1, :, :)
-    WHERE(champan>1.0) champan=1.0
-    WHERE(champan<0.0) champan=0.0
- END IF
-
-!--- DYNAMICAL TO PHYSICAL GRID ----------------------------------------------
-  ALLOCATE(champo(klon, ndays))
-  DO k=1, ndays
-    CALL gr_dyn_fi(1, iip1, jjp1, klon, champan(1, 1, k), champo(1, k))
-  END DO
-  DEALLOCATE(champan)
-
-END SUBROUTINE get_2Dfield
-!
-!-------------------------------------------------------------------------------
-
-
-
-!-------------------------------------------------------------------------------
-!
-FUNCTION year_len(y,cal_in)
-!
-!-------------------------------------------------------------------------------
-  USE ioipsl, ONLY : ioget_calendar,ioconf_calendar,lock_calendar,ioget_year_len
-  IMPLICIT NONE
-!-------------------------------------------------------------------------------
-! Arguments:
-  INTEGER                       :: year_len
-  INTEGER,           INTENT(IN) :: y
-  CHARACTER(LEN=*),  INTENT(IN) :: cal_in
-!-------------------------------------------------------------------------------
-! Local variables:
-  CHARACTER(LEN=20)             :: cal_out              ! calendar (for outputs)
-!-------------------------------------------------------------------------------
-!--- Getting the input calendar to reset at the end of the function
-  CALL ioget_calendar(cal_out)
-
-!--- Unlocking calendar and setting it to wanted one
-  CALL lock_calendar(.FALSE.); CALL ioconf_calendar(TRIM(cal_in))
-
-!--- Getting the number of days in this year
-  year_len=ioget_year_len(y)
-
-!--- Back to original calendar
-  CALL lock_calendar(.FALSE.); CALL ioconf_calendar(TRIM(cal_out))
-
-END FUNCTION year_len
-!
-!-------------------------------------------------------------------------------
-
-
-!-------------------------------------------------------------------------------
-!
-FUNCTION mid_months(y,cal_in,nm)
-!
-!-------------------------------------------------------------------------------
-  USE ioipsl, ONLY : ioget_calendar,ioconf_calendar,lock_calendar,ioget_mon_len
-  IMPLICIT NONE
-!-------------------------------------------------------------------------------
-! Arguments:
-  INTEGER,                INTENT(IN) :: y               ! year
-  CHARACTER(LEN=*),       INTENT(IN) :: cal_in          ! calendar
-  INTEGER,                INTENT(IN) :: nm              ! months/year number
-  REAL,    DIMENSION(nm)             :: mid_months      ! mid-month times
-!-------------------------------------------------------------------------------
-! Local variables:
-  CHARACTER(LEN=99)                  :: mess            ! error message
-  CHARACTER(LEN=20)                  :: cal_out         ! calendar (for outputs)
-  INTEGER, DIMENSION(nm)             :: mnth            ! months lengths (days)
-  INTEGER                            :: m               ! months counter
-  INTEGER                            :: nd              ! number of days
-!-------------------------------------------------------------------------------
-  nd=year_len(y,cal_in)
-
-  IF(nm==12) THEN
-
-  !--- Getting the input calendar to reset at the end of the function
-    CALL ioget_calendar(cal_out)
-
-  !--- Unlocking calendar and setting it to wanted one
-    CALL lock_calendar(.FALSE.); CALL ioconf_calendar(TRIM(cal_in))
-
-  !--- Getting the length of each month
-    DO m=1,nm; mnth(m)=ioget_mon_len(y,m); END DO
-
-  !--- Back to original calendar
-    CALL lock_calendar(.FALSE.); CALL ioconf_calendar(TRIM(cal_out))
-
-  ELSE IF(MODULO(nd,nm)/=0) THEN
-    WRITE(mess,'(a,i3,a,i3,a)')'Unconsistent calendar: ',nd,' days/year, but ',&
-      nm,' months/year. Months number should divide days number.'
-    CALL abort_gcm('mid_months',TRIM(mess),1)
-
-  ELSE
-    mnth=(/(m,m=1,nm,nd/nm)/)
-  END IF
-
-!--- Mid-months times
-  mid_months(1)=0.5*REAL(mnth(1))
-  DO k=2,nm
-    mid_months(k)=mid_months(k-1)+0.5*REAL(mnth(k-1)+mnth(k))
-  END DO
-
-END FUNCTION mid_months
-!
-!-------------------------------------------------------------------------------
-
-
-!-------------------------------------------------------------------------------
-!
-SUBROUTINE ncerr(ncres,fnam)
-!
-!-------------------------------------------------------------------------------
-! Purpose: NetCDF errors handling.
-!-------------------------------------------------------------------------------
-  USE netcdf, ONLY : NF90_NOERR, NF90_STRERROR
-  IMPLICIT NONE
-!-------------------------------------------------------------------------------
-! Arguments:
-  INTEGER,          INTENT(IN) :: ncres
-  CHARACTER(LEN=*), INTENT(IN) :: fnam
-!-------------------------------------------------------------------------------
-#include "iniprint.h"
-  IF(ncres/=NF90_NOERR) THEN
-    WRITE(lunout,*)'Problem with file '//TRIM(fnam)//' in routine limit_netcdf.'
-    CALL abort_gcm('limit_netcdf',NF90_STRERROR(ncres),1)
-  END IF
-
-END SUBROUTINE ncerr
-!
-!-------------------------------------------------------------------------------
-
-#endif
-! of #ifdef CPP_EARTH
-
-END SUBROUTINE limit_netcdf
Index: LMDZ5/branches/testing/libf/dyn3d/mod_const_mpi.F90
===================================================================
--- LMDZ5/branches/testing/libf/dyn3d/mod_const_mpi.F90	(revision 1707)
+++ LMDZ5/branches/testing/libf/dyn3d/mod_const_mpi.F90	(revision 1707)
@@ -0,0 +1,16 @@
+MODULE mod_const_mpi
+
+  INTEGER :: COMM_LMDZ
+  INTEGER :: MPI_REAL_LMDZ
+ 
+
+CONTAINS 
+
+  SUBROUTINE Init_const_mpi
+  IMPLICIT NONE
+  
+    COMM_LMDZ=0
+    MPI_REAL_LMDZ=0
+  END SUBROUTINE Init_const_mpi
+
+END MODULE mod_const_mpi
Index: LMDZ5/branches/testing/libf/dyn3d/mod_const_para.F90
===================================================================
--- LMDZ5/branches/testing/libf/dyn3d/mod_const_para.F90	(revision 1669)
+++ 	(revision )
@@ -1,16 +1,0 @@
-MODULE mod_const_mpi
-
-  INTEGER :: COMM_LMDZ
-  INTEGER :: MPI_REAL_LMDZ
- 
-
-CONTAINS 
-
-  SUBROUTINE Init_const_mpi
-  IMPLICIT NONE
-  
-    COMM_LMDZ=0
-    MPI_REAL_LMDZ=0
-  END SUBROUTINE Init_const_mpi
-
-END MODULE mod_const_mpi
Index: LMDZ5/branches/testing/libf/dyn3d/paramet.h
===================================================================
--- LMDZ5/branches/testing/libf/dyn3d/paramet.h	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3d/paramet.h	(revision 1707)
@@ -17,5 +17,5 @@
       INTEGER jcfil,jcfllm
 
-      PARAMETER( iip1= iim+1-1/iim,iip2=iim+2,iip3=iim+3                &
+      PARAMETER( iip1= iim+1,iip2=iim+2,iip3=iim+3                       &
      &    ,jjp1=jjm+1-1/jjm)
       PARAMETER( llmp1 = llm+1,  llmp2 = llm+2, llmm1 = llm-1 )
Index: LMDZ5/branches/testing/libf/dyn3dmem/abort_gcm.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/abort_gcm.F	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dmem/abort_gcm.F	(revision 1707)
@@ -1,4 +1,4 @@
 !
-! $Id: abort_gcm.F 1425 2010-09-02 13:45:23Z lguez $
+! $Id$
 !
 c
@@ -45,5 +45,4 @@
       if (ierr .eq. 0) then
         write(lunout,*) 'Everything is cool'
-        stop
       else
         write(lunout,*) 'Houston, we have a problem ', ierr
Index: LMDZ5/branches/testing/libf/dyn3dmem/academic.h
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/academic.h	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dmem/academic.h	(revision 1707)
@@ -1,5 +1,9 @@
 !
-! $Header$
+! $Id$
 !
-      real tetarappel(ip1jmp1,llm),taurappel
-      common/academic/tetarappel,taurappel
+      common/academic/tetarappel,knewt_t,kfrict,knewt_g,clat4
+      real :: tetarappel(ip1jmp1,llm)
+      real :: knewt_t(llm)
+      real :: kfrict(llm)
+      real :: knewt_g
+      real :: clat4(ip1jmp1)
Index: LMDZ5/branches/testing/libf/dyn3dmem/addfi_loc.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/addfi_loc.F	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dmem/addfi_loc.F	(revision 1707)
@@ -1,4 +1,4 @@
 !
-! $Header$
+! $Id$
 !
       SUBROUTINE addfi_loc(pdt, leapf, forward,
@@ -7,4 +7,5 @@
       USE parallel
       USE infotrac, ONLY : nqtot
+      USE control_mod, ONLY : planet_type
       IMPLICIT NONE
 c
@@ -156,4 +157,6 @@
 c$OMP END MASTER
  
+      if (planet_type=="earth") then
+      ! earth case, special treatment for first 2 tracers (water)
       DO iq = 1, 2
 c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)
@@ -177,4 +180,17 @@
 c$OMP END DO NOWAIT
       ENDDO
+      else
+      ! general case, treat all tracers equally)
+       DO iq = 1, nqtot
+c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)
+         DO k = 1,llm
+            DO j = ijb,ije
+               pq(j,k,iq)= pq(j,k,iq) + pdqfi(j,k,iq) * pdt
+               pq(j,k,iq)= AMAX1( pq(j,k,iq), qtestt )
+            ENDDO
+         ENDDO
+c$OMP END DO NOWAIT
+       ENDDO
+      endif ! of if (planet_type=="earth")
 
 c$OMP MASTER
Index: LMDZ5/branches/testing/libf/dyn3dmem/advtrac_loc.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/advtrac_loc.F	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dmem/advtrac_loc.F	(revision 1707)
@@ -1,4 +1,4 @@
 !
-! $Id: advtrac_p.F 1299 2010-01-20 14:27:21Z fairhead $
+! $Id$
 !
 c
@@ -342,4 +342,6 @@
 c$OMP BARRIER
 
+      if (planet_type=="earth") then
+
       ijb=ij_begin
       ije=ij_end
@@ -355,4 +357,5 @@
        CALL qminimum_loc( q, 2, finmasse )
 
+      endif ! of if (planet_type=="earth")
 
        RETURN
Index: LMDZ5/branches/testing/libf/dyn3dmem/bands.F90
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/bands.F90	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dmem/bands.F90	(revision 1707)
@@ -1,4 +1,4 @@
 !
-! $Id: bands.F90 1279 2009-12-10 09:02:56Z fairhead $
+! $Id$
 !
   module Bands
@@ -105,6 +105,6 @@
    SUBROUTINE  Set_Bands 
      USE parallel
-#ifdef CPP_EARTH
-! Ehouarn: what follows is only related to // physics; for now only for Earth 
+#ifdef CPP_PHYS
+! Ehouarn: what follows is only related to // physics
      USE mod_phys_lmdz_para, ONLY : jj_para_begin,jj_para_end
 #endif
@@ -118,6 +118,5 @@
       enddo
           
-#ifdef CPP_EARTH
-! Ehouarn: what follows is only related to // physics; for now only for Earth          
+#ifdef CPP_PHYS
       do i=0,MPI_Size-1
         jj_Nb_physic(i)=jj_para_end(i)-jj_para_begin(i)+1
@@ -374,6 +373,6 @@
     subroutine AdjustBands_physic
       use times
-#ifdef CPP_EARTH
-! Ehouarn: what follows is only related to // physics; for now only for Earth 
+#ifdef CPP_PHYS
+! Ehouarn: what follows is only related to // physics
       USE mod_phys_lmdz_para, only : klon_mpi_para_nb
 #endif
@@ -401,6 +400,5 @@
       medium=medium/mpi_size      
       NbTot=0
-#ifdef CPP_EARTH
-! Ehouarn: what follows is only related to // physics; for now only for Earth 
+#ifdef CPP_PHYS
       do i=0,mpi_size-1
         Inc(i)=nint(klon_mpi_para_nb(i)*(medium-value(i))/value(i))
Index: LMDZ5/branches/testing/libf/dyn3dmem/bilan_dyn_loc.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/bilan_dyn_loc.F	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dmem/bilan_dyn_loc.F	(revision 1707)
@@ -421,5 +421,4 @@
           Q_cum(:,jjb:jje,:,l)=0.
           flux_uQ_cum(:,jjb:jje,l,:)=0.
-          flux_v_cum(:,jjb:jje,l)=0.
           if (pole_sud) jje=jj_end-1
           flux_v_cum(:,jjb:jje,l)=0.
Index: LMDZ5/branches/testing/libf/dyn3dmem/bilan_dyn_p.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/bilan_dyn_p.F	(revision 1669)
+++ 	(revision )
@@ -1,717 +1,0 @@
-!
-! $Id: bilan_dyn_p.F 1403 2010-07-01 09:02:53Z fairhead $
-!
-      SUBROUTINE bilan_dyn_p (ntrac,dt_app,dt_cum,
-     s  ps,masse,pk,flux_u,flux_v,teta,phi,ucov,vcov,trac)
-
-c   AFAIRE
-c   Prevoir en champ nq+1 le diagnostique de l'energie
-c   en faisant Qzon=Cv T + L * ...
-c             vQ..A=Cp T + L * ...
-
-#ifdef CPP_IOIPSL
-      USE IOIPSL
-#endif
-      USE parallel
-      USE mod_hallo
-      use misc_mod
-      use write_field
-      IMPLICIT NONE
-
-#include "dimensions.h"
-#include "paramet.h"
-#include "comconst.h"
-#include "comvert.h"
-#include "comgeom2.h"
-#include "temps.h"
-#include "iniprint.h"
-
-c====================================================================
-c
-c   Sous-programme consacre à des diagnostics dynamiques de base
-c
-c 
-c   De facon generale, les moyennes des scalaires Q sont ponderees par
-c   la masse.
-c
-c   Les flux de masse sont eux simplement moyennes.
-c
-c====================================================================
-
-c   Arguments :
-c   ===========
-
-      integer ntrac
-      real dt_app,dt_cum
-      real ps(iip1,jjp1)
-      real masse(iip1,jjp1,llm),pk(iip1,jjp1,llm)
-      real flux_u(iip1,jjp1,llm)
-      real flux_v(iip1,jjm,llm)
-      real teta(iip1,jjp1,llm)
-      real phi(iip1,jjp1,llm)
-      real ucov(iip1,jjp1,llm)
-      real vcov(iip1,jjm,llm)
-      real trac(iip1,jjp1,llm,ntrac)
-
-c   Local :
-c   =======
-
-      integer icum,ncum
-      logical first
-      real zz,zqy,zfactv(jjm,llm)
-
-      integer nQ
-      parameter (nQ=7)
-
-
-cym      character*6 nom(nQ)
-cym      character*6 unites(nQ)
-      character*6,save :: nom(nQ)
-      character*6,save :: unites(nQ)
-
-      character*10 file
-      integer ifile
-      parameter (ifile=4)
-
-      integer itemp,igeop,iecin,iang,iu,iovap,iun
-      integer i_sortie
-
-      save first,icum,ncum
-      save itemp,igeop,iecin,iang,iu,iovap,iun
-      save i_sortie
-
-      real time
-      integer itau
-      save time,itau
-      data time,itau/0.,0/
-
-      data first/.true./
-      data itemp,igeop,iecin,iang,iu,iovap,iun/1,2,3,4,5,6,7/
-      data i_sortie/1/
-
-      real ww
-
-c   variables dynamiques intermédiaires
-      REAL vcont(iip1,jjm,llm),ucont(iip1,jjp1,llm)
-      REAL ang(iip1,jjp1,llm),unat(iip1,jjp1,llm)
-      REAL massebx(iip1,jjp1,llm),masseby(iip1,jjm,llm)
-      REAL vorpot(iip1,jjm,llm)
-      REAL w(iip1,jjp1,llm),ecin(iip1,jjp1,llm),convm(iip1,jjp1,llm)
-      REAL bern(iip1,jjp1,llm)
-
-c   champ contenant les scalaires advectés.
-      real Q(iip1,jjp1,llm,nQ)
-    
-c   champs cumulés
-      real ps_cum(iip1,jjp1)
-      real masse_cum(iip1,jjp1,llm)
-      real flux_u_cum(iip1,jjp1,llm)
-      real flux_v_cum(iip1,jjm,llm)
-      real Q_cum(iip1,jjp1,llm,nQ)
-      real flux_uQ_cum(iip1,jjp1,llm,nQ)
-      real flux_vQ_cum(iip1,jjm,llm,nQ)
-      real flux_wQ_cum(iip1,jjp1,llm,nQ)
-      real dQ(iip1,jjp1,llm,nQ)
-
-      save ps_cum,masse_cum,flux_u_cum,flux_v_cum
-      save Q_cum,flux_uQ_cum,flux_vQ_cum
-
-c   champs de tansport en moyenne zonale
-      integer ntr,itr
-      parameter (ntr=5)
-
-cym      character*10 znom(ntr,nQ)
-cym      character*20 znoml(ntr,nQ)
-cym      character*10 zunites(ntr,nQ)
-      character*10,save :: znom(ntr,nQ)
-      character*20,save :: znoml(ntr,nQ)
-      character*10,save :: zunites(ntr,nQ)
-
-      integer iave,itot,immc,itrs,istn
-      data iave,itot,immc,itrs,istn/1,2,3,4,5/
-      character*3 ctrs(ntr)
-      data ctrs/'  ','TOT','MMC','TRS','STN'/
-
-      real zvQ(jjm,llm,ntr,nQ),zvQtmp(jjm,llm)
-      real zavQ(jjm,ntr,nQ),psiQ(jjm,llm+1,nQ)
-      real zmasse(jjm,llm),zamasse(jjm)
-
-      real zv(jjm,llm),psi(jjm,llm+1)
-
-      integer i,j,l,iQ
-
-
-c   Initialisation du fichier contenant les moyennes zonales.
-c   ---------------------------------------------------------
-
-      character*10 infile
-
-      integer fileid
-      integer thoriid, zvertiid
-      save fileid
-
-      integer ndex3d(jjm*llm)
-
-C   Variables locales
-C
-      integer tau0
-      real zjulian
-      character*3 str
-      character*10 ctrac
-      integer ii,jj
-      integer zan, dayref
-C
-      real rlong(jjm),rlatg(jjm)
-      integer :: jjb,jje,jjn,ijb,ije
-      type(Request) :: Req
-
-! definition du domaine d'ecriture pour le rebuild
-
-      INTEGER,DIMENSION(1) :: ddid
-      INTEGER,DIMENSION(1) :: dsg
-      INTEGER,DIMENSION(1) :: dsl
-      INTEGER,DIMENSION(1) :: dpf
-      INTEGER,DIMENSION(1) :: dpl
-      INTEGER,DIMENSION(1) :: dhs
-      INTEGER,DIMENSION(1) :: dhe 
-      
-      INTEGER :: bilan_dyn_domain_id
-
-
-c=====================================================================
-c   Initialisation
-c=====================================================================
-      ndex3d=0
-      if (adjust) return
-      
-      time=time+dt_app
-      itau=itau+1
-
-      if (first) then
-
-
-        icum=0
-c       initialisation des fichiers
-        first=.false.
-c   ncum est la frequence de stokage en pas de temps
-        ncum=dt_cum/dt_app
-        if (abs(ncum*dt_app-dt_cum).gt.1.e-5*dt_app) then
-           WRITE(lunout,*)
-     .            'Pb : le pas de cumule doit etre multiple du pas'
-           WRITE(lunout,*)'dt_app=',dt_app
-           WRITE(lunout,*)'dt_cum=',dt_cum
-           stop
-        endif
-
-        if (i_sortie.eq.1) then
-	 file='dynzon'
-         if (mpi_rank==0) then
-	 call inigrads(ifile,1
-     s  ,0.,180./pi,0.,0.,jjm,rlatv,-90.,90.,180./pi
-     s  ,llm,presnivs,1.
-     s  ,dt_cum,file,'dyn_zon ')
-         endif
-        endif
-
-        nom(itemp)='T'
-        nom(igeop)='gz'
-        nom(iecin)='K'
-        nom(iang)='ang'
-        nom(iu)='u'
-        nom(iovap)='ovap'
-        nom(iun)='un'
-
-        unites(itemp)='K'
-        unites(igeop)='m2/s2'
-        unites(iecin)='m2/s2'
-        unites(iang)='ang'
-        unites(iu)='m/s'
-        unites(iovap)='kg/kg'
-        unites(iun)='un'
-
-
-c   Initialisation du fichier contenant les moyennes zonales.
-c   ---------------------------------------------------------
-
-      infile='dynzon'
-
-      zan = annee_ref
-      dayref = day_ref
-      CALL ymds2ju(zan, 1, dayref, 0.0, zjulian)
-      tau0 = itau_dyn
-      
-      rlong=0.
-      rlatg=rlatv*180./pi
-
-      jjb=jj_begin
-      jje=jj_end
-      jjn=jj_nb
-      IF (pole_sud) THEN
-        jjn=jj_nb-1
-        jje=jj_end-1
-      ENDIF
-
-      ddid=(/ 2 /)
-      dsg=(/ jjm /)
-      dsl=(/ jjn /)
-      dpf=(/ jjb /)
-      dpl=(/ jje /)
-      dhs=(/ 0 /)
-      dhe=(/ 0 /)
-
-      call flio_dom_set(mpi_size,mpi_rank,ddid,dsg,dsl,dpf,dpl,dhs,dhe, 
-     .                 'box',bilan_dyn_domain_id)
-       
-      call histbeg(trim(infile),
-     .             1, rlong(jjb:jje), jjn, rlatg(jjb:jje),
-     .             1, 1, 1, jjn,
-     .             tau0, zjulian, dt_cum, thoriid, fileid,
-     .             bilan_dyn_domain_id)
-
-C
-C  Appel a histvert pour la grille verticale
-C
-      call histvert(fileid, 'presnivs', 'Niveaux sigma','mb',
-     .              llm, presnivs, zvertiid)
-C
-C  Appels a histdef pour la definition des variables a sauvegarder
-      do iQ=1,nQ
-         do itr=1,ntr
-            if(itr.eq.1) then
-               znom(itr,iQ)=nom(iQ)
-               znoml(itr,iQ)=nom(iQ)
-               zunites(itr,iQ)=unites(iQ)
-            else
-               znom(itr,iQ)=ctrs(itr)//'v'//nom(iQ)
-               znoml(itr,iQ)='transport : v * '//nom(iQ)//' '//ctrs(itr)
-               zunites(itr,iQ)='m/s * '//unites(iQ)
-            endif
-         enddo
-      enddo
-
-c   Declarations des champs avec dimension verticale
-c      print*,'1HISTDEF'
-      do iQ=1,nQ
-         do itr=1,ntr
-      IF (prt_level > 5)
-     . WRITE(lunout,*)'var ',itr,iQ
-     .      ,znom(itr,iQ),znoml(itr,iQ),zunites(itr,iQ)
-            call histdef(fileid,znom(itr,iQ),znoml(itr,iQ),
-     .        zunites(itr,iQ),1,jjn,thoriid,llm,1,llm,zvertiid,
-     .        32,'ave(X)',dt_cum,dt_cum)
-         enddo
-c   Declarations pour les fonctions de courant
-c      print*,'2HISTDEF'
-          call histdef(fileid,'psi'//nom(iQ)
-     .      ,'stream fn. '//znoml(itot,iQ),
-     .      zunites(itot,iQ),1,jjn,thoriid,llm,1,llm,zvertiid,
-     .      32,'ave(X)',dt_cum,dt_cum)
-      enddo
-
-
-c   Declarations pour les champs de transport d'air
-c      print*,'3HISTDEF'
-      call histdef(fileid, 'masse', 'masse',
-     .             'kg', 1, jjn, thoriid, llm, 1, llm, zvertiid,
-     .             32, 'ave(X)', dt_cum, dt_cum)
-      call histdef(fileid, 'v', 'v',
-     .             'm/s', 1, jjn, thoriid, llm, 1, llm, zvertiid,
-     .             32, 'ave(X)', dt_cum, dt_cum)
-c   Declarations pour les fonctions de courant
-c      print*,'4HISTDEF'
-          call histdef(fileid,'psi','stream fn. MMC ','mega t/s',
-     .      1,jjn,thoriid,llm,1,llm,zvertiid,
-     .      32,'ave(X)',dt_cum,dt_cum)
-
-
-c   Declaration des champs 1D de transport en latitude
-c      print*,'5HISTDEF'
-      do iQ=1,nQ
-         do itr=2,ntr
-            call histdef(fileid,'a'//znom(itr,iQ),znoml(itr,iQ),
-     .        zunites(itr,iQ),1,jjn,thoriid,1,1,1,-99,
-     .        32,'ave(X)',dt_cum,dt_cum)
-         enddo
-      enddo
-
-
-c      print*,'8HISTDEF'
-               CALL histend(fileid)
-
-
-      endif
-
-
-c=====================================================================
-c   Calcul des champs dynamiques
-c   ----------------------------
-
-      jjb=jj_begin
-      jje=jj_end
-    
-c   énergie cinétique
-      ucont(:,jjb:jje,:)=0
-
-      call Register_Hallo(ucov,ip1jmp1,llm,1,1,1,1,Req)
-      call Register_Hallo(vcov,ip1jm,llm,1,1,1,1,Req)
-      call SendRequest(Req)
-      call WaitRequest(Req)
-
-      CALL covcont_p(llm,ucov,vcov,ucont,vcont)
-      CALL enercin_p(vcov,ucov,vcont,ucont,ecin)
-
-c   moment cinétique
-      do l=1,llm
-         ang(:,jjb:jje,l)=ucov(:,jjb:jje,l)+constang(:,jjb:jje)
-         unat(:,jjb:jje,l)=ucont(:,jjb:jje,l)*cu(:,jjb:jje)
-      enddo
-
-      Q(:,jjb:jje,:,itemp)=teta(:,jjb:jje,:)*pk(:,jjb:jje,:)/cpp
-      Q(:,jjb:jje,:,igeop)=phi(:,jjb:jje,:)
-      Q(:,jjb:jje,:,iecin)=ecin(:,jjb:jje,:)
-      Q(:,jjb:jje,:,iang)=ang(:,jjb:jje,:)
-      Q(:,jjb:jje,:,iu)=unat(:,jjb:jje,:)
-      Q(:,jjb:jje,:,iovap)=trac(:,jjb:jje,:,1)
-      Q(:,jjb:jje,:,iun)=1.
-
-
-c=====================================================================
-c   Cumul
-c=====================================================================
-c
-      if(icum.EQ.0) then
-         jjb=jj_begin
-         jje=jj_end
-
-         ps_cum(:,jjb:jje)=0.
-         masse_cum(:,jjb:jje,:)=0.
-         flux_u_cum(:,jjb:jje,:)=0.
-         Q_cum(:,jjb:jje,:,:)=0.
-         flux_uQ_cum(:,jjb:jje,:,:)=0.
-         flux_v_cum(:,jjb:jje,:)=0.
-         if (pole_sud) jje=jj_end-1
-         flux_v_cum(:,jjb:jje,:)=0.
-         flux_vQ_cum(:,jjb:jje,:,:)=0.
-      endif
-
-      IF (prt_level > 5)
-     . WRITE(lunout,*)'dans bilan_dyn ',icum,'->',icum+1
-      icum=icum+1
-
-c   accumulation des flux de masse horizontaux
-      jjb=jj_begin
-      jje=jj_end
-
-      ps_cum(:,jjb:jje)=ps_cum(:,jjb:jje)+ps(:,jjb:jje)
-      masse_cum(:,jjb:jje,:)=masse_cum(:,jjb:jje,:)+masse(:,jjb:jje,:)
-      flux_u_cum(:,jjb:jje,:)=flux_u_cum(:,jjb:jje,:)
-     .                       +flux_u(:,jjb:jje,:)
-      if (pole_sud) jje=jj_end-1
-      flux_v_cum(:,jjb:jje,:)=flux_v_cum(:,jjb:jje,:)
-     .                         +flux_v(:,jjb:jje,:)
-
-      jjb=jj_begin
-      jje=jj_end
-
-      do iQ=1,nQ
-        Q_cum(:,jjb:jje,:,iQ)=Q_cum(:,jjb:jje,:,iQ)
-     .                       +Q(:,jjb:jje,:,iQ)*masse(:,jjb:jje,:)
-      enddo
-
-c=====================================================================
-c  FLUX ET TENDANCES
-c=====================================================================
-
-c   Flux longitudinal
-c   -----------------
-      do iQ=1,nQ
-         do l=1,llm
-            do j=jjb,jje
-               do i=1,iim
-                  flux_uQ_cum(i,j,l,iQ)=flux_uQ_cum(i,j,l,iQ)
-     s            +flux_u(i,j,l)*0.5*(Q(i,j,l,iQ)+Q(i+1,j,l,iQ))
-               enddo
-               flux_uQ_cum(iip1,j,l,iQ)=flux_uQ_cum(1,j,l,iQ)
-            enddo
-         enddo
-      enddo
-
-c    flux méridien
-c    -------------
-      do iQ=1,nQ
-        call Register_Hallo(Q(1,1,1,iQ),ip1jmp1,llm,0,1,1,0,Req)
-      enddo
-      call SendRequest(Req)
-      call WaitRequest(Req)
-      
-      jjb=jj_begin
-      jje=jj_end
-      if (pole_sud) jje=jj_end-1
-      
-      do iQ=1,nQ
-         do l=1,llm
-            do j=jjb,jje
-               do i=1,iip1
-                  flux_vQ_cum(i,j,l,iQ)=flux_vQ_cum(i,j,l,iQ)
-     s            +flux_v(i,j,l)*0.5*(Q(i,j,l,iQ)+Q(i,j+1,l,iQ))
-               enddo
-            enddo
-         enddo
-      enddo
-
-
-c    tendances
-c    ---------
-
-c   convergence horizontale
-      call Register_Hallo(flux_uQ_cum,ip1jmp1,llm,2,2,2,2,Req)
-      call Register_Hallo(flux_vQ_cum,ip1jm,llm,2,2,2,2,Req)
-      call SendRequest(Req)
-      call WaitRequest(Req)
-
-      call  convflu_p(flux_uQ_cum,flux_vQ_cum,llm*nQ,dQ)
-
-c   calcul de la vitesse verticale
-      call Register_Hallo(flux_u_cum,ip1jmp1,llm,2,2,2,2,Req)
-      call Register_Hallo(flux_v_cum,ip1jm,llm,2,2,2,2,Req)
-      call SendRequest(Req)
-      call WaitRequest(Req)
-
-      call convmas_p(flux_u_cum,flux_v_cum,convm)
-      CALL vitvert_p(convm,w)
-
-      jjb=jj_begin
-      jje=jj_end
-
-      do iQ=1,nQ
-         do l=1,llm-1
-            do j=jjb,jje
-               do i=1,iip1
-                  ww=-0.5*w(i,j,l+1)*(Q(i,j,l,iQ)+Q(i,j,l+1,iQ))
-                  dQ(i,j,l  ,iQ)=dQ(i,j,l  ,iQ)-ww
-                  dQ(i,j,l+1,iQ)=dQ(i,j,l+1,iQ)+ww
-               enddo
-            enddo
-         enddo
-      enddo
-      IF (prt_level > 5)
-     . WRITE(lunout,*)'Apres les calculs fait a chaque pas'
-c=====================================================================
-c   PAS DE TEMPS D'ECRITURE
-c=====================================================================
-      if (icum.eq.ncum) then
-c=====================================================================
-
-      IF (prt_level > 5)
-     . WRITE(lunout,*)'Pas d ecriture'
-
-c   Normalisation
-      do iQ=1,nQ
-         Q_cum(:,jjb:jje,:,iQ)=Q_cum(:,jjb:jje,:,iQ)
-     .	                      /masse_cum(:,jjb:jje,:)
-      enddo
-      zz=1./REAL(ncum)
-
-      jjb=jj_begin
-      jje=jj_end
-
-      ps_cum(:,jjb:jje)=ps_cum(:,jjb:jje)*zz
-      masse_cum(:,jjb:jje,:)=masse_cum(:,jjb:jje,:)*zz
-      flux_u_cum(:,jjb:jje,:)=flux_u_cum(:,jjb:jje,:)*zz
-      flux_uQ_cum(:,jjb:jje,:,:)=flux_uQ_cum(:,jjb:jje,:,:)*zz
-      dQ(:,jjb:jje,:,:)=dQ(:,jjb:jje,:,:)*zz
-      
-      IF (pole_sud) jje=jj_end-1
-      flux_v_cum(:,jjb:jje,:)=flux_v_cum(:,jjb:jje,:)*zz
-      flux_vQ_cum(:,jjb:jje,:,:)=flux_vQ_cum(:,jjb:jje,:,:)*zz
-
-      jjb=jj_begin
-      jje=jj_end
-
-
-c   A retravailler eventuellement
-c   division de dQ par la masse pour revenir aux bonnes grandeurs
-      do iQ=1,nQ
-         dQ(:,jjb:jje,:,iQ)=dQ(:,jjb:jje,:,iQ)/masse_cum(:,jjb:jje,:)
-      enddo
- 
-c=====================================================================
-c   Transport méridien
-c=====================================================================
-
-c   cumul zonal des masses des mailles
-c   ----------------------------------
-      jjb=jj_begin
-      jje=jj_end
-      if (pole_sud) jje=jj_end-1
-
-      zv(jjb:jje,:)=0.
-      zmasse(jjb:jje,:)=0.
-
-      call Register_Hallo(masse_cum,ip1jmp1,llm,1,1,1,1,Req)
-      do iQ=1,nQ
-        call Register_Hallo(Q_cum(1,1,1,iQ),ip1jmp1,llm,0,1,1,0,Req)
-      enddo
-
-      call SendRequest(Req)
-      call WaitRequest(Req)
-
-      call massbar_p(masse_cum,massebx,masseby)
-      
-      jjb=jj_begin
-      jje=jj_end
-      if (pole_sud) jje=jj_end-1
-      
-      do l=1,llm
-         do j=jjb,jje
-            do i=1,iim
-               zmasse(j,l)=zmasse(j,l)+masseby(i,j,l)
-               zv(j,l)=zv(j,l)+flux_v_cum(i,j,l)
-            enddo
-            zfactv(j,l)=cv(1,j)/zmasse(j,l)
-         enddo
-      enddo
-
-c     print*,'3OK'
-c   --------------------------------------------------------------
-c   calcul de la moyenne zonale du transport :
-c   ------------------------------------------
-c
-c                                     --
-c TOT : la circulation totale       [ vq ]
-c
-c                                      -     -
-c MMC : mean meridional circulation [ v ] [ q ]
-c
-c                                     ----      --       - -
-c TRS : transitoires                [ v'q'] = [ vq ] - [ v q ]
-c
-c                                     - * - *       - -       -     -
-c STT : stationaires                [ v   q   ] = [ v q ] - [ v ] [ q ]
-c
-c                                              - -
-c    on utilise aussi l'intermediaire TMP :  [ v q ]
-c
-c    la variable zfactv transforme un transport meridien cumule
-c    en kg/s * unte-du-champ-transporte en m/s * unite-du-champ-transporte
-c
-c   --------------------------------------------------------------
-
-
-c   ----------------------------------------
-c   Transport dans le plan latitude-altitude
-c   ----------------------------------------
-
-      jjb=jj_begin
-      jje=jj_end
-      if (pole_sud) jje=jj_end-1
-      
-      zvQ=0.
-      psiQ=0.
-      do iQ=1,nQ
-         zvQtmp=0.
-         do l=1,llm
-            do j=jjb,jje
-c              print*,'j,l,iQ=',j,l,iQ
-c   Calcul des moyennes zonales du transort total et de zvQtmp
-               do i=1,iim
-                  zvQ(j,l,itot,iQ)=zvQ(j,l,itot,iQ)
-     s                            +flux_vQ_cum(i,j,l,iQ)
-                  zqy=      0.5*(Q_cum(i,j,l,iQ)*masse_cum(i,j,l)+
-     s                           Q_cum(i,j+1,l,iQ)*masse_cum(i,j+1,l))
-                  zvQtmp(j,l)=zvQtmp(j,l)+flux_v_cum(i,j,l)*zqy
-     s             /(0.5*(masse_cum(i,j,l)+masse_cum(i,j+1,l)))
-                  zvQ(j,l,iave,iQ)=zvQ(j,l,iave,iQ)+zqy
-               enddo
-c              print*,'aOK'
-c   Decomposition
-               zvQ(j,l,iave,iQ)=zvQ(j,l,iave,iQ)/zmasse(j,l)
-               zvQ(j,l,itot,iQ)=zvQ(j,l,itot,iQ)*zfactv(j,l)
-               zvQtmp(j,l)=zvQtmp(j,l)*zfactv(j,l)
-               zvQ(j,l,immc,iQ)=zv(j,l)*zvQ(j,l,iave,iQ)*zfactv(j,l)
-               zvQ(j,l,itrs,iQ)=zvQ(j,l,itot,iQ)-zvQtmp(j,l)
-               zvQ(j,l,istn,iQ)=zvQtmp(j,l)-zvQ(j,l,immc,iQ)
-            enddo
-         enddo
-c   fonction de courant meridienne pour la quantite Q
-         do l=llm,1,-1
-            do j=jjb,jje
-               psiQ(j,l,iQ)=psiQ(j,l+1,iQ)+zvQ(j,l,itot,iQ)
-            enddo
-         enddo
-      enddo
-
-c   fonction de courant pour la circulation meridienne moyenne
-      psi(jjb:jje,:)=0.
-      do l=llm,1,-1
-         do j=jjb,jje
-            psi(j,l)=psi(j,l+1)+zv(j,l)
-            zv(j,l)=zv(j,l)*zfactv(j,l)
-         enddo
-      enddo
-
-c     print*,'4OK'
-c   sorties proprement dites
-      if (i_sortie.eq.1) then
-      jjb=jj_begin
-      jje=jj_end
-      jjn=jj_nb
-      if (pole_sud) jje=jj_end-1
-      if (pole_sud) jjn=jj_nb-1
-      
-      do iQ=1,nQ
-         do itr=1,ntr
-            call histwrite(fileid,znom(itr,iQ),itau,
-     s                     zvQ(jjb:jje,:,itr,iQ)
-     s                     ,jjn*llm,ndex3d)
-         enddo
-         call histwrite(fileid,'psi'//nom(iQ),
-     s                  itau,psiQ(jjb:jje,1:llm,iQ)
-     s                  ,jjn*llm,ndex3d)
-      enddo
-
-      call histwrite(fileid,'masse',itau,zmasse(jjb:jje,1:llm)
-     s   ,jjn*llm,ndex3d)
-      call histwrite(fileid,'v',itau,zv(jjb:jje,1:llm)
-     s   ,jjn*llm,ndex3d)
-      psi(jjb:jje,:)=psi(jjb:jje,:)*1.e-9
-      call histwrite(fileid,'psi',itau,psi(jjb:jje,1:llm),
-     s               jjn*llm,ndex3d)
-
-      endif
-
-
-c   -----------------
-c   Moyenne verticale
-c   -----------------
-
-      zamasse(jjb:jje)=0.
-      do l=1,llm
-         zamasse(jjb:jje)=zamasse(jjb:jje)+zmasse(jjb:jje,l)
-      enddo
-     
-      zavQ(jjb:jje,:,:)=0.
-      do iQ=1,nQ
-         do itr=2,ntr
-            do l=1,llm
-               zavQ(jjb:jje,itr,iQ)=zavQ(jjb:jje,itr,iQ)
-     s                             +zvQ(jjb:jje,l,itr,iQ)
-     s                             *zmasse(jjb:jje,l)
-            enddo
-            zavQ(jjb:jje,itr,iQ)=zavQ(jjb:jje,itr,iQ)/zamasse(jjb:jje)
-            call histwrite(fileid,'a'//znom(itr,iQ),itau,
-     s                     zavQ(jjb:jje,itr,iQ),jjn*llm,ndex3d)
-         enddo
-      enddo
-
-c     on doit pouvoir tracer systematiquement la fonction de courant.
-
-c=====================================================================
-c/////////////////////////////////////////////////////////////////////
-      icum=0                  !///////////////////////////////////////
-      endif ! icum.eq.ncum    !///////////////////////////////////////
-c/////////////////////////////////////////////////////////////////////
-c=====================================================================
-
-      return
-      end
Index: LMDZ5/branches/testing/libf/dyn3dmem/caladvtrac_loc.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/caladvtrac_loc.F	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dmem/caladvtrac_loc.F	(revision 1707)
@@ -8,6 +8,6 @@
      *                   flxw, pk, iapptrac)
       USE parallel 
-      USE infotrac
-      USE control_mod
+      USE infotrac, ONLY : nqtot
+      USE control_mod, ONLY : iapp_tracvl,planet_type
       USE caladvtrac_mod
       USE mod_hallo
@@ -38,5 +38,5 @@
       REAL :: masse(ijb_u:ije_u,llm)
       REAL :: p( ijb_u:ije_u,llmp1)
-      REAL :: q( ijb_u:ije_u,llm,nqtot),dq( ijb_u:ije_u,llm,2 )
+      REAL :: q( ijb_u:ije_u,llm,nqtot),dq( ijb_u:ije_u,llm, nqtot )
       REAL :: teta( ijb_u:ije_u,llm),pk( ijb_u:ije_u,llm)
       REAL :: flxw(ijb_u:ije_u,llm)
Index: LMDZ5/branches/testing/libf/dyn3dmem/calfis_loc.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/calfis_loc.F	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dmem/calfis_loc.F	(revision 1707)
@@ -27,6 +27,6 @@
      $                  pdqfi,
      $                  pdpsfi)
-#ifdef CPP_EARTH
-! Ehouarn: For now, calfis_p needs Earth physics
+#ifdef CPP_PHYS
+! If using physics
 c
 c    Auteur :  P. Le Van, F. Hourdin 
@@ -36,8 +36,9 @@
       USE parallel, ONLY : omp_chunk, using_mpi,jjb_u,jje_u,jjb_v,jje_v
       USE mod_interface_dyn_phys
+      USE IOPHY
+#endif
       USE Write_Field
       Use Write_field_p
       USE Times
-      USE IOPHY
       USE infotrac
       USE control_mod
@@ -145,4 +146,6 @@
 
 
+#ifdef CPP_PHYS
+! Ehouarn: for now calfis_p needs some informations from physics to compile
 c    Local variables :
 c    -----------------
@@ -220,5 +223,5 @@
       PARAMETER(ntetaSTD=3)
       REAL rtetaSTD(ntetaSTD)
-      DATA rtetaSTD/350., 380., 405./
+      DATA rtetaSTD/350., 380., 405./ ! Earth-specific values, beware !!
       REAL PVteta(klon,ntetaSTD)
       
@@ -243,5 +246,7 @@
       REAL,ALLOCATABLE,SAVE:: zdufi2(:,:),zdvfi2(:,:)
       integer :: k,kstart,kend
-      INTEGER :: offset  
+      INTEGER :: offset
+
+      LOGICAL tracerdyn  
 c
 c-----------------------------------------------------------------------
@@ -512,6 +517,7 @@
 
 
-      IF (is_sequential) THEN
-c
+      IF (is_sequential.and.(planet_type=="earth")) THEN
+#ifdef CPP_PHYS
+! PVtheta calls tetalevel, which is in the physics
 cIM calcul PV a teta=350, 380, 405K
         CALL PVtheta(ngridmx,llm,pucov,pvcov,pteta,
@@ -519,4 +525,5 @@
      $           ntetaSTD,rtetaSTD,PVteta)
 c
+#endif
       ENDIF
 
@@ -662,7 +669,4 @@
 c$OMP BARRIER
       
-      if (planet_type=="earth") then
-#ifdef CPP_EARTH
-
 
 !$OMP MASTER 
@@ -675,4 +679,5 @@
       zdqfic_omp(:,:,:)=0.
 
+#ifdef CPP_PHYS
       do isplit=1,nsplit_phys
 
@@ -681,4 +686,5 @@
          lafin_split=lafin.and.isplit==nsplit_phys
 
+      if (planet_type=="earth") then
 
       CALL physiq (klon,
@@ -711,4 +717,33 @@
      .             PVteta)
 
+      else if ( planet_type=="generic" ) then
+
+      CALL physiq (klon,     !! ngrid
+     .             llm,            !! nlayer
+     .             nqtot,          !! nq
+     .             tname,          !! tracer names from dynamical core (given in infotrac)
+     .             debut_split,    !! firstcall 
+     .             lafin_split,    !! lastcall
+     .             jD_cur,         !! pday. see leapfrog_p 
+     .             jH_cur_split,   !! ptime "fraction of day"
+     .             zdt_split,      !! ptimestep
+     .             zplev_omp,  !! pplev
+     .             zplay_omp,  !! pplay
+     .             zphi_omp,   !! pphi
+     .             zufi_omp,   !! pu
+     .             zvfi_omp,   !! pv
+     .             ztfi_omp,   !! pt
+     .             zqfi_omp,   !! pq
+     .             flxwfi_omp, !! pw !! or 0. anyway this is for diagnostic. not used in physiq.
+     .             zdufi_omp,  !! pdu
+     .             zdvfi_omp,  !! pdv
+     .             zdtfi_omp,  !! pdt
+     .             zdqfi_omp,  !! pdq
+     .             zdpsrf_omp, !! pdpsrf
+     .             tracerdyn)      !! tracerdyn <-- utilite ???
+
+      endif ! of if (planet_type=="earth")
+
+
          zufi_omp(:,:)=zufi_omp(:,:)+zdufi_omp(:,:)*zdt_split
          zvfi_omp(:,:)=zvfi_omp(:,:)+zdvfi_omp(:,:)*zdt_split
@@ -723,4 +758,8 @@
       enddo
 
+#endif
+! of #ifdef CPP_PHYS
+
+
       zdufi_omp(:,:)=zdufic_omp(:,:)/nsplit_phys
       zdvfi_omp(:,:)=zdvfic_omp(:,:)/nsplit_phys
@@ -728,6 +767,4 @@
       zdqfi_omp(:,:,:)=zdqfic_omp(:,:,:)/nsplit_phys
 
-#endif
-      endif !of if (planet_type=="earth")
 c$OMP BARRIER
 
@@ -1179,11 +1216,10 @@
       firstcal = .FALSE.
 
-#else
-      write(*,*) "calfis_p: for now can only work with parallel physics"
-      write(lunout,*)
-   & "calfis_p: for now can only work with parallel physics"
-      stop
-#endif
-! of #ifdef CPP_EARTH
+#else 
+      write(lunout,*) 
+     & "calfis_p: for now can only work with parallel physics" 
+      stop 
+#endif 
+! of #ifdef CPP_PHYS
       RETURN
       END
Index: LMDZ5/branches/testing/libf/dyn3dmem/call_calfis_mod.F90
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/call_calfis_mod.F90	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dmem/call_calfis_mod.F90	(revision 1707)
@@ -136,6 +136,18 @@
   !$OMP END MASTER
    
-    jD_cur = jD_ref + day_ini - day_ref + int (itau * dtvr / daysec) 
-    jH_cur = jH_ref + (itau * dtvr / daysec - int(itau * dtvr / daysec)) 
+           jD_cur = jD_ref + day_ini - day_ref                           &
+     &        + itau/day_step
+
+           IF (planet_type .eq."generic") THEN
+              ! AS: we make jD_cur to be pday
+              jD_cur = int(day_ini + itau/day_step)
+           ENDIF
+
+           jH_cur = jH_ref + start_time +                                &
+     &              mod(itau,day_step)/float(day_step) 
+    if (jH_cur > 1.0 ) then
+      jD_cur = jD_cur +1.
+      jH_cur = jH_cur -1.
+    endif
 
 !   Inbterface avec les routines de phylmd (phymars ... )
Index: LMDZ5/branches/testing/libf/dyn3dmem/call_dissip_mod.F90
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/call_dissip_mod.F90	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dmem/call_dissip_mod.F90	(revision 1707)
@@ -240,4 +240,8 @@
     !$OMP END DO NOWAIT
 
+         if (1 == 0) then
+!!! Ehouarn: lines here 1) kill 1+1=2 in the dynamics
+!!!                     2) should probably not be here anyway
+!!! but are kept for those who would want to revert to previous behaviour
     !$OMP MASTER               
       DO ij =  1,iim
@@ -251,5 +255,6 @@
     !$OMP END MASTER
     
-    ENDIF
+    ENDIF ! of if (1 == 0)
+    endif ! of of (pole_nord)
         
     IF (pole_sud) THEN
@@ -269,4 +274,8 @@
     !$OMP END DO NOWAIT
 
+    if (1 == 0) then
+!!! Ehouarn: lines here 1) kill 1+1=2 in the dynamics
+!!!                     2) should probably not be here anyway
+!!! but are kept for those who would want to revert to previous behaviour
     !$OMP MASTER               
       DO ij =  1,iim
@@ -279,5 +288,6 @@
       ENDDO
     !$OMP END MASTER
-    ENDIF
+    ENDIF ! of if (1 == 0)
+    endif ! of if (pole_sud)
 
 
Index: LMDZ5/branches/testing/libf/dyn3dmem/ce0l.F90
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/ce0l.F90	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dmem/ce0l.F90	(revision 1707)
@@ -1,4 +1,4 @@
 !
-! $Id: ce0l.F90 1425 2010-09-02 13:45:23Z lguez $
+! $Id$
 !
 !-------------------------------------------------------------------------------
@@ -19,7 +19,8 @@
   USE dimphy
   USE comgeomphy
-  USE mod_phys_lmdz_para
+  USE mod_phys_lmdz_para, mpi_root_xx=>mpi_root
   USE mod_const_mpi
   USE infotrac
+  USE parallel, ONLY: finalize_parallel
 
 #ifdef CPP_IOIPSL
@@ -30,4 +31,5 @@
   IMPLICIT NONE
 #ifndef CPP_EARTH
+#include "iniprint.h"
   WRITE(lunout,*)'limit_netcdf: Earth-specific routine, needs Earth physics'
 #else
@@ -41,12 +43,20 @@
 #include "temps.h"
 #include "logic.h"
+#ifdef CPP_MPI
+      include 'mpif.h'
+#endif
+
   INTEGER, PARAMETER            :: longcles=20
+  INTEGER                       :: ierr
   REAL,    DIMENSION(longcles)  :: clesphy0
   REAL,    DIMENSION(iip1,jjp1) :: masque
   CHARACTER(LEN=15)             :: calnd
+  REAL,    DIMENSION(iip1,jjp1) :: phis ! geopotentiel au sol
 !-------------------------------------------------------------------------------
   CALL conf_gcm( 99, .TRUE. , clesphy0 )
 
+#ifdef CPP_MPI
   CALL init_mpi
+#endif
 
   CALL Init_Phys_lmdz(iim,jjp1,llm,1,(/(jjm-1)*iim+2/))
@@ -55,5 +65,5 @@
        CALL abort_gcm('ce0l','In parallel mode,                         &
  &                 ce0l must be called only                             &
- &                 for 1 process and 1 task')
+ &                 for 1 process and 1 task',1)
   ENDIF
 
@@ -76,9 +86,12 @@
 #endif
 
-  IF (config_inca /= 'none') THEN
+  IF (type_trac == 'inca') THEN
 #ifdef INCA
-    CALL init_const_lmdz(nbtr,anneeref,dayref,iphysiq,day_step,nday)
-    CALL init_inca_para(iim,jjm+1,klon,1,klon_mpi_para_nb,0)
-    WRITE(lunout,*)'nbtr =' , nbtr 
+      CALL init_const_lmdz( &
+         nbtr,anneeref,dayref,&
+         iphysiq,day_step,nday,& 
+         nbsrf, is_oce,is_sic,&
+         is_ter,is_lic)
+      
 #endif
   END IF
@@ -90,5 +103,5 @@
   WRITE(lunout,'(//)')
   WRITE(lunout,*) ' interbar = ',interbar
-  CALL etat0_netcdf(interbar,masque,ok_etat0)
+  CALL etat0_netcdf(interbar,masque,phis,ok_etat0)
 
   IF(ok_limit) THEN
@@ -101,4 +114,20 @@
   END IF
 
+  IF (grilles_gcm_netcdf) THEN
+     WRITE(lunout,'(//)')
+     WRITE(lunout,*) '  ***************************  '
+     WRITE(lunout,*) '  ***  grilles_gcm_netcdf ***  '
+     WRITE(lunout,*) '  ***************************  '
+     WRITE(lunout,'(//)')
+     CALL grilles_gcm_netcdf_sub(masque,phis)
+  END IF
+  
+#ifdef CPP_MPI
+!$OMP MASTER
+  CALL MPI_FINALIZE(ierr)
+  IF (ierr /= 0) CALL abort_gcm('ce0l','Error in MPI_FINALIZE',1)
+!$OMP END MASTER
+#endif
+
 #endif
 ! of #ifndef CPP_EARTH #else
Index: LMDZ5/branches/testing/libf/dyn3dmem/comconst.h
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/comconst.h	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dmem/comconst.h	(revision 1707)
@@ -1,23 +1,40 @@
 !
-! $Id: comconst.h 1279 2009-12-10 09:02:56Z fairhead $
+! $Id$
 !
 !-----------------------------------------------------------------------
 ! INCLUDE comconst.h
 
-      COMMON/comconst/im,jm,lllm,imp1,jmp1,lllmm1,lllmp1,lcl,           &
-     & dtvr,daysec,                                                     &
+      COMMON/comconsti/im,jm,lllm,imp1,jmp1,lllmm1,lllmp1,lcl,          &
+     &                 iflag_top_bound
+      COMMON/comconstr/dtvr,daysec,                                     &
      & pi,dtphys,dtdiss,rad,r,cpp,kappa,cotot,unsim,g,omeg              &
      &                   ,dissip_factz,dissip_deltaz,dissip_zref        &
-     &                   ,iflag_top_bound,tau_top_bound
+     &                   ,tau_top_bound,                                &
+     & daylen,year_day,molmass, ihf
 
 
       INTEGER im,jm,lllm,imp1,jmp1,lllmm1,lllmp1,lcl
-      REAL dtvr,daysec
-      REAL pi,dtphys,dtdiss,rad,r,cpp,kappa
-      REAL cotot,unsim,g,omeg
+      REAL dtvr ! dynamical time step (in s)
+      REAL daysec !length (in s) of a standard day
+      REAL pi    ! something like 3.14159....
+      REAL dtphys ! (s) time step for the physics
+      REAL dtdiss ! (s) time step for the dissipation
+      REAL rad ! (m) radius of the planet
+      REAL r ! Reduced Gas constant r=R/mu 
+             ! with R=8.31.. J.K-1.mol-1, mu: mol mass of atmosphere (kg/mol) 
+      REAL cpp   ! Specific heat Cp (J.kg-1.K-1)
+      REAL kappa ! kappa=R/Cp 
+      REAL cotot
+      REAL unsim ! = 1./iim
+      REAL g ! (m/s2) gravity
+      REAL omeg ! (rad/s) rotation rate of the planet
       REAL dissip_factz,dissip_deltaz,dissip_zref
       INTEGER iflag_top_bound
       REAL tau_top_bound
+      REAL daylen ! length of solar day, in 'standard' day length
+      REAL year_day ! Number of standard days in a year
+      REAL molmass ! (g/mol) molar mass of the atmosphere
 
+      REAL ihf ! (W/m2) Intrinsic heat flux (for giant planets)
 
 !-----------------------------------------------------------------------
Index: LMDZ5/branches/testing/libf/dyn3dmem/comdissipn.h
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/comdissipn.h	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dmem/comdissipn.h	(revision 1707)
@@ -1,16 +1,20 @@
 !
-! $Header$
+! $Id$
 !
-c-----------------------------------------------------------------------
-c INCLUDE comdissipn.h
+!  Attention : ce fichier include est compatible format fixe/format libre
+!                 veillez à n'utiliser que des ! pour les commentaires
+!                 et à bien positionner les & des lignes de continuation 
+!                 (les placer en colonne 6 et en colonne 73)
+!-----------------------------------------------------------------------
+! INCLUDE comdissipn.h
 
       REAL  tetaudiv, tetaurot, tetah, cdivu, crot, cdivh
-c
-      COMMON/comdissipn/ tetaudiv(llm),tetaurot(llm),tetah(llm)   ,
-     1                        cdivu,      crot,         cdivh
+!
+      COMMON/comdissipn/ tetaudiv(llm),tetaurot(llm),tetah(llm)   ,     &
+     &                        cdivu,      crot,         cdivh
 
-c
-c    Les parametres de ce common proviennent des calculs effectues dans 
-c             Inidissip  .
-c
-c-----------------------------------------------------------------------
+!
+!    Les parametres de ce common proviennent des calculs effectues dans 
+!             Inidissip  .
+!
+!-----------------------------------------------------------------------
Index: LMDZ5/branches/testing/libf/dyn3dmem/comdissnew.h
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/comdissnew.h	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dmem/comdissnew.h	(revision 1707)
@@ -12,8 +12,14 @@
 
       COMMON/comdissnew/ lstardis,nitergdiv,nitergrot,niterh,tetagdiv,  &
-     &                   tetagrot,tetatemp,coefdis 
+     &                   tetagrot,tetatemp,coefdis, vert_prof_dissip
 
       LOGICAL lstardis
       INTEGER nitergdiv, nitergrot, niterh
+
+      integer vert_prof_dissip ! vertical profile of horizontal dissipation
+!     Allowed values:
+!     0: rational fraction, function of pressure
+!     1: tanh of altitude
+
       REAL     tetagdiv, tetagrot,  tetatemp, coefdis
 
Index: LMDZ5/branches/testing/libf/dyn3dmem/comvert.h
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/comvert.h	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dmem/comvert.h	(revision 1707)
@@ -1,14 +1,27 @@
 !
-! $Header$
+! $Id$
 !
 !-----------------------------------------------------------------------
 !   INCLUDE 'comvert.h'
 
-      COMMON/comvert/ap(llm+1),bp(llm+1),presnivs(llm),dpres(llm),       &
-     &               pa,preff,nivsigs(llm),nivsig(llm+1)
+      COMMON/comvertr/ap(llm+1),bp(llm+1),presnivs(llm),dpres(llm),     &
+     &               pa,preff,nivsigs(llm),nivsig(llm+1),               &
+     &               aps(llm),bps(llm),scaleheight,pseudoalt(llm)
 
-      common/comverti/disvert_type
+      common/comverti/disvert_type, pressure_exner
 
-      REAL ap,bp,presnivs,dpres,pa,preff,nivsigs,nivsig
+      real ap     ! hybrid pressure contribution at interlayers
+      real bp     ! hybrid sigma contribution at interlayer
+      real presnivs ! (reference) pressure at mid-layers
+      real dpres
+      real pa     ! reference pressure (Pa) at which hybrid coordinates
+                  ! become purely pressure
+      real preff  ! reference surface pressure (Pa)
+      real nivsigs
+      real nivsig
+      real aps    ! hybrid pressure contribution at mid-layers
+      real bps    ! hybrid sigma contribution at mid-layers
+      real scaleheight ! atmospheric (reference) scale height (km)
+      real pseudoalt ! for planets
 
       integer disvert_type ! type of vertical discretization:
@@ -17,3 +30,8 @@
                            ! 2: Planets (default for planet_type!=earth),
                            !     using 'z2sig.def' (or 'esasig.def) file
-!-----------------------------------------------------------------------
+
+      logical pressure_exner
+!     compute pressure inside layers using Exner function, else use mean
+!     of pressure values at interfaces
+
+ !-----------------------------------------------------------------------
Index: LMDZ5/branches/testing/libf/dyn3dmem/conf_gcm.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/conf_gcm.F	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dmem/conf_gcm.F	(revision 1707)
@@ -1,4 +1,4 @@
 !
-! $Id: conf_gcm.F 1403 2010-07-01 09:02:53Z fairhead $
+! $Id$
 !
 c
@@ -6,4 +6,5 @@
       SUBROUTINE conf_gcm( tapedef, etatinit, clesphy0 )
 c
+      USE control_mod
 #ifdef CPP_IOIPSL
       use IOIPSL
@@ -17,5 +18,7 @@
       use mod_hallo, ONLY : use_mpi_alloc
       use parallel, ONLY : omp_chunk
-      USE control_mod
+      USE infotrac, ONLY : type_trac
+      use assert_m, only: assert
+
       IMPLICIT NONE
 c-----------------------------------------------------------------------
@@ -43,10 +46,10 @@
 #include "serre.h"
 #include "comdissnew.h"
-!#include "clesphys.h"
-#include "iniprint.h"
 #include "temps.h"
 #include "comconst.h"
 
 ! FH 2008/05/09 On elimine toutes les clefs physiques dans la dynamique
+! #include "clesphys.h"
+#include "iniprint.h"
 c
 c
@@ -103,5 +106,6 @@
       CALL getin('lunout', lunout)
       IF (lunout /= 5 .and. lunout /= 6) THEN
-        OPEN(lunout,FILE='lmdz.out')
+        OPEN(UNIT=lunout,FILE='lmdz.out_0000',ACTION='write', 
+     &          STATUS='unknown',FORM='formatted')
       ENDIF
 
@@ -166,4 +170,12 @@
       CALL getin('nday',nday)
 
+!Config  Key  = starttime
+!Config  Desc = Heure de depart de la simulation
+!Config  Def  = 0
+!Config  Help = Heure de depart de la simulation
+!Config         en jour
+      starttime = 0
+      CALL getin('starttime',starttime)
+
 !Config  Key  = day_step
 !Config  Desc = nombre de pas par jour
@@ -175,8 +187,4 @@
 
 !Config  Key  = nsplit_phys
-!Config  Desc = nombre d'iteration de la physique
-!Config  Def  = 240 
-!Config  Help = nombre d'itration de la physique
-!
        nsplit_phys = 1 
        CALL getin('nsplit_phys',nsplit_phys)
@@ -226,11 +234,12 @@
        CALL getin('output_grads_dyn',output_grads_dyn)
 
-!Config  Key  = idissip
+!Config  Key  = dissip_period
 !Config  Desc = periode de la dissipation 
-!Config  Def  = 10
+!Config  Def  = 0
 !Config  Help = periode de la dissipation 
-!Config         (en pas) ... a completer !
-       idissip = 10
-       CALL getin('idissip',idissip)
+!Config  dissip_period=0 => la valeur sera calcule dans inidissip       
+!Config  dissip_period>0 => on prend cette valeur
+       dissip_period = 0
+       CALL getin('dissip_period',dissip_period)
 
 ccc  ....   P. Le Van , modif le 29/04/97 .pour la dissipation  ...
@@ -314,5 +323,4 @@
        CALL getin('tau_top_bound',tau_top_bound)
 
-!
 !Config  Key  = coefdis
 !Config  Desc = coefficient pour gamdissip
@@ -579,4 +587,22 @@
        offline = .FALSE.
        CALL getin('offline',offline)
+       IF (offline .AND. adjust) THEN
+          WRITE(lunout,*) 
+     &         'WARNING : option offline does not work with adjust=y :'
+          WRITE(lunout,*) 'the files defstoke.nc, fluxstoke.nc ', 
+     &         'and fluxstokev.nc will not be created'
+          WRITE(lunout,*) 
+     &         'only the file phystoke.nc will still be created ' 
+       END IF
+       
+!Config  Key  = type_trac
+!Config  Desc = Choix de couplage avec model de chimie INCA ou REPROBUS
+!Config  Def  = lmdz
+!Config  Help = 
+!Config         'lmdz' = pas de couplage, pur LMDZ
+!Config         'inca' = model de chime INCA 
+!Config         'repr' = model de chime REPROBUS
+      type_trac = 'lmdz'
+      CALL getin('type_trac',type_trac)
 
 !Config  Key  = config_inca
@@ -628,5 +654,5 @@
       write(lunout,*)' periodav = ', periodav 
       write(lunout,*)' output_grads_dyn = ', output_grads_dyn
-      write(lunout,*)' idissip = ', idissip
+      write(lunout,*)' dissip_period = ', dissip_period
       write(lunout,*)' lstardis = ', lstardis
       write(lunout,*)' nitergdiv = ', nitergdiv
@@ -651,4 +677,5 @@
       write(lunout,*)' tauyy = ', tauyy
       write(lunout,*)' offline = ', offline
+      write(lunout,*)' type_trac = ', type_trac
       write(lunout,*)' config_inca = ', config_inca
       write(lunout,*)' ok_dynzon = ', ok_dynzon 
@@ -769,4 +796,22 @@
        offline = .FALSE.
        CALL getin('offline',offline)
+       IF (offline .AND. adjust) THEN
+          WRITE(lunout,*) 
+     &         'WARNING : option offline does not work with adjust=y :'
+          WRITE(lunout,*) 'the files defstoke.nc, fluxstoke.nc ', 
+     &         'and fluxstokev.nc will not be created'
+          WRITE(lunout,*) 
+     &         'only the file phystoke.nc will still be created ' 
+       END IF
+
+!Config  Key  = type_trac
+!Config  Desc = Choix de couplage avec model de chimie INCA ou REPROBUS
+!Config  Def  = lmdz
+!Config  Help = 
+!Config         'lmdz' = pas de couplage, pur LMDZ
+!Config         'inca' = model de chime INCA 
+!Config         'repr' = model de chime REPROBUS
+      type_trac = 'lmdz'
+      CALL getin('type_trac',type_trac)
 
 !Config  Key  = config_inca
@@ -781,5 +826,5 @@
 
 !Config  Key  = ok_dynzon 
-!Config  Desc = calcul et sortie des transports 
+!Config  Desc = sortie des transports zonaux dans la dynamique
 !Config  Def  = n 
 !Config  Help = Permet de mettre en route le calcul des transports 
@@ -817,5 +862,5 @@
         write(lunout,*)"Le zoom en longitude est incompatible",
      &                 " avec l'utilisation du filtre FFT ",
-     &                 "---> filtre FFT dÃ©sactivÃ© "
+     &                 "---> FFT filter not active"
        use_filtre_fft=.FALSE.
       ENDIF
@@ -851,4 +896,9 @@
       CALL getin('ok_strato',ok_strato)
 
+      vert_prof_dissip = merge(1, 0, ok_strato .and. llm==39)
+      CALL getin('vert_prof_dissip', vert_prof_dissip)
+      call assert(vert_prof_dissip == 0 .or. vert_prof_dissip ==  1,
+     $     "bad value for vert_prof_dissip")
+
 !Config  Key  = ok_gradsfile
 !Config  Desc = activation des sorties grads du guidage
@@ -874,4 +924,10 @@
       ok_etat0 = .TRUE.
       CALL getin('ok_etat0',ok_etat0)
+
+!Config  Key  = grilles_gcm_netcdf
+!Config  Desc = creation de fichier grilles_gcm.nc dans create_etat0_limit
+!Config  Def  = n
+      grilles_gcm_netcdf = .FALSE.
+      CALL getin('grilles_gcm_netcdf',grilles_gcm_netcdf)
 
       write(lunout,*)' #########################################'
@@ -889,5 +945,5 @@
       write(lunout,*)' periodav = ', periodav 
       write(lunout,*)' output_grads_dyn = ', output_grads_dyn
-      write(lunout,*)' idissip = ', idissip
+      write(lunout,*)' dissip_period = ', dissip_period
       write(lunout,*)' lstardis = ', lstardis
       write(lunout,*)' nitergdiv = ', nitergdiv
@@ -912,6 +968,7 @@
       write(lunout,*)' tauy = ', tauy
       write(lunout,*)' offline = ', offline
+      write(lunout,*)' type_trac = ', type_trac
       write(lunout,*)' config_inca = ', config_inca
-      write(lunout,*)' ok_dynzon = ', ok_dynzon 
+      write(lunout,*)' ok_dynzon = ', ok_dynzon
       write(lunout,*)' ok_dyn_ins = ', ok_dyn_ins 
       write(lunout,*)' ok_dyn_ave = ', ok_dyn_ave 
@@ -923,4 +980,5 @@
       write(lunout,*)' ok_limit = ', ok_limit
       write(lunout,*)' ok_etat0 = ', ok_etat0
+      write(lunout,*)' grilles_gcm_netcdf = ', grilles_gcm_netcdf
 c
       RETURN
Index: LMDZ5/branches/testing/libf/dyn3dmem/conf_planete.F90
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/conf_planete.F90	(revision 1707)
+++ LMDZ5/branches/testing/libf/dyn3dmem/conf_planete.F90	(revision 1707)
@@ -0,0 +1,70 @@
+!
+! $Id$
+!
+SUBROUTINE conf_planete
+!
+#ifdef CPP_IOIPSL
+USE IOIPSL
+#else
+! if not using IOIPSL, we still need to use (a local version of) getin
+USE ioipsl_getincom
+#endif
+IMPLICIT NONE
+!
+!
+!   Declarations :
+!   --------------
+#include "dimensions.h"
+#include "comconst.h"
+#include "comvert.h"
+!
+!   local:
+!   ------
+
+! ---------------------------------------------
+! Initialisations de constantes de la dynamique
+! ---------------------------------------------
+! Pi
+pi=2.*asin(1.)
+
+!Reference surface pressure (Pa)
+preff=101325.
+CALL getin('preff', preff)
+! Reference pressure at which hybrid coord. become purely pressure
+! pa=50000.
+pa=preff/2.
+CALL getin('pa', pa)
+! Gravity
+g=9.80665
+CALL getin('g',g)
+! Molar mass of the atmosphere
+molmass = 28.9644
+CALL getin('molmass',molmass)
+! kappa=R/Cp et Cp      
+kappa = 2./7.
+CALL getin('kappa',kappa)
+cpp=8.3145/molmass/kappa*1000.
+CALL getin('cpp',cpp)
+! Radius of the planet
+rad = 6371229. 
+CALL getin('radius',rad)
+! Length of a standard day (s)
+daysec=86400.
+CALL getin('daysec',daysec)
+! Rotation rate of the planet:
+! Length of a solar day, in standard days
+daylen = 1.
+CALL getin('daylen',daylen)
+! Number of days (standard) per year:
+year_day = 365.25
+CALL getin('year_day',year_day)
+! Omega
+! omeg=2.*pi/86400.
+omeg=2.*pi/daysec*(1./daylen+1./year_day)
+CALL getin('omeg',omeg)
+
+! Intrinsic heat flux (default: none) (only used if planet_type="giant")
+ihf = 0.
+call getin('ihf',ihf)
+
+END SUBROUTINE conf_planete
Index: LMDZ5/branches/testing/libf/dyn3dmem/control_mod.F90
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/control_mod.F90	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dmem/control_mod.F90	(revision 1707)
@@ -10,7 +10,7 @@
   IMPLICIT NONE
 
-  REAL    :: periodav
+  REAL    :: periodav, starttime
   INTEGER :: nday,day_step,iperiod,iapp_tracvl,nsplit_phys
-  INTEGER :: iconser,iecri,idissip,iphysiq,iecrimoy
+  INTEGER :: iconser,iecri,dissip_period,iphysiq,iecrimoy
   INTEGER :: dayref,anneeref, raz_date, ip_ebil_dyn
   LOGICAL :: offline
@@ -25,9 +25,3 @@
                      ! in NetCDF files dyn_hist*ave.nc
 
-  LOGICAL ok_dynzon  ! output zonal transports in dynzon.nc file
-  LOGICAL ok_dyn_ins ! output instantaneous values of fields
-                     ! in the dynamics in NetCDF files dyn_hist*nc
-  LOGICAL ok_dyn_ave ! output averaged values of fields in the dynamics
-                     ! in NetCDF files dyn_hist*ave.nc
-
 END MODULE
Index: LMDZ5/branches/testing/libf/dyn3dmem/defrun.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/defrun.F	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dmem/defrun.F	(revision 1707)
@@ -1,4 +1,4 @@
 !
-! $Id: defrun.F 1403 2010-07-01 09:02:53Z fairhead $
+! $Id$
 !
 c
@@ -132,7 +132,7 @@
 
       READ (tapedef,9001) ch1,ch4
-      READ (tapedef,*)    idissip
-      WRITE(tapeout,9001) ch1,'idissip'
-      WRITE(tapeout,*)    idissip
+      READ (tapedef,*)    dissip_period
+      WRITE(tapeout,9001) ch1,'dissip_period'
+      WRITE(tapeout,*)    dissip_period
 
 ccc  ....   P. Le Van , modif le 29/04/97 .pour la dissipation  ...
Index: LMDZ5/branches/testing/libf/dyn3dmem/disvert.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/disvert.F	(revision 1669)
+++ 	(revision )
@@ -1,194 +1,0 @@
-!
-! $Id: disvert.F 1403 2010-07-01 09:02:53Z fairhead $
-!
-      SUBROUTINE disvert(pa,preff,ap,bp,dpres,presnivs,nivsigs,nivsig)
-
-c    Auteur :  P. Le Van .
-c
-      IMPLICIT NONE
-
-#include "dimensions.h"
-#include "paramet.h"
-#include "iniprint.h"
-#include "logic.h"
-c
-c=======================================================================
-c
-c
-c    s = sigma ** kappa   :  coordonnee  verticale
-c    dsig(l)            : epaisseur de la couche l ds la coord.  s
-c    sig(l)             : sigma a l'interface des couches l et l-1
-c    ds(l)              : distance entre les couches l et l-1 en coord.s
-c
-c=======================================================================
-c
-      REAL pa,preff
-      REAL ap(llmp1),bp(llmp1),dpres(llm),nivsigs(llm),nivsig(llmp1)
-      REAL presnivs(llm)
-c
-c   declarations:
-c   -------------
-c
-      REAL sig(llm+1),dsig(llm)
-       real zzz(1:llm+1)
-       real dzz(1:llm)
-      real zk,zkm1,dzk1,dzk2,k0,k1
-c
-      INTEGER l
-      REAL snorm,dsigmin
-      REAL alpha,beta,gama,delta,deltaz,h
-      INTEGER np,ierr
-      REAL pi,x
-
-      REAL SSUM
-c
-c-----------------------------------------------------------------------
-c
-      pi=2.*ASIN(1.)
-
-      OPEN(99,file='sigma.def',status='old',form='formatted',
-     s   iostat=ierr)
-
-c-----------------------------------------------------------------------
-c   cas 1 on lit les options dans sigma.def:
-c   ----------------------------------------
-
-      IF (ierr.eq.0) THEN
-
-      READ(99,*) h           ! hauteur d'echelle 8.
-      READ(99,*) deltaz      ! epaiseur de la premiere couche 0.04
-      READ(99,*) beta        ! facteur d'acroissement en haut 1.3
-      READ(99,*) k0          ! nombre de couches dans la transition surf
-      READ(99,*) k1          ! nombre de couches dans la transition haute
-      CLOSE(99)
-      alpha=deltaz/(llm*h)
-      write(lunout,*)'h,alpha,k0,k1,beta'
-
-c     read(*,*) h,deltaz,beta,k0,k1 ! 8 0.04 4 20 1.2
-
-      alpha=deltaz/tanh(1./k0)*2.
-      zkm1=0.
-      sig(1)=1.
-      do l=1,llm
-        sig(l+1)=(cosh(l/k0))**(-alpha*k0/h)
-     + *exp(-alpha/h*tanh((llm-k1)/k0)*beta**(l-(llm-k1))/log(beta))
-        zk=-h*log(sig(l+1))
-
-        dzk1=alpha*tanh(l/k0)
-        dzk2=alpha*tanh((llm-k1)/k0)*beta**(l-(llm-k1))/log(beta)
-        write(lunout,*)l,sig(l+1),zk,zk-zkm1,dzk1,dzk2
-        zkm1=zk
-      enddo
-
-      sig(llm+1)=0.
-
-c
-       DO 2  l = 1, llm
-       dsig(l) = sig(l)-sig(l+1)
-   2   CONTINUE
-c
-
-      ELSE
-c-----------------------------------------------------------------------
-c   cas 2 ancienne discretisation (LMD5...):
-c   ----------------------------------------
-
-      WRITE(LUNOUT,*)'WARNING!!! Ancienne discretisation verticale'
-
-      if (ok_strato) then
-         if (llm==39) then
-            dsigmin=0.3
-         else if (llm==50) then
-            dsigmin=1.
-         else
-            WRITE(LUNOUT,*) 'ATTENTION discretisation z a ajuster'
-            dsigmin=1.
-         endif
-         WRITE(LUNOUT,*) 'Discretisation verticale DSIGMIN=',dsigmin
-      endif
-
-      h=7.
-      snorm  = 0.
-      DO l = 1, llm
-         x = 2.*asin(1.) * (REAL(l)-0.5) / REAL(llm+1)
-
-         IF (ok_strato) THEN
-           dsig(l) =(dsigmin + 7.0 * SIN(x)**2)
-     &            *(0.5*(1.-tanh(1.*(x-asin(1.))/asin(1.))))**2        
-         ELSE
-           dsig(l) = 1.0 + 7.0 * SIN(x)**2
-         ENDIF
-
-         snorm = snorm + dsig(l)
-      ENDDO
-      snorm = 1./snorm
-      DO l = 1, llm
-         dsig(l) = dsig(l)*snorm
-      ENDDO
-      sig(llm+1) = 0.
-      DO l = llm, 1, -1
-         sig(l) = sig(l+1) + dsig(l)
-      ENDDO
-
-      ENDIF
-
-
-      DO l=1,llm
-        nivsigs(l) = REAL(l)
-      ENDDO
-
-      DO l=1,llmp1
-        nivsig(l)= REAL(l)
-      ENDDO
-
-c
-c    ....  Calculs  de ap(l) et de bp(l)  ....
-c    .........................................
-c
-c
-c   .....  pa et preff sont lus  sur les fichiers start par lectba  .....
-c
-
-      bp(llmp1) =   0.
-
-      DO l = 1, llm
-cc
-ccc    ap(l) = 0.
-ccc    bp(l) = sig(l)
-
-      bp(l) = EXP( 1. -1./( sig(l)*sig(l)) )
-      ap(l) = pa * ( sig(l) - bp(l) )
-c
-      ENDDO
-
-      bp(1)=1.
-      ap(1)=0.
-
-      ap(llmp1) = pa * ( sig(llmp1) - bp(llmp1) )
-
-      write(lunout,*)' BP '
-      write(lunout,*)  bp
-      write(lunout,*)' AP '
-      write(lunout,*)  ap
-
-      write(lunout,*)
-     .'Niveaux de pressions approximatifs aux centres des'
-      write(lunout,*)'couches calcules pour une pression de surface =',
-     .                 preff
-      write(lunout,*)
-     .     'et altitudes equivalentes pour une hauteur d echelle de'
-      write(lunout,*)'8km'
-      DO l = 1, llm
-       dpres(l) = bp(l) - bp(l+1)
-       presnivs(l) = 0.5 *( ap(l)+bp(l)*preff + ap(l+1)+bp(l+1)*preff )
-       write(lunout,*)'PRESNIVS(',l,')=',presnivs(l),'    Z ~ ',
-     .        log(preff/presnivs(l))*8.
-     .  ,'   DZ ~ ',8.*log((ap(l)+bp(l)*preff)/
-     .       max(ap(l+1)+bp(l+1)*preff,1.e-10))
-      ENDDO
-
-      write(lunout,*)' PRESNIVS '
-      write(lunout,*)presnivs
-
-      RETURN
-      END
Index: LMDZ5/branches/testing/libf/dyn3dmem/disvert.F90
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/disvert.F90	(revision 1707)
+++ LMDZ5/branches/testing/libf/dyn3dmem/disvert.F90	(revision 1707)
@@ -0,0 +1,180 @@
+! $Id: disvert.F90 1645 2012-07-30 16:01:50Z lguez $
+
+SUBROUTINE disvert(pa,preff,ap,bp,dpres,presnivs,nivsigs,nivsig,scaleheight)
+
+  ! Auteur : P. Le Van
+
+  use new_unit_m, only: new_unit
+  use ioipsl, only: getin
+  use assert_m, only: assert
+
+  IMPLICIT NONE
+
+  include "dimensions.h"
+  include "paramet.h"
+  include "iniprint.h"
+  include "logic.h"
+
+  ! s = sigma ** kappa : coordonnee verticale
+  ! dsig(l) : epaisseur de la couche l ds la coord. s
+  ! sig(l) : sigma a l'interface des couches l et l-1
+  ! ds(l) : distance entre les couches l et l-1 en coord.s
+
+  real,intent(in) :: pa, preff
+  real,intent(out) :: ap(llmp1) ! in Pa
+  real, intent(out):: bp(llmp1)
+  real,intent(out) :: dpres(llm), nivsigs(llm), nivsig(llmp1)
+  real,intent(out) :: presnivs(llm)
+  real,intent(out) :: scaleheight
+
+  REAL sig(llm+1), dsig(llm)
+  real zk, zkm1, dzk1, dzk2, k0, k1
+
+  INTEGER l, unit
+  REAL dsigmin
+  REAL alpha, beta, deltaz
+  REAL x
+  character(len=*),parameter :: modname="disvert"
+
+  character(len=6):: vert_sampling
+  ! (allowed values are "param", "tropo", "strato" and "read")
+
+  !-----------------------------------------------------------------------
+
+  print *, "Call sequence information: disvert"
+
+  ! default scaleheight is 8km for earth
+  scaleheight=8.
+
+  vert_sampling = merge("strato", "tropo ", ok_strato) ! default value
+  call getin('vert_sampling', vert_sampling)
+  print *, 'vert_sampling = ' // vert_sampling
+
+  select case (vert_sampling)
+  case ("param")
+     ! On lit les options dans sigma.def:
+     OPEN(99, file='sigma.def', status='old', form='formatted')
+     READ(99, *) scaleheight ! hauteur d'echelle 8.
+     READ(99, *) deltaz ! epaiseur de la premiere couche 0.04
+     READ(99, *) beta ! facteur d'acroissement en haut 1.3
+     READ(99, *) k0 ! nombre de couches dans la transition surf
+     READ(99, *) k1 ! nombre de couches dans la transition haute
+     CLOSE(99)
+     alpha=deltaz/(llm*scaleheight)
+     write(lunout, *)trim(modname),':scaleheight, alpha, k0, k1, beta', &
+                               scaleheight, alpha, k0, k1, beta
+
+     alpha=deltaz/tanh(1./k0)*2.
+     zkm1=0.
+     sig(1)=1.
+     do l=1, llm
+        sig(l+1)=(cosh(l/k0))**(-alpha*k0/scaleheight) &
+             *exp(-alpha/scaleheight*tanh((llm-k1)/k0) &
+                  *beta**(l-(llm-k1))/log(beta))
+        zk=-scaleheight*log(sig(l+1))
+
+        dzk1=alpha*tanh(l/k0)
+        dzk2=alpha*tanh((llm-k1)/k0)*beta**(l-(llm-k1))/log(beta)
+        write(lunout, *)l, sig(l+1), zk, zk-zkm1, dzk1, dzk2
+        zkm1=zk
+     enddo
+
+     sig(llm+1)=0.
+
+     bp(: llm) = EXP(1. - 1. / sig(: llm)**2)
+     bp(llmp1) = 0.
+
+     ap = pa * (sig - bp)
+  case("tropo")
+     DO l = 1, llm
+        x = 2*asin(1.) * (l - 0.5) / (llm + 1)
+        dsig(l) = 1.0 + 7.0 * SIN(x)**2
+     ENDDO
+     dsig = dsig / sum(dsig)
+     sig(llm+1) = 0.
+     DO l = llm, 1, -1
+        sig(l) = sig(l+1) + dsig(l)
+     ENDDO
+
+     bp(1)=1.
+     bp(2: llm) = EXP(1. - 1. / sig(2: llm)**2)
+     bp(llmp1) = 0.
+
+     ap(1)=0.
+     ap(2: llm + 1) = pa * (sig(2: llm + 1) - bp(2: llm + 1))
+  case("strato")
+     if (llm==39) then
+        dsigmin=0.3
+     else if (llm==50) then
+        dsigmin=1.
+     else
+        write(lunout,*) trim(modname), ' ATTENTION discretisation z a ajuster'
+        dsigmin=1.
+     endif
+     WRITE(LUNOUT,*) trim(modname), 'Discretisation verticale DSIGMIN=',dsigmin
+
+     DO l = 1, llm
+        x = 2*asin(1.) * (l - 0.5) / (llm + 1)
+        dsig(l) =(dsigmin + 7. * SIN(x)**2) &
+             *(0.5*(1.-tanh(1.*(x-asin(1.))/asin(1.))))**2
+     ENDDO
+     dsig = dsig / sum(dsig)
+     sig(llm+1) = 0.
+     DO l = llm, 1, -1
+        sig(l) = sig(l+1) + dsig(l)
+     ENDDO
+
+     bp(1)=1.
+     bp(2: llm) = EXP(1. - 1. / sig(2: llm)**2)
+     bp(llmp1) = 0.
+
+     ap(1)=0.
+     ap(2: llm + 1) = pa * (sig(2: llm + 1) - bp(2: llm + 1))
+  case("read")
+     ! Read "ap" and "bp". First line is skipped (title line). "ap"
+     ! should be in Pa. First couple of values should correspond to
+     ! the surface, that is : "bp" should be in descending order.
+     call new_unit(unit)
+     open(unit, file="hybrid.txt", status="old", action="read", &
+          position="rewind")
+     read(unit, fmt=*) ! skip title line
+     do l = 1, llm + 1
+        read(unit, fmt=*) ap(l), bp(l)
+     end do
+     close(unit)
+     call assert(ap(1) == 0., ap(llm + 1) == 0., bp(1) == 1., &
+          bp(llm + 1) == 0., "disvert: bad ap or bp values")
+  case default
+     call abort_gcm("disvert", 'Wrong value for "vert_sampling"', 1)
+  END select
+
+  DO l=1, llm
+     nivsigs(l) = REAL(l)
+  ENDDO
+
+  DO l=1, llmp1
+     nivsig(l)= REAL(l)
+  ENDDO
+
+  write(lunout, *)  trim(modname),': BP '
+  write(lunout, *) bp
+  write(lunout, *)  trim(modname),': AP '
+  write(lunout, *) ap
+
+  write(lunout, *) 'Niveaux de pressions approximatifs aux centres des'
+  write(lunout, *)'couches calcules pour une pression de surface =', preff
+  write(lunout, *) 'et altitudes equivalentes pour une hauteur d echelle de '
+  write(lunout, *) scaleheight,' km'
+  DO l = 1, llm
+     dpres(l) = bp(l) - bp(l+1)
+     presnivs(l) = 0.5 *( ap(l)+bp(l)*preff + ap(l+1)+bp(l+1)*preff )
+     write(lunout, *)'PRESNIVS(', l, ')=', presnivs(l), ' Z ~ ', &
+          log(preff/presnivs(l))*scaleheight &
+          , ' DZ ~ ', scaleheight*log((ap(l)+bp(l)*preff)/ &
+          max(ap(l+1)+bp(l+1)*preff, 1.e-10))
+  ENDDO
+
+  write(lunout, *) trim(modname),': PRESNIVS '
+  write(lunout, *) presnivs
+
+END SUBROUTINE disvert
Index: LMDZ5/branches/testing/libf/dyn3dmem/disvert_noterre.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/disvert_noterre.F	(revision 1707)
+++ LMDZ5/branches/testing/libf/dyn3dmem/disvert_noterre.F	(revision 1707)
@@ -0,0 +1,330 @@
+! $Id$
+      SUBROUTINE disvert_noterre
+
+c    Auteur :  F. Forget Y. Wanherdrick, P. Levan
+c    Nouvelle version 100% Mars !!
+c    On l'utilise aussi pour Venus et Titan, legerment modifiee.
+
+#ifdef CPP_IOIPSL
+      use IOIPSL
+#else
+! if not using IOIPSL, we still need to use (a local version of) getin
+      use ioipsl_getincom
+#endif
+
+      IMPLICIT NONE
+
+#include "dimensions.h"
+#include "paramet.h"
+#include "comvert.h"
+#include "comconst.h"
+#include "logic.h"
+#include "iniprint.h"
+c
+c=======================================================================
+c    Discretisation verticale en coordonnée hybride (ou sigma)
+c
+c=======================================================================
+c
+c   declarations:
+c   -------------
+c
+c
+      INTEGER l,ll
+      REAL snorm
+      REAL alpha,beta,gama,delta,deltaz
+      real quoi,quand
+      REAL zsig(llm),sig(llm+1)
+      INTEGER np,ierr
+      integer :: ierr1,ierr2,ierr3,ierr4
+      REAL x
+
+      REAL SSUM
+      EXTERNAL SSUM
+      real newsig 
+      REAL dz0,dz1,nhaut,sig1,esig,csig,zz
+      real tt,rr,gg, prevz
+      real s(llm),dsig(llm) 
+
+      integer iz 
+      real z, ps,p
+      character(len=*),parameter :: modname="disvert_noterre"
+
+c
+c-----------------------------------------------------------------------
+c
+! Initializations:
+!      pi=2.*ASIN(1.) ! already done in iniconst
+      
+      hybrid=.true. ! default value for hybrid (ie: use hybrid coordinates)
+      CALL getin('hybrid',hybrid)
+      write(lunout,*) trim(modname),': hybrid=',hybrid
+
+! Ouverture possible de fichiers typiquement E.T.
+
+         open(99,file="esasig.def",status='old',form='formatted',
+     s   iostat=ierr2)
+         if(ierr2.ne.0) then
+              close(99)
+              open(99,file="z2sig.def",status='old',form='formatted',
+     s        iostat=ierr4)
+         endif
+
+c-----------------------------------------------------------------------
+c   cas 1 on lit les options dans esasig.def:
+c   ----------------------------------------
+
+      IF(ierr2.eq.0) then
+
+c        Lecture de esasig.def :
+c        Systeme peu souple, mais qui respecte en theorie
+c        La conservation de l'energie (conversion Energie potentielle
+c        <-> energie cinetique, d'apres la note de Frederic Hourdin...
+
+         write(lunout,*)'*****************************'
+         write(lunout,*)'WARNING reading esasig.def'
+         write(lunout,*)'*****************************'
+         READ(99,*) scaleheight
+         READ(99,*) dz0
+         READ(99,*) dz1
+         READ(99,*) nhaut
+         CLOSE(99)
+
+         dz0=dz0/scaleheight
+         dz1=dz1/scaleheight
+
+         sig1=(1.-dz1)/tanh(.5*(llm-1)/nhaut)
+
+         esig=1.
+
+         do l=1,20
+            esig=-log((1./sig1-1.)*exp(-dz0)/esig)/(llm-1.)
+         enddo
+         csig=(1./sig1-1.)/(exp(esig)-1.)
+
+         DO L = 2, llm
+            zz=csig*(exp(esig*(l-1.))-1.)
+            sig(l) =1./(1.+zz)
+     &      * tanh(.5*(llm+1-l)/nhaut)
+         ENDDO
+         sig(1)=1.
+         sig(llm+1)=0.
+         quoi      = 1. + 2.* kappa
+         s( llm )  = 1.
+         s(llm-1) = quoi
+         IF( llm.gt.2 )  THEN
+            DO  ll = 2, llm-1
+               l         = llm+1 - ll
+               quand     = sig(l+1)/ sig(l)
+               s(l-1)    = quoi * (1.-quand) * s(l)  + quand * s(l+1)
+            ENDDO
+         END IF
+c
+         snorm=(1.-.5*sig(2)+kappa*(1.-sig(2)))*s(1)+.5*sig(2)*s(2)
+         DO l = 1, llm
+            s(l)    = s(l)/ snorm
+         ENDDO
+
+c-----------------------------------------------------------------------
+c   cas 2 on lit les options dans z2sig.def:
+c   ----------------------------------------
+
+      ELSE IF(ierr4.eq.0) then
+         write(lunout,*)'****************************'
+         write(lunout,*)'Reading z2sig.def'
+         write(lunout,*)'****************************'
+
+         READ(99,*) scaleheight
+         do l=1,llm
+            read(99,*) zsig(l)
+         end do
+         CLOSE(99)
+
+         sig(1) =1
+         do l=2,llm
+           sig(l) = 0.5 * ( exp(-zsig(l)/scaleheight) + 
+     &                      exp(-zsig(l-1)/scaleheight) )
+         end do
+         sig(llm+1) =0
+
+c-----------------------------------------------------------------------
+      ELSE
+         write(lunout,*) 'didn t you forget something ??? '
+         write(lunout,*) 'We need file  z2sig.def ! (OR esasig.def)'
+         stop
+      ENDIF
+c-----------------------------------------------------------------------
+
+      DO l=1,llm
+        nivsigs(l) = REAL(l)
+      ENDDO
+
+      DO l=1,llmp1
+        nivsig(l)= REAL(l)
+      ENDDO
+
+ 
+c-----------------------------------------------------------------------
+c    ....  Calculs  de ap(l) et de bp(l)  ....
+c    .........................................
+c
+c   .....  pa et preff sont lus  sur les fichiers start par dynetat0 .....
+c-----------------------------------------------------------------------
+c
+
+      if (hybrid) then  ! use hybrid coordinates
+         write(lunout,*) "*********************************"
+         write(lunout,*) "Using hybrid vertical coordinates"
+         write(lunout,*) 
+c        Coordonnees hybrides avec mod
+         DO l = 1, llm
+
+         call sig_hybrid(sig(l),pa,preff,newsig)
+            bp(l) = EXP( 1. - 1./(newsig**2)  )
+            ap(l) = pa * (newsig - bp(l) )
+         enddo
+         bp(llmp1) = 0.
+         ap(llmp1) = 0.
+      else ! use sigma coordinates
+         write(lunout,*) "********************************"
+         write(lunout,*) "Using sigma vertical coordinates"
+         write(lunout,*) 
+c        Pour ne pas passer en coordonnees hybrides
+         DO l = 1, llm
+            ap(l) = 0.
+            bp(l) = sig(l)
+         ENDDO
+         ap(llmp1) = 0.
+      endif
+
+      bp(llmp1) =   0.
+
+      write(lunout,*) trim(modname),': BP '
+      write(lunout,*)  bp
+      write(lunout,*) trim(modname),': AP '
+      write(lunout,*)  ap
+
+c     Calcul au milieu des couches :
+c     WARNING : le choix de placer le milieu des couches au niveau de
+c     pression intermédiaire est arbitraire et pourrait etre modifié.
+c     Le calcul du niveau pour la derniere couche 
+c     (on met la meme distance (en log pression)  entre P(llm)
+c     et P(llm -1) qu'entre P(llm-1) et P(llm-2) ) est
+c     Specifique.  Ce choix est spécifié ici ET dans exner_milieu.F
+
+      DO l = 1, llm-1
+       aps(l) =  0.5 *( ap(l) +ap(l+1)) 
+       bps(l) =  0.5 *( bp(l) +bp(l+1)) 
+      ENDDO
+     
+      if (hybrid) then
+         aps(llm) = aps(llm-1)**2 / aps(llm-2) 
+         bps(llm) = 0.5*(bp(llm) + bp(llm+1))
+      else
+         bps(llm) = bps(llm-1)**2 / bps(llm-2) 
+         aps(llm) = 0.
+      end if
+
+      write(lunout,*) trim(modname),': BPs '
+      write(lunout,*)  bps
+      write(lunout,*) trim(modname),': APs'
+      write(lunout,*)  aps
+
+      DO l = 1, llm
+       presnivs(l) = aps(l)+bps(l)*preff
+       pseudoalt(l) = -scaleheight*log(presnivs(l)/preff)
+      ENDDO
+
+      write(lunout,*)trim(modname),' : PRESNIVS' 
+      write(lunout,*)presnivs 
+      write(lunout,*)'Pseudo altitude of Presnivs : (for a scale ',
+     &                'height of ',scaleheight,' km)' 
+      write(lunout,*)pseudoalt
+
+c     --------------------------------------------------
+c     This can be used to plot the vertical discretization
+c     (> xmgrace -nxy testhybrid.tab )
+c     --------------------------------------------------
+c     open (53,file='testhybrid.tab')
+c     scaleheight=15.5
+c     do iz=0,34
+c       z = -5 + min(iz,34-iz)
+c     approximation of scale height for Venus
+c       scaleheight = 15.5 - z/55.*10.
+c       ps = preff*exp(-z/scaleheight)
+c       zsig(1)= -scaleheight*log((aps(1) + bps(1)*ps)/preff)
+c       do l=2,llm
+c     approximation of scale height for Venus
+c          if (zsig(l-1).le.55.) then
+c             scaleheight = 15.5 - zsig(l-1)/55.*10.
+c          else
+c             scaleheight = 5.5 - (zsig(l-1)-55.)/35.*2.
+c          endif
+c          zsig(l)= zsig(l-1)-scaleheight*
+c    .    log((aps(l) + bps(l)*ps)/(aps(l-1) + bps(l-1)*ps))
+c       end do
+c       write(53,'(I3,50F10.5)') iz, zsig
+c      end do
+c      close(53)
+c     --------------------------------------------------
+
+
+      RETURN
+      END
+
+c ************************************************************
+      subroutine sig_hybrid(sig,pa,preff,newsig)
+c     ----------------------------------------------
+c     Subroutine utilisee pour calculer des valeurs de sigma modifie
+c     pour conserver les coordonnees verticales decrites dans
+c     esasig.def/z2sig.def lors du passage en coordonnees hybrides
+c     F. Forget 2002
+c     Connaissant sig (niveaux "sigma" ou on veut mettre les couches)
+c     L'objectif est de calculer newsig telle que
+c       (1 -pa/preff)*exp(1-1./newsig**2)+(pa/preff)*newsig = sig
+c     Cela ne se résoud pas analytiquement: 
+c     => on résoud par iterration bourrine 
+c     ----------------------------------------------
+c     Information  : where exp(1-1./x**2) become << x
+c           x      exp(1-1./x**2) /x
+c           1           1
+c           0.68       0.5
+c           0.5        1.E-1
+c           0.391      1.E-2
+c           0.333      1.E-3
+c           0.295      1.E-4
+c           0.269      1.E-5
+c           0.248      1.E-6
+c        => on peut utiliser newsig = sig*preff/pa si sig*preff/pa < 0.25
+
+
+      implicit none
+      real x1, x2, sig,pa,preff, newsig, F
+      integer j
+
+      newsig = sig
+      x1=0
+      x2=1
+      if (sig.ge.1) then
+            newsig= sig
+      else if (sig*preff/pa.ge.0.25) then
+        DO J=1,9999  ! nombre d''iteration max
+          F=((1 -pa/preff)*exp(1-1./newsig**2)+(pa/preff)*newsig)/sig
+c         write(0,*) J, ' newsig =', newsig, ' F= ', F
+          if (F.gt.1) then
+              X2 = newsig
+              newsig=(X1+newsig)*0.5
+          else
+              X1 = newsig
+              newsig=(X2+newsig)*0.5
+          end if
+c         Test : on arete lorsque on approxime sig à moins de 0.01 m près 
+c         (en pseudo altitude) :
+          IF(abs(10.*log(F)).LT.1.E-5) goto 999
+        END DO
+       else   !    if (sig*preff/pa.le.0.25) then
+             newsig= sig*preff/pa
+       end if
+ 999   continue
+       Return
+      END
Index: LMDZ5/branches/testing/libf/dyn3dmem/dynetat0.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/dynetat0.F	(revision 1669)
+++ 	(revision )
@@ -1,386 +1,0 @@
-!
-! $Id $
-!
-      SUBROUTINE dynetat0(fichnom,vcov,ucov,
-     .                    teta,q,masse,ps,phis,time)
-
-      USE infotrac
-      IMPLICIT NONE
-
-c=======================================================================
-c
-c   Auteur:  P. Le Van / L.Fairhead
-c   -------
-c
-c   objet:
-c   ------
-c
-c   Lecture de l'etat initial
-c
-c=======================================================================
-c-----------------------------------------------------------------------
-c   Declarations:
-c   -------------
-
-#include "dimensions.h"
-#include "paramet.h"
-#include "temps.h"
-#include "comconst.h"
-#include "comvert.h"
-#include "comgeom.h"
-#include "ener.h"
-#include "netcdf.inc"
-#include "description.h"
-#include "serre.h"
-#include "logic.h"
-#include "iniprint.h"
-
-c   Arguments:
-c   ----------
-
-      CHARACTER*(*) fichnom
-      REAL vcov(ip1jm,llm),ucov(ip1jmp1,llm),teta(ip1jmp1,llm)
-      REAL q(ip1jmp1,llm,nqtot),masse(ip1jmp1,llm)
-      REAL ps(ip1jmp1),phis(ip1jmp1)
-
-      REAL time
-
-c   Variables 
-c
-      INTEGER length,iq
-      PARAMETER (length = 100)
-      REAL tab_cntrl(length) ! tableau des parametres du run
-      INTEGER ierr, nid, nvarid
-
-c-----------------------------------------------------------------------
-
-c  Ouverture NetCDF du fichier etat initial
-
-      ierr = NF_OPEN (fichnom, NF_NOWRITE,nid)
-      IF (ierr.NE.NF_NOERR) THEN
-        write(lunout,*)'dynetat0: Pb d''ouverture du fichier start.nc'
-        write(lunout,*)' ierr = ', ierr
-        CALL ABORT
-      ENDIF
-
-c
-      ierr = NF_INQ_VARID (nid, "controle", nvarid)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Le champ <controle> est absent"
-         CALL abort
-      ENDIF
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(nid, nvarid, tab_cntrl)
-#else
-      ierr = NF_GET_VAR_REAL(nid, nvarid, tab_cntrl)
-#endif
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Lecture echoue pour <controle>"
-         CALL abort
-      ENDIF
-
-      im         = tab_cntrl(1)
-      jm         = tab_cntrl(2)
-      lllm       = tab_cntrl(3)
-      day_ref    = tab_cntrl(4)
-      annee_ref  = tab_cntrl(5)
-      rad        = tab_cntrl(6)
-      omeg       = tab_cntrl(7)
-      g          = tab_cntrl(8)
-      cpp        = tab_cntrl(9)
-      kappa      = tab_cntrl(10)
-      daysec     = tab_cntrl(11)
-      dtvr       = tab_cntrl(12)
-      etot0      = tab_cntrl(13)
-      ptot0      = tab_cntrl(14)
-      ztot0      = tab_cntrl(15)
-      stot0      = tab_cntrl(16)
-      ang0       = tab_cntrl(17)
-      pa         = tab_cntrl(18)
-      preff      = tab_cntrl(19)
-c
-      clon       = tab_cntrl(20)
-      clat       = tab_cntrl(21)
-      grossismx  = tab_cntrl(22)
-      grossismy  = tab_cntrl(23)
-c
-      IF ( tab_cntrl(24).EQ.1. )  THEN
-        fxyhypb  = . TRUE .
-c        dzoomx   = tab_cntrl(25)
-c        dzoomy   = tab_cntrl(26)
-c        taux     = tab_cntrl(28)
-c        tauy     = tab_cntrl(29)
-      ELSE
-        fxyhypb = . FALSE .
-        ysinus  = . FALSE .
-        IF( tab_cntrl(27).EQ.1. ) ysinus = . TRUE. 
-      ENDIF
-
-      day_ini = tab_cntrl(30)
-      itau_dyn = tab_cntrl(31)
-c   .................................................................
-c
-c
-      write(lunout,*)'dynetat0: rad,omeg,g,cpp,kappa',
-     &               rad,omeg,g,cpp,kappa
-
-      IF(   im.ne.iim           )  THEN
-          PRINT 1,im,iim
-          STOP
-      ELSE  IF( jm.ne.jjm       )  THEN
-          PRINT 2,jm,jjm
-          STOP
-      ELSE  IF( lllm.ne.llm     )  THEN
-          PRINT 3,lllm,llm
-          STOP
-      ENDIF
-
-      ierr = NF_INQ_VARID (nid, "rlonu", nvarid)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Le champ <rlonu> est absent"
-         CALL abort
-      ENDIF
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(nid, nvarid, rlonu)
-#else
-      ierr = NF_GET_VAR_REAL(nid, nvarid, rlonu)
-#endif
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Lecture echouee pour <rlonu>"
-         CALL abort
-      ENDIF
-
-      ierr = NF_INQ_VARID (nid, "rlatu", nvarid)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Le champ <rlatu> est absent"
-         CALL abort
-      ENDIF
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(nid, nvarid, rlatu)
-#else
-      ierr = NF_GET_VAR_REAL(nid, nvarid, rlatu)
-#endif
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Lecture echouee pour <rlatu>"
-         CALL abort
-      ENDIF
-
-      ierr = NF_INQ_VARID (nid, "rlonv", nvarid)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Le champ <rlonv> est absent"
-         CALL abort
-      ENDIF
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(nid, nvarid, rlonv)
-#else
-      ierr = NF_GET_VAR_REAL(nid, nvarid, rlonv)
-#endif
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Lecture echouee pour <rlonv>"
-         CALL abort
-      ENDIF
-
-      ierr = NF_INQ_VARID (nid, "rlatv", nvarid)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Le champ <rlatv> est absent"
-         CALL abort
-      ENDIF
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(nid, nvarid, rlatv)
-#else
-      ierr = NF_GET_VAR_REAL(nid, nvarid, rlatv)
-#endif
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Lecture echouee pour rlatv"
-         CALL abort
-      ENDIF
-
-      ierr = NF_INQ_VARID (nid, "cu", nvarid)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Le champ <cu> est absent"
-         CALL abort
-      ENDIF
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(nid, nvarid, cu)
-#else
-      ierr = NF_GET_VAR_REAL(nid, nvarid, cu)
-#endif
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Lecture echouee pour <cu>"
-         CALL abort
-      ENDIF
-
-      ierr = NF_INQ_VARID (nid, "cv", nvarid)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Le champ <cv> est absent"
-         CALL abort
-      ENDIF
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(nid, nvarid, cv)
-#else
-      ierr = NF_GET_VAR_REAL(nid, nvarid, cv)
-#endif
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Lecture echouee pour <cv>"
-         CALL abort
-      ENDIF
-
-      ierr = NF_INQ_VARID (nid, "aire", nvarid)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Le champ <aire> est absent"
-         CALL abort
-      ENDIF
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(nid, nvarid, aire)
-#else
-      ierr = NF_GET_VAR_REAL(nid, nvarid, aire)
-#endif
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Lecture echouee pour <aire>"
-         CALL abort
-      ENDIF
-
-      ierr = NF_INQ_VARID (nid, "phisinit", nvarid)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Le champ <phisinit> est absent"
-         CALL abort
-      ENDIF
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(nid, nvarid, phis)
-#else
-      ierr = NF_GET_VAR_REAL(nid, nvarid, phis)
-#endif
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Lecture echouee pour <phisinit>"
-         CALL abort
-      ENDIF
-
-      ierr = NF_INQ_VARID (nid, "temps", nvarid)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Le champ <temps> est absent"
-         CALL abort
-      ENDIF
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(nid, nvarid, time)
-#else
-      ierr = NF_GET_VAR_REAL(nid, nvarid, time)
-#endif
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Lecture echouee <temps>"
-         CALL abort
-      ENDIF
-
-      ierr = NF_INQ_VARID (nid, "ucov", nvarid)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Le champ <ucov> est absent"
-         CALL abort
-      ENDIF
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(nid, nvarid, ucov)
-#else
-      ierr = NF_GET_VAR_REAL(nid, nvarid, ucov)
-#endif
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Lecture echouee pour <ucov>"
-         CALL abort
-      ENDIF
- 
-      ierr = NF_INQ_VARID (nid, "vcov", nvarid)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Le champ <vcov> est absent"
-         CALL abort
-      ENDIF
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(nid, nvarid, vcov)
-#else
-      ierr = NF_GET_VAR_REAL(nid, nvarid, vcov)
-#endif
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Lecture echouee pour <vcov>"
-         CALL abort
-      ENDIF
-
-      ierr = NF_INQ_VARID (nid, "teta", nvarid)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Le champ <teta> est absent"
-         CALL abort
-      ENDIF
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(nid, nvarid, teta)
-#else
-      ierr = NF_GET_VAR_REAL(nid, nvarid, teta)
-#endif
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Lecture echouee pour <teta>"
-         CALL abort
-      ENDIF
-
-
-      IF(nqtot.GE.1) THEN
-      DO iq=1,nqtot
-        ierr =  NF_INQ_VARID (nid, tname(iq), nvarid)
-        IF (ierr .NE. NF_NOERR) THEN
-           write(lunout,*)"dynetat0: Le traceur <"//trim(tname(iq))//
-     &                    "> est absent"
-           write(lunout,*)"          Il est donc initialise a zero"
-           q(:,:,iq)=0.
-        ELSE
-#ifdef NC_DOUBLE
-          ierr = NF_GET_VAR_DOUBLE(nid, nvarid, q(1,1,iq))
-#else
-          ierr = NF_GET_VAR_REAL(nid, nvarid, q(1,1,iq))
-#endif
-          IF (ierr .NE. NF_NOERR) THEN
-            write(lunout,*)"dynetat0: Lecture echouee pour "//tname(iq)
-            CALL abort
-          ENDIF
-        ENDIF
-      ENDDO
-      ENDIF
-
-      ierr = NF_INQ_VARID (nid, "masse", nvarid)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Le champ <masse> est absent"
-         CALL abort
-      ENDIF
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(nid, nvarid, masse)
-#else
-      ierr = NF_GET_VAR_REAL(nid, nvarid, masse)
-#endif
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Lecture echouee pour <masse>"
-         CALL abort
-      ENDIF
-
-      ierr = NF_INQ_VARID (nid, "ps", nvarid)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Le champ <ps> est absent"
-         CALL abort
-      ENDIF
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(nid, nvarid, ps)
-#else
-      ierr = NF_GET_VAR_REAL(nid, nvarid, ps)
-#endif
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Lecture echouee pour <ps>"
-         CALL abort
-      ENDIF
-
-      ierr = NF_CLOSE(nid)
-
-       day_ini=day_ini+INT(time)
-       time=time-INT(time)
-
-  1   FORMAT(//10x,'la valeur de im =',i4,2x,'lue sur le fichier de dem
-     *arrage est differente de la valeur parametree iim =',i4//)
-   2  FORMAT(//10x,'la valeur de jm =',i4,2x,'lue sur le fichier de dem
-     *arrage est differente de la valeur parametree jjm =',i4//)
-   3  FORMAT(//10x,'la valeur de lmax =',i4,2x,'lue sur le fichier dema
-     *rrage est differente de la valeur parametree llm =',i4//)
-   4  FORMAT(//10x,'la valeur de dtrv =',i4,2x,'lue sur le fichier dema
-     *rrage est differente de la valeur  dtinteg =',i4//)
-
-      RETURN
-      END
Index: LMDZ5/branches/testing/libf/dyn3dmem/dynetat0_loc.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/dynetat0_loc.F	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dmem/dynetat0_loc.F	(revision 1707)
@@ -5,4 +5,5 @@
      .                    teta,q,masse,ps,phis,time)
       USE infotrac
+      use control_mod, only : planet_type
       USE parallel
       IMPLICIT NONE
@@ -57,4 +58,6 @@
       REAL,ALLOCATABLE :: phis_glo(:)
 
+      INTEGER idecal
+
 c-----------------------------------------------------------------------
 c  Ouverture NetCDF du fichier etat initial
@@ -84,30 +87,42 @@
       ENDIF
 
+      !!! AS: idecal is a hack to be able to read planeto starts...
+      !!!     .... while keeping everything OK for LMDZ EARTH
+      if (planet_type.eq."generic") then
+          print*,'NOTE NOTE NOTE : Planeto-like start files'
+          idecal = 4
+          annee_ref  = 2000
+      else
+          print*,'NOTE NOTE NOTE : Earth-like start files'
+          idecal = 5
+          annee_ref  = tab_cntrl(5)
+      endif
+
+
       im         = tab_cntrl(1)
       jm         = tab_cntrl(2)
       lllm       = tab_cntrl(3)
       day_ref    = tab_cntrl(4)
-      annee_ref  = tab_cntrl(5)
-      rad        = tab_cntrl(6)
-      omeg       = tab_cntrl(7)
-      g          = tab_cntrl(8)
-      cpp        = tab_cntrl(9)
-      kappa      = tab_cntrl(10)
-      daysec     = tab_cntrl(11)
-      dtvr       = tab_cntrl(12)
-      etot0      = tab_cntrl(13)
-      ptot0      = tab_cntrl(14)
-      ztot0      = tab_cntrl(15)
-      stot0      = tab_cntrl(16)
-      ang0       = tab_cntrl(17)
-      pa         = tab_cntrl(18)
-      preff      = tab_cntrl(19)
-c
-      clon       = tab_cntrl(20)
-      clat       = tab_cntrl(21)
-      grossismx  = tab_cntrl(22)
-      grossismy  = tab_cntrl(23)
-c
-      IF ( tab_cntrl(24).EQ.1. )  THEN
+      rad        = tab_cntrl(idecal+1)
+      omeg       = tab_cntrl(idecal+2)
+      g          = tab_cntrl(idecal+3)
+      cpp        = tab_cntrl(idecal+4)
+      kappa      = tab_cntrl(idecal+5)
+      daysec     = tab_cntrl(idecal+6)
+      dtvr       = tab_cntrl(idecal+7)
+      etot0      = tab_cntrl(idecal+8)
+      ptot0      = tab_cntrl(idecal+9)
+      ztot0      = tab_cntrl(idecal+10)
+      stot0      = tab_cntrl(idecal+11)
+      ang0       = tab_cntrl(idecal+12)
+      pa         = tab_cntrl(idecal+13)
+      preff      = tab_cntrl(idecal+14)
+c
+      clon       = tab_cntrl(idecal+15)
+      clat       = tab_cntrl(idecal+16)
+      grossismx  = tab_cntrl(idecal+17)
+      grossismy  = tab_cntrl(idecal+18)
+c
+      IF ( tab_cntrl(idecal+19).EQ.1. )  THEN
         fxyhypb  = . TRUE .
 c        dzoomx   = tab_cntrl(25)
@@ -118,5 +133,5 @@
         fxyhypb = . FALSE .
         ysinus  = . FALSE .
-        IF( tab_cntrl(27).EQ.1. ) ysinus = . TRUE. 
+        IF( tab_cntrl(idecal+22).EQ.1. ) ysinus = . TRUE. 
       ENDIF
 
@@ -266,6 +281,11 @@
       ierr = NF_INQ_VARID (nid, "temps", nvarid)
       IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0_loc: Le champ <temps> est absent"
-         CALL abort
+         write(lunout,*)"dynetat0: Le champ <temps> est absent"
+         write(lunout,*)"dynetat0: J essaie <Time>"
+         ierr = NF_INQ_VARID (nid, "Time", nvarid)
+         IF (ierr .NE. NF_NOERR) THEN
+            write(lunout,*)"dynetat0: Le champ <Time> est absent"
+            CALL abort
+         ENDIF
       ENDIF
 #ifdef NC_DOUBLE
Index: LMDZ5/branches/testing/libf/dyn3dmem/dynredem_loc.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/dynredem_loc.F	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dmem/dynredem_loc.F	(revision 1707)
@@ -1,4 +1,4 @@
 !
-! $Id: dynredem_p.F 1299 2010-01-20 14:27:21Z fairhead $
+! $Id$
 !
 c
@@ -126,4 +126,6 @@
        tab_cntrl(30) =  REAL(iday_end)
        tab_cntrl(31) =  REAL(itau_dyn + itaufin)
+c start_time: start_time of simulation (not necessarily 0.)
+       tab_cntrl(32) = start_time
 c
 c    .........................................................
@@ -635,5 +637,5 @@
       CALL dynredem_write_u(nid,"ps",ps,1)
 
-      IF (config_inca == 'none') THEN
+      IF (type_trac /= 'inca') THEN
         DO iq=1,nqtot
           CALL dynredem_write_u(nid,tname(iq),q(:,:,iq),llm)
Index: LMDZ5/branches/testing/libf/dyn3dmem/dynredem_mod.F90
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/dynredem_mod.F90	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dmem/dynredem_mod.F90	(revision 1707)
@@ -1,7 +1,6 @@
+!
+! $Id$
+!
 MODULE dynredem_mod
-
-
-
-
 
 CONTAINS
@@ -37,6 +36,4 @@
    ENDIF
 !$OMP END MASTER
- 
-    ll=size(var,2)
 
 !$OMP MASTER
@@ -105,6 +102,4 @@
 !$OMP END MASTER
  
-    ll=size(var,2)
-
 !$OMP MASTER
     ALLOCATE(var_tmp(ijb_v:ije_v,ll))
@@ -172,6 +167,4 @@
 !$OMP END MASTER
  
-    ll=size(var,2)
-
 !$OMP MASTER
     ALLOCATE(var_tmp(ijb_u:ije_u,ll))
Index: LMDZ5/branches/testing/libf/dyn3dmem/ener.h
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/ener.h	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dmem/ener.h	(revision 1707)
@@ -1,13 +1,16 @@
 !
-! $Header$
+! $Id$
 !
-!-----------------------------------------------------------------------
+!  ATTENTION!!!!: ce fichier include est compatible format fixe/format libre
+!                 veillez à n'utiliser que des ! pour les commentaires
+!                 et à bien positionner les & des lignes de continuation 
+!                 (les placer en colonne 6 et en colonne 73)
+!
 ! INCLUDE 'ener.h'
 
-      COMMON/ener/ang0,etot0,ptot0,ztot0,stot0,                          &
-     &            ang,etot,ptot,ztot,stot,rmsdpdt ,                      &
+      COMMON/ener/ang0,etot0,ptot0,ztot0,stot0,                         &
+     &            ang,etot,ptot,ztot,stot,rmsdpdt ,                     &
      &            rmsv,gtot(llmm1)
-
-      REAL ang0,etot0,ptot0,ztot0,stot0,                                 &
+      REAL ang0,etot0,ptot0,ztot0,stot0,                                &
      &     ang,etot,ptot,ztot,stot,rmsdpdt,rmsv,gtot
 
Index: LMDZ5/branches/testing/libf/dyn3dmem/etat0_netcdf.F90
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/etat0_netcdf.F90	(revision 1669)
+++ 	(revision )
@@ -1,526 +1,0 @@
-!
-! $Id: etat0_netcdf.F90 1425 2010-09-02 13:45:23Z lguez $
-!
-!-------------------------------------------------------------------------------
-!
-SUBROUTINE etat0_netcdf(ib, masque, letat0)
-!
-!-------------------------------------------------------------------------------
-! Purpose: Creates initial states
-!-------------------------------------------------------------------------------
-! Note: This routine is designed to work for Earth
-!-------------------------------------------------------------------------------
-  USE control_mod
-#ifdef CPP_EARTH
-  USE startvar
-  USE ioipsl
-  USE dimphy
-  USE infotrac
-  USE fonte_neige_mod
-  USE pbl_surface_mod
-  USE phys_state_var_mod
-  USE filtreg_mod
-  USE regr_lat_time_climoz_m, ONLY: regr_lat_time_climoz
-  USE conf_phys_m,            ONLY: conf_phys
-! For parameterization of ozone chemistry:
-  use regr_lat_time_coefoz_m, only: regr_lat_time_coefoz
-  use press_coefoz_m, only: press_coefoz
-  use regr_pr_o3_m, only: regr_pr_o3
-  USE netcdf, ONLY : NF90_OPEN, NF90_NOWRITE, NF90_CLOSE, NF90_NOERR
-#endif
-  IMPLICIT NONE
-!-------------------------------------------------------------------------------
-! Arguments:
-#include "dimensions.h"
-#include "paramet.h"
-#include "iniprint.h"
-  LOGICAL,                    INTENT(IN)    :: ib     ! barycentric interpolat.
-  REAL, DIMENSION(iip1,jjp1), INTENT(INOUT) :: masque ! land mask
-  LOGICAL,                    INTENT(IN)    :: letat0 ! F: masque only required
-#ifndef CPP_EARTH
-  WRITE(lunout,*)'limit_netcdf: Earth-specific routine, needs Earth physics'
-#else
-!-------------------------------------------------------------------------------
-! Local variables:
-#include "comgeom2.h"
-#include "comvert.h"
-#include "comconst.h"
-#include "indicesol.h"
-#include "dimsoil.h"
-#include "temps.h"
-  REAL,    DIMENSION(klon)                 :: tsol, qsol
-  REAL,    DIMENSION(klon)                 :: sn, rugmer, run_off_lic_0
-  REAL,    DIMENSION(iip1,jjp1)            :: orog, rugo, psol, phis
-  REAL,    DIMENSION(iip1,jjp1,llm+1)      :: p3d
-  REAL,    DIMENSION(iip1,jjp1,llm)        :: uvent, t3d, tpot, qsat, qd
-  REAL,    DIMENSION(iip1,jjm ,llm)        :: vvent
-  REAL,    DIMENSION(:,:,:,:), ALLOCATABLE :: q3d
-  REAL,    DIMENSION(klon,nbsrf)           :: qsolsrf, snsrf, evap
-  REAL,    DIMENSION(klon,nbsrf)           :: frugs, agesno
-  REAL,    DIMENSION(klon,nsoilmx,nbsrf)   :: tsoil
-
-!--- Local variables for sea-ice reading:
-  INTEGER                                  :: iml_lic, jml_lic, llm_tmp
-  INTEGER                                  :: ttm_tmp, iret, fid
-  INTEGER, DIMENSION(1)                    :: itaul
-  REAL,    DIMENSION(1)                    :: lev
-  REAL                                     :: date
-  REAL,    DIMENSION(:,:),   ALLOCATABLE   ::  lon_lic,  lat_lic, fraclic
-  REAL,    DIMENSION(:),     ALLOCATABLE   :: dlon_lic, dlat_lic
-  REAL,    DIMENSION(iip1,jjp1)            :: flic_tmp
-
-!--- Misc
-  CHARACTER(LEN=80)                        :: x, fmt
-  INTEGER                                  :: i, j, l, ji
-  REAL,    DIMENSION(iip1,jjp1,llm)        :: alpha, beta, pk, pls, y
-  REAL,    DIMENSION(ip1jmp1)              :: pks
-
-#include "comdissnew.h"
-#include "serre.h"
-#include "clesphys.h"
-
-  REAL,    DIMENSION(iip1,jjp1,llm)        :: masse
-  INTEGER :: itau, iday
-  REAL    :: xpn, xps, time, phystep
-  REAL,    DIMENSION(iim)                  :: xppn, xpps
-  REAL,    DIMENSION(ip1jmp1,llm)          :: pbaru, phi, w
-  REAL,    DIMENSION(ip1jm  ,llm)          :: pbarv
-  REAL,    DIMENSION(klon)                 :: fder
-
-!--- Local variables for ocean mask reading:
-  INTEGER :: nid_o2a, iml_omask, jml_omask
-  LOGICAL :: couple=.FALSE.
-  REAL,    DIMENSION(:,:), ALLOCATABLE ::  lon_omask, lat_omask, ocemask, ocetmp
-  REAL,    DIMENSION(:),   ALLOCATABLE :: dlon_omask,dlat_omask
-  REAL,    DIMENSION(klon)             :: ocemask_fi
-  INTEGER, DIMENSION(klon-2)           :: isst
-  REAL,    DIMENSION(iim,jjp1)         :: zx_tmp_2d
-  REAL    :: dummy
-  LOGICAL :: ok_newmicro, ok_journe, ok_mensuel, ok_instan, ok_hf
-  LOGICAL :: ok_LES, ok_ade, ok_aie, aerosol_couple, new_aod
-  INTEGER :: iflag_radia, flag_aerosol
-  REAL    :: bl95_b0, bl95_b1, fact_cldcon, facttemps, ratqsbas, ratqshaut
-  REAL    :: tau_ratqs
-  INTEGER :: iflag_cldcon, iflag_ratqs, iflag_coupl, iflag_clos, iflag_wake
-  INTEGER :: iflag_thermals, nsplit_thermals
-  INTEGER :: iflag_thermals_ed, iflag_thermals_optflux
-  REAL    :: tau_thermals, solarlong0,  seuil_inversion
-  INTEGER :: read_climoz ! read ozone climatology
-!  Allowed values are 0, 1 and 2
-!     0: do not read an ozone climatology
-!     1: read a single ozone climatology that will be used day and night
-!     2: read two ozone climatologies, the average day and night
-!     climatology and the daylight climatology
-!-------------------------------------------------------------------------------
-  REAL    :: alp_offset
-  logical found
-
-!--- Constants
-  pi     = 4. * ATAN(1.)
-  rad    = 6371229.
-  daysec = 86400.
-  omeg   = 2.*pi/daysec
-  g      = 9.8
-  kappa  = 0.2857143
-  cpp    = 1004.70885
-  preff  = 101325.
-  pa     = 50000.
-  jmp1   = jjm + 1
-
-!--- CONSTRUCT A GRID
-  CALL conf_phys(  ok_journe, ok_mensuel, ok_instan, ok_hf, ok_LES,     &
-                   solarlong0,seuil_inversion,                          &
-                   fact_cldcon, facttemps,ok_newmicro,iflag_radia,      &
-                   iflag_cldcon,                                        &
-                   iflag_ratqs,ratqsbas,ratqshaut,tau_ratqs,            &
-                   ok_ade, ok_aie, aerosol_couple,                      &
-                   flag_aerosol, new_aod,                               &
-                   bl95_b0, bl95_b1,                                    &
-                   iflag_thermals,nsplit_thermals,tau_thermals,         &
-                   iflag_thermals_ed,iflag_thermals_optflux,            &
-                   iflag_coupl,iflag_clos,iflag_wake, read_climoz,      &
-                   alp_offset)
-
-! co2_ppm0 : initial value of atmospheric CO2 from .def file (co2_ppm value)
-  co2_ppm0 = co2_ppm
-
-  dtvr   = daysec/FLOAT(day_step)
-  WRITE(lunout,*)'dtvr',dtvr
-
-  CALL iniconst()
-  CALL inigeom()
-
-!--- Initializations for tracers
-  CALL infotrac_init
-  ALLOCATE(q3d(iip1,jjp1,llm,nqtot))
-
-  CALL inifilr()
-  CALL phys_state_var_init(read_climoz)
-
-  rlat(1) = ASIN(1.0)
-  DO j=2,jjm; rlat((j-2)*iim+2:(j-1)*iim+1)=rlatu(j);     END DO
-  rlat(klon) = - ASIN(1.0)
-  rlat(:)=rlat(:)*(180.0/pi)
-
-  rlon(1) = 0.0
-  DO j=2,jjm; rlon((j-2)*iim+2:(j-1)*iim+1)=rlonv(1:iim); END DO
-  rlon(klon) = 0.0
-  rlon(:)=rlon(:)*(180.0/pi)
-
-! For a coupled simulation, the ocean mask from ocean model is used to compute
-! the weights an to insure ocean fractions are the same for atmosphere and ocean
-! Otherwise, mask is created using Relief file.
-
-  WRITE(lunout,*)'Essai de lecture masque ocean'
-  iret = NF90_OPEN("o2a.nc", NF90_NOWRITE, nid_o2a)
-  IF(iret/=NF90_NOERR) THEN
-    WRITE(lunout,*)'ATTENTION!! pas de fichier o2a.nc trouve'
-    WRITE(lunout,*)'Run force'
-    x='masque'
-    masque(:,:)=0.0
-    CALL startget_phys2d(x, iip1, jjp1, rlonv, rlatu, masque, 0.0, jjm, &
-   &              rlonu, rlatv, ib)
-    WRITE(lunout,*)'MASQUE construit : Masque'
-    WRITE(lunout,'(97I1)') nINT(masque)
-    CALL gr_dyn_fi(1, iip1, jjp1, klon, masque, zmasq)
-    WHERE(   zmasq(:)<EPSFRA) zmasq(:)=0.
-    WHERE(1.-zmasq(:)<EPSFRA) zmasq(:)=1.
-  ELSE
-    WRITE(lunout,*)'ATTENTION!! fichier o2a.nc trouve'
-    WRITE(lunout,*)'Run couple'
-    couple=.true.
-    iret=NF90_CLOSE(nid_o2a)
-    CALL flininfo("o2a.nc", iml_omask, jml_omask, llm_tmp, ttm_tmp, nid_o2a)
-    IF(iml_omask/=iim .OR.jml_omask/=jjp1) THEN
-      WRITE(lunout,*)'Dimensions non compatibles pour masque ocean'
-      WRITE(lunout,*)'iim = ',iim,' iml_omask = ',iml_omask
-      WRITE(lunout,*)'jjp1 = ',jjp1,' jml_omask = ',jml_omask
-      CALL abort_gcm('etat0_netcdf','Dimensions non compatibles pour masque oc&
-     &ean',1)
-    END IF
-    ALLOCATE(   ocemask(iml_omask,jml_omask),   ocetmp(iml_omask,jml_omask))
-    ALLOCATE( lon_omask(iml_omask,jml_omask),lat_omask(iml_omask,jml_omask))
-    ALLOCATE(dlon_omask(iml_omask),         dlat_omask(jml_omask))
-    CALL flinopen("o2a.nc", .FALSE., iml_omask, jml_omask, llm_tmp, lon_omask,&
-   &              lat_omask, lev, ttm_tmp, itaul, date, dt, fid)
-    CALL flinget(fid, 'OceMask', iml_omask, jml_omask, llm_tmp, ttm_tmp, &
-   &              1, 1, ocetmp)
-    CALL flinclo(fid)
-    dlon_omask(1:iml_omask) = lon_omask(1:iml_omask,1)
-    dlat_omask(1:jml_omask) = lat_omask(1,1:jml_omask)
-    ocemask = ocetmp
-    IF(dlat_omask(1)<dlat_omask(jml_omask)) THEN
-      DO j=1,jml_omask
-        ocemask(:,j) = ocetmp(:,jml_omask-j+1)
-      END DO
-    END IF
-!
-! Ocean mask to physical grid
-!*******************************************************************************
-    WRITE(lunout,*)'ocemask '
-    WRITE(fmt,"(i4,'i1)')")iml_omask ; fmt='('//ADJUSTL(fmt)
-    WRITE(lunout,fmt)int(ocemask)
-    ocemask_fi(1)=ocemask(1,1)
-    DO j=2,jjm; ocemask_fi((j-2)*iim+2:(j-1)*iim+1)=ocemask(1:iim,j); END DO
-    ocemask_fi(klon)=ocemask(1,jjp1)
-    zmasq=1.-ocemask_fi
-  END IF
-
-  CALL gr_fi_dyn(1,klon,iip1,jjp1,zmasq,masque)
-
-  ! The startget calls need to be replaced by a call to restget to get the
-  ! values in the restart file
-  x = 'relief'; orog(:,:) = 0.0
-  CALL startget_phys2d(x,iip1,jjp1,rlonv,rlatu, orog, 0.0,jjm,rlonu,rlatv,ib,&
- &               masque)
-
-  x = 'rugosite'; rugo(:,:) = 0.0
-  CALL startget_phys2d(x,iip1,jjp1,rlonv,rlatu, rugo, 0.0,jjm, rlonu,rlatv,ib)
-!  WRITE(lunout,'(49I1)') INT(orog(:,:)*10)
-!  WRITE(lunout,'(49I1)') INT(rugo(:,:)*10)
-
-! Sub-surfaces initialization
-!*******************************************************************************
-  pctsrf=0.
-  x = 'psol'; psol(:,:) = 0.0
-  CALL startget_phys2d(x,iip1,jjp1,rlonv,rlatu,psol,0.0,jjm,rlonu,rlatv,ib)
-!  WRITE(lunout,*) 'PSOL :', psol(10,20)
-!  WRITE(lunout,*) ap(:), bp(:)
-
-! Mid-levels pressure computation
-!*******************************************************************************
-  CALL pression(ip1jmp1, ap, bp, psol, p3d)
-  CALL exner_hyb(ip1jmp1, psol, p3d, alpha, beta, pks, pk, y)
-  pls(:,:,:)=preff*(pk(:,:,:)/cpp)**(1./kappa)
-!  WRITE(lunout,*) 'P3D :', p3d(10,20,:)
-!  WRITE(lunout,*) 'PK:',    pk(10,20,:)
-!  WRITE(lunout,*) 'PLS :', pls(10,20,:)
-
-  x = 'surfgeo'; phis(:,:) = 0.0
-  CALL startget_phys2d(x,iip1,jjp1,rlonv,rlatu,phis, 0.0,jjm, rlonu,rlatv,ib)
-
-  x = 'u';    uvent(:,:,:) = 0.0
-  CALL startget_dyn(x,rlonu,rlatu,pls,y,uvent,0.0,  &
- &                  rlonv,rlatv,ib)
-
-  x = 'v';    vvent(:,:,:) = 0.0
-  CALL startget_dyn(x, rlonv,rlatv,pls(:, :jjm, :),y(:, :jjm, :),vvent,0.0, &
- &                  rlonu,rlatu(:jjm),ib)
-
-  x = 't';    t3d(:,:,:) = 0.0
-  CALL startget_dyn(x,rlonv,rlatu,pls,y,t3d,0.0,    &
- &                  rlonu,rlatv,ib)
-
-  x = 'tpot'; tpot(:,:,:) = 0.0
-  CALL startget_dyn(x,rlonv,rlatu,pls,pk,tpot,0.0,  &
- &                  rlonu,rlatv,ib)
-
-  WRITE(lunout,*) 'T3D min,max:',minval(t3d(:,:,:)),maxval(t3d(:,:,:))
-  WRITE(lunout,*) 'PLS min,max:',minval(pls(:,:,:)),maxval(pls(:,:,:))
-
-! Humidity at saturation computation
-!*******************************************************************************
-  WRITE(lunout,*) 'avant q_sat'
-  CALL q_sat(llm*jjp1*iip1, t3d, pls, qsat)
-  WRITE(lunout,*) 'apres q_sat'
-  WRITE(lunout,*) 'QSAT min,max:',minval(qsat(:,:,:)),maxval(qsat(:,:,:))
-!  WRITE(lunout,*) 'QSAT :',qsat(10,20,:)
-
-  x = 'q';    qd (:,:,:) = 0.0
-  CALL startget_dyn(x,rlonv,rlatu,pls,qsat,qd,0.0, rlonu,rlatv,ib)
-  q3d(:,:,:,:) = 0.0 ; q3d(:,:,:,1) = qd(:,:,:)
-
-! Parameterization of ozone chemistry:
-! Look for ozone tracer:
-  i = 1
-  DO
-    found = tname(i)=="O3" .OR. tname(i)=="o3"
-    if (found .or. i == nqtot) exit
-    i = i + 1
-  end do
-  if (found) then
-    call regr_lat_time_coefoz
-    call press_coefoz
-    call regr_pr_o3(p3d, q3d(:, :, :, i))
-!   Convert from mole fraction to mass fraction:
-    q3d(:, :, :, i) = q3d(:, :, :, i)  * 48. / 29.
-  end if
-
-!--- OZONE CLIMATOLOGY
-  IF(read_climoz>=1) CALL regr_lat_time_climoz(read_climoz)
-
-  x = 'tsol'; tsol(:) = 0.0
-  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,tsol,0.0,jjm,rlonu,rlatv,ib)
-
-  x = 'qsol';  qsol(:) = 0.0
-  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,qsol,0.0,jjm,rlonu,rlatv,ib)
-
-  x = 'snow';  sn(:) = 0.0
-  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,sn,0.0,jjm,rlonu,rlatv,ib)
-
-  x = 'rads';  radsol(:) = 0.0
-  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,radsol,0.0,jjm,rlonu,rlatv,ib)
-
-  x = 'rugmer'; rugmer(:) = 0.0
-  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,rugmer,0.0,jjm,rlonu,rlatv,ib)
-
-  x = 'zmea';  zmea(:) = 0.0
-  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,zmea,0.0,jjm,rlonu,rlatv,ib)
-
-  x = 'zstd';  zstd(:) = 0.0
-  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,zstd,0.0,jjm,rlonu,rlatv,ib)
-
-  x = 'zsig';  zsig(:) = 0.0
-  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,zsig,0.0,jjm,rlonu,rlatv,ib)
-
-  x = 'zgam';  zgam(:) = 0.0
-  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,zgam,0.0,jjm,rlonu,rlatv,ib)
-
-  x = 'zthe';  zthe(:) = 0.0
-  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,zthe,0.0,jjm,rlonu,rlatv,ib)
-
-  x = 'zpic';  zpic(:) = 0.0
-  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,zpic,0.0,jjm,rlonu,rlatv,ib)
-
-  x = 'zval';  zval(:) = 0.0
-  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,zval,0.0,jjm,rlonu,rlatv,ib)
-
-!  WRITE(lunout,'(48I3)') 'TSOL :', INT(tsol(2:klon)-273)
-
-! Soil ice file reading for soil fraction and soil ice fraction
-!*******************************************************************************
-  CALL flininfo("landiceref.nc", iml_lic, jml_lic, llm_tmp, ttm_tmp, fid)
-  ALLOCATE( lat_lic(iml_lic,jml_lic),lon_lic(iml_lic, jml_lic))
-  ALLOCATE(dlat_lic(jml_lic),       dlon_lic(iml_lic))
-  ALLOCATE( fraclic(iml_lic,jml_lic))
-  CALL flinopen("landiceref.nc", .FALSE., iml_lic, jml_lic, llm_tmp,  &
- &               lon_lic, lat_lic, lev, ttm_tmp, itaul, date, dt, fid)
-  CALL flinget(fid, 'landice', iml_lic, jml_lic, llm_tmp, ttm_tmp, 1,1, fraclic)
-  CALL flinclo(fid)
-
-! Interpolation on model T-grid
-!*******************************************************************************
-  WRITE(lunout,*)'dimensions de landice iml_lic, jml_lic : ',iml_lic,jml_lic
-! conversion if coordinates are in degrees
-  IF(MAXVAL(lon_lic)>pi) lon_lic=lon_lic*pi/180.
-  IF(MAXVAL(lat_lic)>pi) lat_lic=lat_lic*pi/180.
-  dlon_lic(:)=lon_lic(:,1)
-  dlat_lic(:)=lat_lic(1,:)
-  CALL grille_m( iml_lic, jml_lic, dlon_lic, dlat_lic, fraclic, iim,jjp1,   &
- &               rlonv, rlatu, flic_tmp(1:iim,:) )
-  flic_tmp(iip1,:)=flic_tmp(1,:)
-
-!--- To the physical grid
-  CALL gr_dyn_fi(1, iip1, jjp1, klon, flic_tmp, pctsrf(:,is_lic))
-
-!--- Adequation with soil/sea mask
-  WHERE(pctsrf(:,is_lic)<EPSFRA) pctsrf(:,is_lic)=0. 
-  WHERE(zmasq(:)<EPSFRA)         pctsrf(:,is_lic)=0.
-  pctsrf(:,is_ter)=zmasq(:)
-  DO ji=1,klon
-    IF(zmasq(ji)>EPSFRA) THEN 
-      IF(pctsrf(ji,is_lic)>=zmasq(ji)) THEN
-        pctsrf(ji,is_lic)=zmasq(ji)
-        pctsrf(ji,is_ter)=0.
-      ELSE
-        pctsrf(ji,is_ter)=zmasq(ji)-pctsrf(ji,is_lic)
-        IF(pctsrf(ji,is_ter)<EPSFRA) THEN
-          pctsrf(ji,is_ter)=0.
-          pctsrf(ji,is_lic)=zmasq(ji)
-        END IF 
-      END IF 
-    END IF 
-  END DO 
-
-! sub-surface ocean and sea ice (sea ice set to zero for start)
-!*******************************************************************************
-  pctsrf(:,is_oce)=(1.-zmasq(:))
-  WHERE(pctsrf(:,is_oce)<EPSFRA) pctsrf(:,is_oce)=0.
-  IF(couple) pctsrf(:,is_oce)=ocemask_fi(:)
-  isst=0
-  WHERE(pctsrf(2:klon-1,is_oce)>0.) isst=1
-
-! It is checked that the sub-surfaces sum is equal to 1
-!*******************************************************************************
-  ji=COUNT((ABS(SUM(pctsrf(:,:),dim=2))-1.0)>EPSFRA)
-  IF(ji/=0) WRITE(lunout,*) 'pb repartition sous maille pour ',ji,' points'
-  CALL gr_fi_ecrit(1, klon, iim, jjp1, zmasq, zx_tmp_2d)
-!  WRITE(fmt,"(i3,')')")iim; fmt='(i'//ADJUSTL(fmt)
-!  WRITE(lunout,*)'zmasq = '
-!  WRITE(lunout,TRIM(fmt))NINT(zx_tmp_2d)
-  CALL gr_fi_dyn(1, klon, iip1, jjp1, zmasq, masque)
-  WRITE(fmt,"(i4,'i1)')")iip1 ; fmt='('//ADJUSTL(fmt)
-  WRITE(lunout,*) 'MASQUE construit : Masque'
-  WRITE(lunout,TRIM(fmt))NINT(masque(:,:))
-
-! Intermediate computation
-!*******************************************************************************
-  CALL massdair(p3d,masse)
-  WRITE(lunout,*)' ALPHAX ',alphax
-  DO l=1,llm
-    xppn(:)=aire(1:iim,1   )*masse(1:iim,1   ,l)
-    xpps(:)=aire(1:iim,jjp1)*masse(1:iim,jjp1,l)
-    xpn=SUM(xppn)/apoln
-    xps=SUM(xpps)/apols
-    masse(:,1   ,l)=xpn
-    masse(:,jjp1,l)=xps
-  END DO
-  q3d(iip1,:,:,:)=q3d(1,:,:,:)
-  phis(iip1,:) = phis(1,:)
-
-  IF(.NOT.letat0) RETURN
-
-! Writing
-!*******************************************************************************
-  CALL inidissip(lstardis,nitergdiv,nitergrot,niterh,tetagdiv,tetagrot,tetatemp)
-  WRITE(lunout,*)'sortie inidissip'
-  itau=0
-  itau_dyn=0
-  itau_phy=0
-  iday=dayref+itau/day_step
-  time=FLOAT(itau-(iday-dayref)*day_step)/day_step
-  IF(time>1.) THEN
-   time=time-1
-   iday=iday+1
-  END IF
-  day_ref=dayref
-  annee_ref=anneeref
-
-  CALL geopot( ip1jmp1, tpot, pk, pks, phis, phi )
-  WRITE(lunout,*)'sortie geopot'
-
-  CALL caldyn0( itau, uvent, vvent, tpot, psol, masse, pk, phis,               &
-                phi,  w, pbaru, pbarv, time+iday-dayref)
-  WRITE(lunout,*)'sortie caldyn0'     
-  CALL dynredem0( "start.nc", dayref, phis)
-  WRITE(lunout,*)'sortie dynredem0'
-  CALL dynredem1( "start.nc", 0.0, vvent, uvent, tpot, q3d, masse, psol)
-  WRITE(lunout,*)'sortie dynredem1' 
-
-! Physical initial state writting
-!*******************************************************************************
-  WRITE(lunout,*)'phystep ',dtvr,iphysiq,nbapp_rad
-  phystep   = dtvr * FLOAT(iphysiq)
-  radpas    = NINT (86400./phystep/ FLOAT(nbapp_rad) )
-  WRITE(lunout,*)'phystep =', phystep, radpas
-
-! Init: tsol, qsol, sn, evap, tsoil, rain_fall, snow_fall, solsw, sollw, frugs
-!*******************************************************************************
-  DO i=1,nbsrf; ftsol(:,i) = tsol; END DO
-  DO i=1,nbsrf; snsrf(:,i) = sn;   END DO
-  falb1(:,is_ter) = 0.08; falb1(:,is_lic) = 0.6
-  falb1(:,is_oce) = 0.5;  falb1(:,is_sic) = 0.6
-  falb2 = falb1
-  evap(:,:) = 0.
-  DO i=1,nbsrf; qsolsrf(:,i)=150.; END DO
-  DO i=1,nbsrf; DO j=1,nsoilmx; tsoil(:,j,i) = tsol; END DO; END DO
-  rain_fall = 0.; snow_fall = 0.
-  solsw = 165.;   sollw = -53.
-  t_ancien = 273.15
-  q_ancien = 0.
-  agesno = 0.
-  frugs(:,is_oce) = rugmer(:)
-  frugs(:,is_ter) = MAX(1.0e-05,zstd(:)*zsig(:)/2.0)
-  frugs(:,is_lic) = MAX(1.0e-05,zstd(:)*zsig(:)/2.0)
-  frugs(:,is_sic) = 0.001
-  fder = 0.0
-  clwcon = 0.0
-  rnebcon = 0.0
-  ratqs = 0.0
-  run_off_lic_0 = 0.0 
-  rugoro = 0.0
-
-! Before phyredem calling, surface modules and values to be saved in startphy.nc
-! are initialized
-!*******************************************************************************
-  dummy = 1.0
-  pbl_tke(:,:,:) = 1.e-8 
-  zmax0(:) = 40.
-  f0(:) = 1.e-5
-  ema_work1(:,:) = 0.
-  ema_work2(:,:) = 0.
-  wake_deltat(:,:) = 0.
-  wake_deltaq(:,:) = 0.
-  wake_s(:) = 0.
-  wake_cstar(:) = 0.
-  wake_fip(:) = 0.
-  wake_pe = 0.
-  fm_therm = 0.
-  entr_therm = 0.
-  detr_therm = 0.
-
-  CALL fonte_neige_init(run_off_lic_0)
-  CALL pbl_surface_init( qsol, fder, snsrf, qsolsrf, evap, frugs, agesno, tsoil )
-  CALL phyredem( "startphy.nc" )
-
-!  WRITE(lunout,*)'CCCCCCCCCCCCCCCCCC REACTIVER SORTIE VISU DANS ETAT0'
-!  WRITE(lunout,*)'entree histclo'
-  CALL histclo()
-
-#endif 
-!#endif of #ifdef CPP_EARTH
-  RETURN
-
-END SUBROUTINE etat0_netcdf
-!
-!-------------------------------------------------------------------------------
Index: LMDZ5/branches/testing/libf/dyn3dmem/exner_hyb.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/exner_hyb.F	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dmem/exner_hyb.F	(revision 1707)
@@ -1,4 +1,4 @@
 !
-! $Id: exner_hyb.F 1403 2010-07-01 09:02:53Z fairhead $
+! $Id$
 !
       SUBROUTINE  exner_hyb ( ngrid, ps, p,alpha,beta, pks, pk, pkf )
@@ -51,17 +51,25 @@
       REAL SSUM
 c
+      logical,save :: firstcall=.true.
+      character(len=*),parameter :: modname="exner_hyb"
+      
+      ! Sanity check
+      if (firstcall) then
+        ! sanity checks for Shallow Water case (1 vertical layer)
+        if (llm.eq.1) then
+          if (kappa.ne.1) then
+            call abort_gcm(modname,
+     &      "kappa!=1 , but running in Shallow Water mode!!",42)
+          endif
+          if (cpp.ne.r) then
+            call abort_gcm(modname,
+     &      "cpp!=r , but running in Shallow Water mode!!",42)
+          endif
+        endif ! of if (llm.eq.1)
+
+        firstcall=.false.
+      endif ! of if (firstcall)
 
       if (llm.eq.1) then
-        ! Specific behaviour for Shallow Water (1 vertical layer) case
-      
-        ! Sanity checks
-        if (kappa.ne.1) then
-          call abort_gcm("exner_hyb",
-     &    "kappa!=1 , but running in Shallow Water mode!!",42)
-        endif
-        if (cpp.ne.r) then
-        call abort_gcm("exner_hyb",
-     &    "cpp!=r , but running in Shallow Water mode!!",42)
-        endif
         
         ! Compute pks(:),pk(:),pkf(:)
@@ -77,6 +85,8 @@
         ! our work is done, exit routine
         return
+
       endif ! of if (llm.eq.1)
 
+!!!! General case:
      
       unpl2k    = 1.+ 2.* kappa
Index: LMDZ5/branches/testing/libf/dyn3dmem/exner_hyb_loc.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/exner_hyb_loc.F	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dmem/exner_hyb_loc.F	(revision 1707)
@@ -57,19 +57,31 @@
       EXTERNAL SSUM
       INTEGER ije,ijb,jje,jjb
+      logical,save :: firstcall=.true.
+!$OMP THREADPRIVATE(firstcall) 
+      character(len=*),parameter :: modname="exner_hyb_loc"
 c
 c$OMP BARRIER           
 
+      ! Sanity check
+      if (firstcall) then
+        ! sanity checks for Shallow Water case (1 vertical layer)
+        if (llm.eq.1) then
+          if (kappa.ne.1) then
+            call abort_gcm(modname,
+     &      "kappa!=1 , but running in Shallow Water mode!!",42)
+          endif
+          if (cpp.ne.r) then
+            call abort_gcm(modname,
+     &      "cpp!=r , but running in Shallow Water mode!!",42)
+          endif
+        endif ! of if (llm.eq.1)
+
+        firstcall=.false.
+      endif ! of if (firstcall)
+
+c$OMP BARRIER
+
+! Specific behaviour for Shallow Water (1 vertical layer) case
       if (llm.eq.1) then
-        ! Specific behaviour for Shallow Water (1 vertical layer) case
-      
-        ! Sanity checks
-        if (kappa.ne.1) then
-          call abort_gcm("exner_hyb",
-     &    "kappa!=1 , but running in Shallow Water mode!!",42)
-        endif
-        if (cpp.ne.r) then
-        call abort_gcm("exner_hyb",
-     &    "cpp!=r , but running in Shallow Water mode!!",42)
-        endif
         
         ! Compute pks(:),pk(:),pkf(:)
@@ -111,5 +123,5 @@
       endif
 !$OMP END MASTER
-
+!$OMP BARRIER
         jjb=jj_begin
         jje=jj_end
Index: LMDZ5/branches/testing/libf/dyn3dmem/exner_milieu.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/exner_milieu.F	(revision 1707)
+++ LMDZ5/branches/testing/libf/dyn3dmem/exner_milieu.F	(revision 1707)
@@ -0,0 +1,144 @@
+!
+! $Id$
+!
+      SUBROUTINE  exner_milieu ( ngrid, ps, p,beta, pks, pk, pkf )
+c
+c     Auteurs :  F. Forget , Y. Wanherdrick
+c P.Le Van  , Fr. Hourdin  .
+c    ..........
+c
+c    ....  ngrid, ps,p             sont des argum.d'entree  au sous-prog ...
+c    .... beta, pks,pk,pkf   sont des argum.de sortie au sous-prog ...
+c
+c   ************************************************************************
+c    Calcule la fonction d'Exner pk = Cp * (p/preff) ** kappa , aux milieux des 
+c    couches .   Pk(l) sera calcule aux milieux  des couches l ,entre les
+c    pressions p(l) et p(l+1) ,definis aux interfaces des llm couches .
+c   ************************************************************************
+c    .. N.B : Au sommet de l'atmosphere,  p(llm+1) = 0. , et ps et pks sont
+c    la pression et la fonction d'Exner  au  sol  .
+c
+c     WARNING : CECI est une version speciale de exner_hyb originale
+c               Utilise dans la version martienne pour pouvoir 
+c               tourner avec des coordonnees verticales complexe
+c              => Il ne verifie PAS la condition la proportionalite en 
+c              energie totale/ interne / potentielle (F.Forget 2001)
+c    ( voir note de Fr.Hourdin )  ,
+c
+      IMPLICIT NONE
+c
+#include "dimensions.h"
+#include "paramet.h"
+#include "comconst.h"
+#include "comgeom.h"
+#include "comvert.h"
+#include "serre.h"
+
+      INTEGER  ngrid
+      REAL p(ngrid,llmp1),pk(ngrid,llm),pkf(ngrid,llm)
+      REAL ps(ngrid),pks(ngrid), beta(ngrid,llm)
+
+c    .... variables locales   ...
+
+      INTEGER l, ij
+      REAL dum1
+
+      REAL ppn(iim),pps(iim)
+      REAL xpn, xps
+      REAL SSUM
+      EXTERNAL SSUM
+      logical,save :: firstcall=.true.
+      character(len=*),parameter :: modname="exner_milieu"
+
+      ! Sanity check
+      if (firstcall) then
+        ! sanity checks for Shallow Water case (1 vertical layer)
+        if (llm.eq.1) then
+          if (kappa.ne.1) then
+            call abort_gcm(modname,
+     &      "kappa!=1 , but running in Shallow Water mode!!",42)
+          endif
+          if (cpp.ne.r) then
+            call abort_gcm(modname,
+     &      "cpp!=r , but running in Shallow Water mode!!",42)
+          endif
+        endif ! of if (llm.eq.1)
+
+        firstcall=.false.
+      endif ! of if (firstcall)
+
+!!!! Specific behaviour for Shallow Water (1 vertical layer) case:
+      if (llm.eq.1) then
+      
+        ! Compute pks(:),pk(:),pkf(:)
+        
+        DO   ij  = 1, ngrid
+          pks(ij) = (cpp/preff) * ps(ij) 
+          pk(ij,1) = .5*pks(ij)
+        ENDDO
+        
+        CALL SCOPY   ( ngrid * llm, pk, 1, pkf, 1 )
+        CALL filtreg ( pkf, jmp1, llm, 2, 1, .TRUE., 1 ) 
+        
+        ! our work is done, exit routine
+        return
+
+      endif ! of if (llm.eq.1)
+
+!!!! General case:
+
+c     -------------
+c     Calcul de pks
+c     -------------
+   
+      DO   ij  = 1, ngrid
+        pks(ij) = cpp * ( ps(ij)/preff ) ** kappa
+      ENDDO
+
+      DO  ij   = 1, iim
+        ppn(ij) = aire(   ij   ) * pks(  ij     )
+        pps(ij) = aire(ij+ip1jm) * pks(ij+ip1jm )
+      ENDDO
+      xpn      = SSUM(iim,ppn,1) /apoln
+      xps      = SSUM(iim,pps,1) /apols
+
+      DO ij   = 1, iip1
+        pks(   ij     )  =  xpn
+        pks( ij+ip1jm )  =  xps
+      ENDDO
+c
+c
+c    .... Calcul de pk  pour la couche l 
+c    --------------------------------------------
+c
+      dum1 = cpp * (2*preff)**(-kappa) 
+      DO l = 1, llm-1
+        DO   ij   = 1, ngrid
+         pk(ij,l) = dum1 * (p(ij,l) + p(ij,l+1))**kappa
+        ENDDO
+      ENDDO
+
+c    .... Calcul de pk  pour la couche l = llm ..
+c    (on met la meme distance (en log pression)  entre Pk(llm)
+c    et Pk(llm -1) qu'entre Pk(llm-1) et Pk(llm-2)
+
+      DO   ij   = 1, ngrid
+         pk(ij,llm) = pk(ij,llm-1)**2 / pk(ij,llm-2)
+      ENDDO
+
+
+c    calcul de pkf
+c    -------------
+      CALL SCOPY   ( ngrid * llm, pk, 1, pkf, 1 )
+      CALL filtreg ( pkf, jmp1, llm, 2, 1, .TRUE., 1 )
+      
+c    EST-CE UTILE ?? : calcul de beta
+c    --------------------------------
+      DO l = 2, llm
+        DO   ij   = 1, ngrid
+          beta(ij,l) = pk(ij,l) / pk(ij,l-1)   
+        ENDDO
+      ENDDO
+
+      RETURN
+      END
Index: LMDZ5/branches/testing/libf/dyn3dmem/exner_milieu_loc.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/exner_milieu_loc.F	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dmem/exner_milieu_loc.F	(revision 1707)
@@ -1,4 +1,4 @@
 !
-! $Id $
+! $Id$
 !
       SUBROUTINE  exner_milieu_loc ( ngrid, ps, p,beta, pks, pk, pkf )
@@ -54,14 +54,8 @@
       logical,save :: firstcall=.true.
 !$OMP THREADPRIVATE(firstcall) 
-      character(len=*),parameter :: modname="exner_milieu_p"
+      character(len=*),parameter :: modname="exner_milieu_loc"
 
       ! Sanity check
       if (firstcall) then
-        ! check that vertical discretization is compatible
-        ! with this routine
-        if (disvert_type.ne.2) then
-          call abort_gcm(modname,
-     &     "this routine should only be called if disvert_type==2",42)
-        endif
         
         ! sanity checks for Shallow Water case (1 vertical layer)
@@ -123,5 +117,5 @@
       endif
 !$OMP END MASTER
-
+!$OMP BARRIER
         jjb=jj_begin
         jje=jj_end
@@ -171,4 +165,5 @@
       endif
 c$OMP END MASTER
+c$OMP BARRIER
 c
 c
Index: LMDZ5/branches/testing/libf/dyn3dmem/filtreg_p.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/filtreg_p.F	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dmem/filtreg_p.F	(revision 1707)
@@ -208,24 +208,39 @@
                IF( ifiltre.EQ.-2 )   THEN
                   DO j = jdfil,jffil
+#ifdef BLAS
                      CALL DGEMM("N", "N", iim, nbniv_loc, iim, 1.0, 
      &                    matrinvn(1,1,j), iim, 
      &                    champ_loc(1,j,1), iip1*nlat, 0.0,
      &                    champ_fft(1,j-jdfil+1,1), iip1*nlat)
+#else
+                     champ_fft(:iim,j-jdfil+1,:)
+     &                    =matmul(matrinvn(:,:,j),champ_loc(:iim,j,:))
+#endif
                   ENDDO
                   
                ELSE IF ( griscal )     THEN
                   DO j = jdfil,jffil
+#ifdef BLAS
                      CALL DGEMM("N", "N", iim, nbniv_loc, iim, 1.0, 
      &                    matriceun(1,1,j), iim, 
      &                    champ_loc(1,j,1), iip1*nlat, 0.0,
      &                    champ_fft(1,j-jdfil+1,1), iip1*nlat)
+#else
+                     champ_fft(:iim,j-jdfil+1,:)
+     &                    =matmul(matriceun(:,:,j),champ_loc(:iim,j,:))
+#endif
                   ENDDO
                   
                ELSE 
                   DO j = jdfil,jffil
+#ifdef BLAS
                      CALL DGEMM("N", "N", iim, nbniv_loc, iim, 1.0, 
      &                    matricevn(1,1,j), iim, 
      &                    champ_loc(1,j,1), iip1*nlat, 0.0, 
      &                    champ_fft(1,j-jdfil+1,1), iip1*nlat)
+#else
+                     champ_fft(:iim,j-jdfil+1,:)
+     &                    =matmul(matricevn(:,:,j),champ_loc(:iim,j,:))
+#endif
                   ENDDO
                   
@@ -236,8 +251,14 @@
                IF( ifiltre.EQ.-2 )   THEN
                   DO j = jdfil,jffil
+#ifdef BLAS
                      CALL DGEMM("N", "N", iim, nbniv_loc, iim, 1.0, 
      &                    matrinvs(1,1,j-jfiltsu+1), iim, 
      &                    champ_loc(1,j,1), iip1*nlat, 0.0, 
      &                    champ_fft(1,j-jdfil+1,1), iip1*nlat)
+#else
+                     champ_fft(:iim,j-jdfil+1,:)
+     &                    =matmul(matrinvs(:,:,j-jfiltsu+1),
+     &                            champ_loc(:iim,j,:))
+#endif
                   ENDDO
                   
@@ -245,8 +266,14 @@
                   
                   DO j = jdfil,jffil
+#ifdef BLAS
                      CALL DGEMM("N", "N", iim, nbniv_loc, iim, 1.0, 
      &                    matriceus(1,1,j-jfiltsu+1), iim, 
      &                    champ_loc(1,j,1), iip1*nlat, 0.0, 
      &                    champ_fft(1,j-jdfil+1,1), iip1*nlat)
+#else
+                     champ_fft(:iim,j-jdfil+1,:)
+     &                    =matmul(matriceus(:,:,j-jfiltsu+1),
+     &                            champ_loc(:iim,j,:))
+#endif
                   ENDDO
                   
@@ -254,8 +281,14 @@
                   
                   DO j = jdfil,jffil
+#ifdef BLAS
                      CALL DGEMM("N", "N", iim, nbniv_loc, iim, 1.0, 
      &                    matricevs(1,1,j-jfiltsv+1), iim, 
      &                    champ_loc(1,j,1), iip1*nlat, 0.0, 
      &                    champ_fft(1,j-jdfil+1,1), iip1*nlat)
+#else
+                     champ_fft(:iim,j-jdfil+1,:)
+     &                    =matmul(matricevs(:,:,j-jfiltsv+1),
+     &                            champ_loc(:iim,j,:))
+#endif
                   ENDDO
                   
Index: LMDZ5/branches/testing/libf/dyn3dmem/friction_loc.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/friction_loc.F	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dmem/friction_loc.F	(revision 1707)
@@ -6,17 +6,23 @@
       USE parallel
       USE control_mod
+#ifdef CPP_IOIPSL
+      USE IOIPSL
+#else
+! if not using IOIPSL, we still need to use (a local version of) getin
+      USE ioipsl_getincom
+#endif
       IMPLICIT NONE
 
-c=======================================================================
-c
-c
-c   Objet:
-c   ------
-c
-c  ***********
-c    Friction
-c  ***********
-c
-c=======================================================================
+!=======================================================================
+!
+!   Friction for the Newtonian case:
+!   --------------------------------
+!    2 possibilities (depending on flag 'friction_type'
+!     friction_type=0 : A friction that is only applied to the lowermost
+!                       atmospheric layer
+!     friction_type=1 : Friction applied on all atmospheric layer (but
+!       (default)       with stronger magnitude near the surface; see
+!                       iniacademic.F)
+!=======================================================================
 
 #include "dimensions.h"
@@ -24,16 +30,41 @@
 #include "comgeom2.h"
 #include "comconst.h"
-
-      REAL pdt
+#include "iniprint.h"
+#include "academic.h"
+
+! arguments:
+      REAL,INTENT(inout) :: ucov( iip1,jjb_u:jje_u,llm )
+      REAL,INTENT(inout) :: vcov( iip1,jjb_v:jje_v,llm )
+      REAL,INTENT(in) :: pdt ! time step
+
+! local variables:
+
       REAL modv(iip1,jjb_u:jje_u),zco,zsi
       REAL vpn,vps,upoln,upols,vpols,vpoln
       REAL u2(iip1,jjb_u:jje_u),v2(iip1,jjb_v:jje_v)
-      REAL ucov( iip1,jjb_u:jje_u,llm ),vcov( iip1,jjb_v:jje_v,llm )
-      INTEGER  i,j
-      REAL cfric
-      parameter (cfric=1.e-5)
+      INTEGER  i,j,l
+      REAL,PARAMETER :: cfric=1.e-5
+      LOGICAL,SAVE :: firstcall=.true.
+      INTEGER,SAVE :: friction_type=1
+      CHARACTER(len=20) :: modname="friction_p"
+      CHARACTER(len=80) :: abort_message
+!$OMP THREADPRIVATE(firstcall,friction_type)
       integer :: jjb,jje
 
-
+!$OMP SINGLE
+      IF (firstcall) THEN
+        ! set friction type
+        call getin("friction_type",friction_type)
+        if ((friction_type.lt.0).or.(friction_type.gt.1)) then
+          abort_message="wrong friction type"
+          write(lunout,*)'Friction: wrong friction type',friction_type
+          call abort_gcm(modname,abort_message,42)
+        endif
+        firstcall=.false.
+      ENDIF
+!$OMP END SINGLE COPYPRIVATE(friction_type,firstcall)
+
+      if (friction_type.eq.0) then ! friction on first layer only
+!$OMP SINGLE
 c   calcul des composantes au carre du vent naturel
       jjb=jj_begin
@@ -138,4 +169,33 @@
          vcov(iip1,j,1)=vcov(1,j,1)
       enddo
+!$OMP END SINGLE
+      endif ! of if (friction_type.eq.0)
+
+      if (friction_type.eq.1) then
+       ! for ucov() 
+        jjb=jj_begin
+        jje=jj_end
+        if (pole_nord) jjb=jj_begin+1
+        if (pole_sud) jje=jj_end-1
+
+!$OMP DO SCHEDULE(STATIC,OMP_CHUNK)
+        do l=1,llm
+          ucov(1:iip1,jjb:jje,l)=ucov(1:iip1,jjb:jje,l)*
+     &                                  (1.-pdt*kfrict(l))
+        enddo
+!$OMP END DO NOWAIT
+        
+       ! for vcoc()
+        jjb=jj_begin
+        jje=jj_end
+        if (pole_sud) jje=jj_end-1
+        
+!$OMP DO SCHEDULE(STATIC,OMP_CHUNK)
+        do l=1,llm
+          vcov(1:iip1,jjb:jje,l)=vcov(1:iip1,jjb:jje,l)*
+     &                                  (1.-pdt*kfrict(l))
+        enddo
+!$OMP END DO
+      endif ! of if (friction_type.eq.1)
 
       RETURN
Index: LMDZ5/branches/testing/libf/dyn3dmem/gcm.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/gcm.F	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dmem/gcm.F	(revision 1707)
@@ -1,4 +1,4 @@
 !
-! $Id: gcm.F 1403 2010-07-01 09:02:53Z fairhead $
+! $Id$
 !
 c
@@ -20,6 +20,5 @@
       USE control_mod
 
-! Ehouarn: for now these only apply to Earth:
-#ifdef CPP_EARTH
+#ifdef CPP_PHYS
       USE mod_grid_phy_lmdz
       USE mod_phys_lmdz_para, ONLY : klon_mpi_para_nb
@@ -87,6 +86,4 @@
 
       REAL zdtvr
-c      INTEGER nbetatmoy, nbetatdem,nbetat
-      INTEGER nbetatmoy, nbetatdem
 
 c   variables dynamiques
@@ -189,13 +186,10 @@
       call ini_getparam("out.def")
       call Read_Distrib
-! Ehouarn : temporarily (?) keep this only for Earth
-      if (planet_type.eq."earth") then
-#ifdef CPP_EARTH
+
+#ifdef CPP_PHYS
         CALL Init_Phys_lmdz(iim,jjp1,llm,mpi_size,distrib_phys)
 #endif
-      endif ! of if (planet_type.eq."earth")
       CALL set_bands
-#ifdef CPP_EARTH
-! Ehouarn: For now only Earth physics is parallel
+#ifdef CPP_PHYS
       CALL Init_interface_dyn_phys
 #endif
@@ -209,12 +203,9 @@
 c$OMP END PARALLEL
 
-! Ehouarn : temporarily (?) keep this only for Earth
-      if (planet_type.eq."earth") then
-#ifdef CPP_EARTH
+#ifdef CPP_PHYS
 c$OMP PARALLEL
       call InitComgeomphy
 c$OMP END PARALLEL 
 #endif
-      endif ! of if (planet_type.eq."earth")
 
 c-----------------------------------------------------------------------
@@ -240,5 +231,5 @@
 #endif
 
-      IF (config_inca /= 'none') THEN
+      IF (type_trac == 'inca') THEN
 #ifdef INCA
          call init_const_lmdz(
@@ -282,18 +273,10 @@
         endif
 
-        if (planet_type.eq."earth") then
-#ifdef CPP_EARTH
+!        if (planet_type.eq."earth") then
 ! Load an Earth-format start file
          CALL dynetat0_loc("start.nc",vcov,ucov,
      &              teta,q,masse,ps,phis, time_0)
-#else
-        ! SW model also has Earth-format start files
-        ! (but can be used without the CPP_EARTH directive)
-          if (iflag_phys.eq.0) then
-            CALL dynetat0_loc("start.nc",vcov,ucov,
-     &              teta,q,masse,ps,phis, time_0)
-          endif
-#endif
-        endif ! of if (planet_type.eq."earth")
+!        endif ! of if (planet_type.eq."earth")
+
 c       write(73,*) 'ucov',ucov
 c       write(74,*) 'vcov',vcov
@@ -337,4 +320,15 @@
 C on remet le calendrier à zero si demande
 c
+      IF (start_time /= starttime) then
+        WRITE(lunout,*)' GCM: Attention l''heure de depart lue dans le'
+     &,' fichier restart ne correspond pas à celle lue dans le run.def'
+        IF (raz_date == 1) then
+          WRITE(lunout,*)'Je prends l''heure lue dans run.def'
+          start_time = starttime
+        ELSE
+          WRITE(lunout,*)'Je m''arrete'
+          CALL abort
+        ENDIF
+      ENDIF
       IF (raz_date == 1) THEN
         annee_ref = anneeref
@@ -404,23 +398,20 @@
 #endif
 
-c  nombre d'etats dans les fichiers demarrage et histoire
-      nbetatdem = nday / iecri
-      nbetatmoy = nday / periodav + 1
 
 c-----------------------------------------------------------------------
 c   Initialisation des constantes dynamiques :
 c   ------------------------------------------
-      dtvr = zdtvr
-      CALL iniconst
+        dtvr = zdtvr
+        CALL iniconst
 
 c-----------------------------------------------------------------------
 c   Initialisation de la geometrie :
 c   --------------------------------
-      CALL inigeom
+        CALL inigeom
 
 c-----------------------------------------------------------------------
 c   Initialisation du filtre :
 c   --------------------------
-      CALL inifilr
+        CALL inifilr
 c
 c-----------------------------------------------------------------------
@@ -429,10 +420,10 @@
 
       CALL inidissip( lstardis, nitergdiv, nitergrot, niterh   ,
-     *                tetagdiv, tetagrot , tetatemp              )
+     *                tetagdiv, tetagrot , tetatemp, vert_prof_dissip)
 
 c-----------------------------------------------------------------------
 c   Initialisation de la physique :
 c   -------------------------------
-      IF (call_iniphys.and.iflag_phys.eq.1) THEN
+      IF (call_iniphys.and.(iflag_phys==1.or.iflag_phys>=100)) THEN
          latfi(1)=rlatu(1)
          lonfi(1)=0.
@@ -455,13 +446,12 @@
          WRITE(lunout,*)
      .       'GCM: WARNING!!! vitesse verticale nulle dans la physique'
-! Earth:
-         if (planet_type.eq."earth") then
-#ifdef CPP_EARTH
-         CALL iniphysiq(ngridmx,llm,daysec,day_ini,dtphys/nsplit_phys ,
-     ,                latfi,lonfi,airefi,zcufi,zcvfi,rad,g,r,cpp     )
-#endif
-         endif ! of if (planet_type.eq."earth")
+! Physics:
+#ifdef CPP_PHYS
+         CALL iniphysiq(ngridmx,llm,daysec,day_ini,dtphys/nsplit_phys, 
+     &                latfi,lonfi,airefi,zcufi,zcvfi,rad,g,r,cpp, 
+     &                iflag_phys) 
+#endif
          call_iniphys=.false.
-      ENDIF ! of IF (call_iniphys.and.(iflag_phys.eq.1))
+      ENDIF ! of IF (call_iniphys.and.(iflag_phys==1.or.iflag_phys>=100))
 
 
@@ -469,5 +459,5 @@
 c   Initialisation des dimensions d'INCA :
 c   --------------------------------------
-      IF (config_inca /= 'none') THEN
+      IF (type_trac == 'inca') THEN
 !$OMP PARALLEL
 #ifdef INCA
@@ -496,7 +486,8 @@
 #endif
 
-      if (planet_type.eq."earth") then
+!      if (planet_type.eq."earth") then
+! Write an Earth-format restart file
         CALL dynredem0_loc("restart.nc", day_end, phis)
-      endif
+!      endif
 
       ecripar = .TRUE.
@@ -544,5 +535,5 @@
 c       write(78,*) 'q',q
 
-c$OMP PARALLEL DEFAULT(SHARED) COPYIN(/temps/,/logic/)
+c$OMP PARALLEL DEFAULT(SHARED) COPYIN(/temps/,/logici/,/logicl/)
       CALL leapfrog_loc(ucov,vcov,teta,ps,masse,phis,q,clesphy0,
      .              time_0)
Index: LMDZ5/branches/testing/libf/dyn3dmem/gr_dyn_fi_p.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/gr_dyn_fi_p.F	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dmem/gr_dyn_fi_p.F	(revision 1707)
@@ -1,9 +1,8 @@
 !
-! $Id: gr_dyn_fi_p.F 1279 2009-12-10 09:02:56Z fairhead $
+! $Id$
 !
       SUBROUTINE gr_dyn_fi_p(nfield,im,jm,ngrid,pdyn,pfi)
-#ifdef CPP_EARTH
+#ifdef CPP_PHYS
 ! Interface with parallel physics,
-! for now this routine only works with Earth physics
       USE mod_interface_dyn_phys
       USE dimphy
@@ -40,10 +39,6 @@
       ENDDO
 c$OMP END DO NOWAIT
-#else
-      write(lunout,*) "gr_fi_dyn_p : This routine should not be called",
-     &   "without parallelized physics"
-      stop
 #endif
-! of #ifdef CPP_EARTH
+! of #ifdef CPP_PHYS
       RETURN
       END
Index: LMDZ5/branches/testing/libf/dyn3dmem/gr_fi_dyn_p.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/gr_fi_dyn_p.F	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dmem/gr_fi_dyn_p.F	(revision 1707)
@@ -1,9 +1,8 @@
 !
-! $Id: gr_fi_dyn_p.F 1279 2009-12-10 09:02:56Z fairhead $
+! $Id$
 !
       SUBROUTINE gr_fi_dyn_p(nfield,ngrid,im,jm,pfi,pdyn)
-#ifdef CPP_EARTH
+#ifdef CPP_PHYS
 ! Interface with parallel physics,
-! for now this routine only works with Earth physics
       USE mod_interface_dyn_phys
       USE dimphy
@@ -52,10 +51,6 @@
       ENDDO
 c$OMP END DO NOWAIT
-#else
-      write(lunout,*) "gr_fi_dyn_p : This routine should not be called",
-     &   "without parallelized physics"
-      stop
 #endif
-! of #ifdef CPP_EARTH
+! of #ifdef CPP_PHYS
       RETURN
       END
Index: LMDZ5/branches/testing/libf/dyn3dmem/grid_noro.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/grid_noro.F	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dmem/grid_noro.F	(revision 1707)
@@ -1,4 +1,4 @@
 !
-! $Id: grid_noro.F 1403 2010-07-01 09:02:53Z fairhead $
+! $Id$
 !
 c
@@ -458,10 +458,7 @@
 C MAKE A MOVING AVERAGE OVER 9 GRIDPOINTS OF THE X FIELDS
 
-      PARAMETER (ISMo=300,JSMo=200)
-      REAL X(IMAR,JMAR),XF(ISMo,JSMo)
+      REAL X(IMAR,JMAR),XF(IMAR,JMAR)
       real WEIGHTpb(-1:1,-1:1)
 
-      if(imar.gt.ismo) stop'surdimensionner ismo dans mva9 (grid_noro)'
-      if(jmar.gt.jsmo) stop'surdimensionner jsmo dans mva9 (grid_noro)'
       
       SUM=0.
Index: LMDZ5/branches/testing/libf/dyn3dmem/grilles_gcm_netcdf_sub.F90
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/grilles_gcm_netcdf_sub.F90	(revision 1707)
+++ LMDZ5/branches/testing/libf/dyn3dmem/grilles_gcm_netcdf_sub.F90	(revision 1707)
@@ -0,0 +1,237 @@
+!
+! $Id$
+!
+! This subroutine creates the file grilles_gcm.nc containg longitudes and
+! latitudes in degrees for grid u and v. This subroutine is called from
+! ce0l if grilles_gcm_netcdf=TRUE. This subroutine corresponds to the first 
+! part in the program create_fausse_var.
+!
+SUBROUTINE grilles_gcm_netcdf_sub(masque,phis)
+
+  IMPLICIT NONE
+
+  INCLUDE "dimensions.h"
+  INCLUDE "paramet.h"
+  INCLUDE "comconst.h"
+  INCLUDE "comgeom.h"
+  INCLUDE "comvert.h"
+  INCLUDE "netcdf.inc"
+  INCLUDE "serre.h"
+
+
+  REAL,DIMENSION(iip1,jjp1),INTENT(IN)  :: masque ! masque terre/mer
+  REAL,DIMENSION(iip1,jjp1),INTENT(IN)  :: phis   ! geopotentiel au sol
+
+  REAL temp(iim+1,jjm+1)
+  ! Attributs netcdf sortie
+  INTEGER ncid_out,rcode_out
+  INTEGER out_lonuid,out_lonvid,out_latuid,out_latvid,out_levid
+  INTEGER out_varid
+  INTEGER out_lonudim,out_lonvdim
+  INTEGER out_latudim,out_latvdim,out_dim(3)
+  INTEGER out_levdim
+
+  INTEGER, PARAMETER :: longcles = 20
+  REAL  clesphy0(longcles)
+
+  INTEGER start(4),COUNT(4)
+
+  INTEGER status,i,j
+  REAL rlatudeg(jjp1),rlatvdeg(jjm),rlevdeg(llm)
+  REAL rlonudeg(iip1),rlonvdeg(iip1)
+
+  REAL dlon1(iip1),dlon2(iip1),dlat1(jjp1),dlat2(jjp1)
+  REAL acoslat,dxkm,dykm,resol(iip1,jjp1)
+  REAL,DIMENSION(iip1,jjp1)  :: phis_loc
+  INTEGER masque_int(iip1,jjp1)
+  INTEGER :: phis_id
+  INTEGER :: area_id
+  INTEGER :: mask_id
+  
+  rad = 6400000
+  omeg = 7.272205e-05
+  g = 9.8
+  kappa = 0.285716
+  daysec = 86400
+  cpp = 1004.70885
+
+  preff = 101325.
+  pa= 50000.
+
+  CALL conf_gcm( 99, .TRUE. , clesphy0 )
+  CALL iniconst
+  CALL inigeom
+
+  DO j=1,jjp1
+     rlatudeg(j)=rlatu(j)*180./pi
+  ENDDO
+  DO j=1,jjm
+     rlatvdeg(j)=rlatv(j)*180./pi
+  ENDDO
+
+  DO i=1,iip1
+     rlonudeg(i)=rlonu(i)*180./pi + 360.
+     rlonvdeg(i)=rlonv(i)*180./pi + 360.
+  ENDDO
+
+
+  !  2 ----- OUVERTURE DE LA SORTIE NETCDF
+  ! ---------------------------------------------------
+  ! CREATION OUTPUT
+  ! ouverture fichier netcdf de sortie out
+  status=NF_CREATE('grilles_gcm.nc',NF_NOCLOBBER,ncid_out)
+  status=NF_DEF_DIM(ncid_out,'lonu',iim+1,out_lonudim)
+  status=NF_DEF_DIM(ncid_out,'lonv',iim+1,out_lonvdim)
+  status=NF_DEF_DIM(ncid_out,'latu',jjm+1,out_latudim)
+  status=NF_DEF_DIM(ncid_out,'latv',jjm,out_latvdim)
+
+
+  !   Longitudes en u
+  status=NF_DEF_VAR(ncid_out,'lonu',NF_FLOAT,1,out_lonudim, out_lonuid)
+  CALL handle_err(status)
+  status=NF_PUT_ATT_TEXT(ncid_out,out_lonuid,'units', 12,'degrees_east')
+  status=NF_PUT_ATT_TEXT(ncid_out,out_lonuid,'long_name',9,'Longitude en u')
+
+  !   Longitudes en v
+  status=NF_DEF_VAR(ncid_out,'lonv',NF_FLOAT,1,out_lonvdim, out_lonvid)
+  CALL handle_err(status)
+  status=NF_PUT_ATT_TEXT(ncid_out,out_lonvid,'units', 12,'degrees_east')
+  status=NF_PUT_ATT_TEXT(ncid_out,out_lonvid,'long_name', 9,'Longitude en v')
+
+  !   Latitude en u
+  status=NF_DEF_VAR(ncid_out,'latu',NF_FLOAT,1,out_latudim, out_latuid)
+  CALL handle_err(status)
+  status=NF_PUT_ATT_TEXT(ncid_out,out_latuid,'units', 13,'degrees_north')
+  status=NF_PUT_ATT_TEXT(ncid_out,out_latuid,'long_name', 8,'Latitude en u')
+
+  !  Latitude en v
+  status=NF_DEF_VAR(ncid_out,'latv',NF_FLOAT,1,out_latvdim, out_latvid)
+  CALL handle_err(status)
+  status=NF_PUT_ATT_TEXT(ncid_out,out_latvid,'units', 13,'degrees_north')
+  status=NF_PUT_ATT_TEXT(ncid_out,out_latvid,'long_name', 8,'Latitude en v')
+
+  !   ecriture de la grille u
+  out_dim(1)=out_lonudim
+  out_dim(2)=out_latudim
+  status=NF_DEF_VAR(ncid_out,'grille_u',NF_FLOAT,2,out_dim, out_varid)
+  CALL handle_err(status)
+  status=NF_PUT_ATT_TEXT(ncid_out,out_varid,'units', 6,'Kelvin')
+  status=NF_PUT_ATT_TEXT(ncid_out,out_varid,'long_name', 16,'Grille aux point u')
+
+  !   ecriture de la grille v
+  out_dim(1)=out_lonvdim
+  out_dim(2)=out_latvdim
+  status=NF_DEF_VAR(ncid_out,'grille_v',NF_FLOAT,2,out_dim, out_varid)
+  CALL handle_err(status)
+  status=NF_PUT_ATT_TEXT(ncid_out,out_varid,'units', 6,'Kelvin')
+  status=NF_PUT_ATT_TEXT(ncid_out,out_varid,'long_name', 16,'Grille aux point v')
+
+  !   ecriture de la grille u
+  out_dim(1)=out_lonvdim
+  out_dim(2)=out_latudim
+  status=NF_DEF_VAR(ncid_out,'grille_s',NF_FLOAT,2,out_dim, out_varid)
+  CALL handle_err(status)
+  status=NF_PUT_ATT_TEXT(ncid_out,out_varid,'units', 6,'Kelvin')
+  status=NF_PUT_ATT_TEXT(ncid_out,out_varid,'long_name',16,'Grille aux point u')
+
+  status=NF_ENDDEF(ncid_out)
+  ! 5) ----- FERMETURE DES FICHIERS NETCDF------------------
+  ! --------------------------------------------------------
+  ! 3-b- Ecriture de la grille pour la sortie
+  ! rajoute l'ecriture de la grille
+
+#ifdef NC_DOUBLE
+  status=NF_PUT_VARA_DOUBLE(ncid_out,out_lonuid,1,iim+1,rlonudeg)
+  status=NF_PUT_VARA_DOUBLE(ncid_out,out_lonvid,1,iim+1,rlonvdeg)
+  status=NF_PUT_VARA_DOUBLE(ncid_out,out_latuid,1,jjm+1,rlatudeg)
+  status=NF_PUT_VARA_DOUBLE(ncid_out,out_latvid,1,jjm,rlatvdeg)
+#else
+  status=NF_PUT_VARA_REAL(ncid_out,out_lonuid,1,iim+1,rlonudeg)
+  status=NF_PUT_VARA_REAL(ncid_out,out_lonvid,1,iim+1,rlonvdeg)
+  status=NF_PUT_VARA_REAL(ncid_out,out_latuid,1,jjm+1,rlatudeg)
+  status=NF_PUT_VARA_REAL(ncid_out,out_latvid,1,jjm,rlatvdeg)
+#endif
+
+  start(1)=1
+  start(2)=1
+  start(3)=1
+  start(4)=1
+
+  COUNT(1)=iim+1
+  COUNT(2)=jjm+1
+  COUNT(3)=1
+  COUNT(4)=1
+
+  DO j=1,jjm+1
+     DO i=1,iim+1
+        temp(i,j)=MOD(i,2)+MOD(j,2)
+     ENDDO
+  ENDDO
+
+#ifdef NC_DOUBLE
+  status=NF_PUT_VARA_DOUBLE(ncid_out,out_varid,start, count,temp)
+#else
+  status=NF_PUT_VARA_REAL(ncid_out,out_varid,start, count,temp)
+#endif
+
+  ! On re-ouvre le fichier pour rajouter 4 nouvelles variables necessaire pour INCA
+! lev - phis - aire - mask
+  rlevdeg(:) = presnivs
+  phis_loc(:,:) = phis(:,:)/g
+
+! niveaux de pression verticaux
+  status = NF_REDEF (ncid_out)
+  status=NF_DEF_DIM(ncid_out,'lev',llm,out_levdim)
+  
+! fields
+  out_dim(1)=out_lonvdim
+  out_dim(2)=out_latudim
+
+  status = nf_def_var(ncid_out,'phis',NF_FLOAT,2,out_dim,phis_id)
+  CALL handle_err(status)
+  status = nf_def_var(ncid_out,'aire',NF_FLOAT,2,out_dim,area_id)
+  CALL handle_err(status)
+  status = nf_def_var(ncid_out,'mask',NF_INT  ,2,out_dim,mask_id)
+  CALL handle_err(status)
+
+  status=NF_ENDDEF(ncid_out)
+
+  ! ecriture des variables
+#ifdef NC_DOUBLE
+  status=NF_PUT_VARA_DOUBLE(ncid_out,out_levid,1,llm,rlevdeg)
+#else
+  status=NF_PUT_VARA_REAL(ncid_out,out_levid,1,llm,rlevdeg)
+#endif
+
+  start(1)=1
+  start(2)=1
+  start(3)=1
+  start(4)=0
+  COUNT(1)=iip1
+  COUNT(2)=jjp1
+  COUNT(3)=1
+  COUNT(4)=0
+
+  status = nf_put_vara_double(ncid_out, phis_id,start,count, phis_loc)
+  status = nf_put_vara_double(ncid_out, area_id,start,count, aire)
+  masque_int(:,:) = nINT(masque(:,:))
+  status = nf_put_vara_int(ncid_out, mask_id,start,count,masque_int)
+  CALL handle_err(status)
+  
+  ! fermeture du fichier netcdf
+  CALL ncclos(ncid_out,rcode_out)
+
+END SUBROUTINE grilles_gcm_netcdf_sub
+
+
+
+SUBROUTINE handle_err(status)
+  INCLUDE "netcdf.inc"
+
+  INTEGER status
+  IF (status.NE.nf_noerr) THEN
+     PRINT *,NF_STRERROR(status)
+     CALL abort_gcm('grilles_gcm_netcdf','netcdf error',1)
+  ENDIF
+END SUBROUTINE handle_err
+
Index: LMDZ5/branches/testing/libf/dyn3dmem/guide_loc_mod.F90
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/guide_loc_mod.F90	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dmem/guide_loc_mod.F90	(revision 1707)
@@ -467,5 +467,5 @@
 !       Calcul niveaux pression milieu de couches 
 	CALL pression_loc( ijnb_u, ap, bp, ps, p )
-	if (disvert_type==1) then
+	if (pressure_exner) then
           CALL exner_hyb_loc(ip1jmp1,ps,p,alpha,beta,pks,pk,pkf)
 	else
Index: LMDZ5/branches/testing/libf/dyn3dmem/guide_p_mod.F90
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/guide_p_mod.F90	(revision 1669)
+++ 	(revision )
@@ -1,1646 +1,0 @@
-!
-! $Id$
-!
-MODULE guide_p_mod
-
-!=======================================================================
-!   Auteur:  F.Hourdin
-!            F. Codron 01/09
-!=======================================================================
-
-  USE getparam
-  USE Write_Field_p
-  use netcdf, only: nf90_nowrite, nf90_open, nf90_inq_varid, nf90_close
-
-  IMPLICIT NONE
-
-! ---------------------------------------------
-! Declarations des cles logiques et parametres 
-! ---------------------------------------------
-  INTEGER, PRIVATE, SAVE  :: iguide_read,iguide_int,iguide_sav
-  INTEGER, PRIVATE, SAVE  :: nlevnc
-  LOGICAL, PRIVATE, SAVE  :: guide_u,guide_v,guide_T,guide_Q,guide_P
-  LOGICAL, PRIVATE, SAVE  :: guide_hr,guide_teta  
-  LOGICAL, PRIVATE, SAVE  :: guide_BL,guide_reg,guide_add,gamma4,guide_zon 
-  LOGICAL, PRIVATE, SAVE  :: guide_modele,invert_p,invert_y,ini_anal
-  LOGICAL, PRIVATE, SAVE  :: guide_2D,guide_sav
-  
-  REAL, PRIVATE, SAVE     :: tau_min_u,tau_max_u
-  REAL, PRIVATE, SAVE     :: tau_min_v,tau_max_v
-  REAL, PRIVATE, SAVE     :: tau_min_T,tau_max_T
-  REAL, PRIVATE, SAVE     :: tau_min_Q,tau_max_Q
-  REAL, PRIVATE, SAVE     :: tau_min_P,tau_max_P
-
-  REAL, PRIVATE, SAVE     :: lat_min_g,lat_max_g
-  REAL, PRIVATE, SAVE     :: lon_min_g,lon_max_g
-  REAL, PRIVATE, SAVE     :: tau_lon,tau_lat
-
-  REAL, ALLOCATABLE, DIMENSION(:), PRIVATE, SAVE     :: alpha_u,alpha_v 
-  REAL, ALLOCATABLE, DIMENSION(:), PRIVATE, SAVE     :: alpha_T,alpha_Q 
-  REAL, ALLOCATABLE, DIMENSION(:), PRIVATE, SAVE     :: alpha_P,alpha_pcor
-  
-! ---------------------------------------------
-! Variables de guidage
-! ---------------------------------------------
-! Variables des fichiers de guidage
-  REAL, ALLOCATABLE, DIMENSION(:,:,:), PRIVATE, SAVE   :: unat1,unat2
-  REAL, ALLOCATABLE, DIMENSION(:,:,:), PRIVATE, SAVE   :: vnat1,vnat2
-  REAL, ALLOCATABLE, DIMENSION(:,:,:), PRIVATE, SAVE   :: tnat1,tnat2
-  REAL, ALLOCATABLE, DIMENSION(:,:,:), PRIVATE, SAVE   :: qnat1,qnat2
-  REAL, ALLOCATABLE, DIMENSION(:,:),   PRIVATE, SAVE   :: psnat1,psnat2
-  REAL, ALLOCATABLE, DIMENSION(:),     PRIVATE, SAVE   :: apnc,bpnc
-! Variables aux dimensions du modele
-  REAL, ALLOCATABLE, DIMENSION(:,:),   PRIVATE, SAVE   :: ugui1,ugui2
-  REAL, ALLOCATABLE, DIMENSION(:,:),   PRIVATE, SAVE   :: vgui1,vgui2
-  REAL, ALLOCATABLE, DIMENSION(:,:),   PRIVATE, SAVE   :: tgui1,tgui2
-  REAL, ALLOCATABLE, DIMENSION(:,:),   PRIVATE, SAVE   :: qgui1,qgui2
-  REAL, ALLOCATABLE, DIMENSION(:),   PRIVATE, SAVE   :: psgui1,psgui2
-  
-  INTEGER,SAVE,PRIVATE :: ijb_u,ijb_v,ije_u,ije_v,ijn_u,ijn_v
-  INTEGER,SAVE,PRIVATE :: jjb_u,jjb_v,jje_u,jje_v,jjn_u,jjn_v
-
-
-CONTAINS
-!=======================================================================
-
-  SUBROUTINE guide_init
-
-    USE control_mod
-    IMPLICIT NONE
-  
-    INCLUDE "dimensions.h"
-    INCLUDE "paramet.h"
-    INCLUDE "netcdf.inc"
-
-    INTEGER                :: error,ncidpl,rid,rcod
-    CHARACTER (len = 80)   :: abort_message
-    CHARACTER (len = 20)   :: modname = 'guide_init'
-
-! ---------------------------------------------
-! Lecture des parametres:  
-! ---------------------------------------------
-! Variables guidees
-    CALL getpar('guide_u',.true.,guide_u,'guidage de u')
-    CALL getpar('guide_v',.true.,guide_v,'guidage de v')
-    CALL getpar('guide_T',.true.,guide_T,'guidage de T')
-    CALL getpar('guide_P',.true.,guide_P,'guidage de P')
-    CALL getpar('guide_Q',.true.,guide_Q,'guidage de Q')
-    CALL getpar('guide_hr',.true.,guide_hr,'guidage de Q par H.R')
-    CALL getpar('guide_teta',.false.,guide_teta,'guidage de T par Teta')
-
-    CALL getpar('guide_add',.false.,guide_add,'for�age constant?')
-    CALL getpar('guide_zon',.false.,guide_zon,'guidage moy zonale')
-
-!   Constantes de rappel. Unite : fraction de jour
-    CALL getpar('tau_min_u',0.02,tau_min_u,'Cste de rappel min, u')
-    CALL getpar('tau_max_u', 10.,tau_max_u,'Cste de rappel max, u')
-    CALL getpar('tau_min_v',0.02,tau_min_v,'Cste de rappel min, v')
-    CALL getpar('tau_max_v', 10.,tau_max_v,'Cste de rappel max, v')
-    CALL getpar('tau_min_T',0.02,tau_min_T,'Cste de rappel min, T')
-    CALL getpar('tau_max_T', 10.,tau_max_T,'Cste de rappel max, T')
-    CALL getpar('tau_min_Q',0.02,tau_min_Q,'Cste de rappel min, Q')
-    CALL getpar('tau_max_Q', 10.,tau_max_Q,'Cste de rappel max, Q')
-    CALL getpar('tau_min_P',0.02,tau_min_P,'Cste de rappel min, P')
-    CALL getpar('tau_max_P', 10.,tau_max_P,'Cste de rappel max, P')
-    CALL getpar('gamma4',.false.,gamma4,'Zone sans rappel elargie')
-    CALL getpar('guide_BL',.true.,guide_BL,'guidage dans C.Lim')
-    
-! Sauvegarde du for�age
-    CALL getpar('guide_sav',.false.,guide_sav,'sauvegarde guidage')
-    CALL getpar('iguide_sav',4,iguide_sav,'freq. sauvegarde guidage')
-    ! frequences f>0: fx/jour; f<0: tous les f jours; f=0: 1 seule fois.
-    IF (iguide_sav.GT.0) THEN
-        iguide_sav=day_step/iguide_sav
-    ELSE
-        iguide_sav=day_step*iguide_sav
-    ENDIF
-
-! Guidage regional seulement (sinon constant ou suivant le zoom)
-    CALL getpar('guide_reg',.false.,guide_reg,'guidage regional')
-    CALL getpar('lat_min_g',-90.,lat_min_g,'Latitude mini guidage ')
-    CALL getpar('lat_max_g', 90.,lat_max_g,'Latitude maxi guidage ')
-    CALL getpar('lon_min_g',-180.,lon_min_g,'longitude mini guidage ')
-    CALL getpar('lon_max_g', 180.,lon_max_g,'longitude maxi guidage ')
-    CALL getpar('tau_lat', 5.,tau_lat,'raideur lat guide regional ')
-    CALL getpar('tau_lon', 5.,tau_lon,'raideur lon guide regional ')
-
-! Parametres pour lecture des fichiers
-    CALL getpar('iguide_read',4,iguide_read,'freq. lecture guidage')
-    CALL getpar('iguide_int',4,iguide_int,'freq. lecture guidage')
-    IF (iguide_int.GT.0) THEN
-        iguide_int=day_step/iguide_int
-    ELSE
-        iguide_int=day_step*iguide_int
-    ENDIF
-    CALL getpar('guide_modele',.false.,guide_modele,'guidage niveaux modele')
-    CALL getpar('ini_anal',.false.,ini_anal,'Etat initial = analyse')
-    CALL getpar('guide_invertp',.true.,invert_p,'niveaux p inverses')
-    CALL getpar('guide_inverty',.true.,invert_y,'inversion N-S')
-    CALL getpar('guide_2D',.false.,guide_2D,'fichier guidage lat-P')
-
-! ---------------------------------------------
-! Determination du nombre de niveaux verticaux
-! des fichiers guidage
-! ---------------------------------------------
-    ncidpl=-99
-    if (guide_modele) then
-       if (ncidpl.eq.-99) rcod=nf90_open('apbp.nc',Nf90_NOWRITe, ncidpl)
-    else
-         if (guide_u) then
-           if (ncidpl.eq.-99) rcod=nf90_open('u.nc',Nf90_NOWRITe,ncidpl)
-         elseif (guide_v) then
-           if (ncidpl.eq.-99) rcod=nf90_open('v.nc',nf90_nowrite,ncidpl)
-         elseif (guide_T) then
-           if (ncidpl.eq.-99) rcod=nf90_open('T.nc',nf90_nowrite,ncidpl)
-         elseif (guide_Q) then
-           if (ncidpl.eq.-99) rcod=nf90_open('hur.nc',nf90_nowrite, ncidpl)
-         endif
-    endif 
-    error=NF_INQ_DIMID(ncidpl,'LEVEL',rid)
-    IF (error.NE.NF_NOERR) error=NF_INQ_DIMID(ncidpl,'PRESSURE',rid)
-    IF (error.NE.NF_NOERR) THEN
-        print *,'Guide: probleme lecture niveaux pression'
-        CALL abort_gcm(modname,abort_message,1)
-    ENDIF
-    error=NF_INQ_DIMLEN(ncidpl,rid,nlevnc)
-    print *,'Guide: nombre niveaux vert. nlevnc', nlevnc 
-    rcod = nf90_close(ncidpl)
-
-! ---------------------------------------------
-! Allocation des variables
-! ---------------------------------------------
-    abort_message='pb in allocation guide'
-
-    ALLOCATE(apnc(nlevnc), stat = error)
-    IF (error /= 0) CALL abort_gcm(modname,abort_message,1)
-    ALLOCATE(bpnc(nlevnc), stat = error)
-    IF (error /= 0) CALL abort_gcm(modname,abort_message,1)
-    apnc=0.;bpnc=0.
-
-    ALLOCATE(alpha_pcor(llm), stat = error)
-    IF (error /= 0) CALL abort_gcm(modname,abort_message,1)
-    ALLOCATE(alpha_u(ip1jmp1), stat = error)
-    IF (error /= 0) CALL abort_gcm(modname,abort_message,1)
-    ALLOCATE(alpha_v(ip1jm), stat = error)
-    IF (error /= 0) CALL abort_gcm(modname,abort_message,1)
-    ALLOCATE(alpha_T(ip1jmp1), stat = error)
-    IF (error /= 0) CALL abort_gcm(modname,abort_message,1)
-    ALLOCATE(alpha_Q(ip1jmp1), stat = error)
-    IF (error /= 0) CALL abort_gcm(modname,abort_message,1)
-    ALLOCATE(alpha_P(ip1jmp1), stat = error)
-    IF (error /= 0) CALL abort_gcm(modname,abort_message,1)
-    alpha_u=0.;alpha_v=0;alpha_T=0;alpha_Q=0;alpha_P=0
-    
-    IF (guide_u) THEN
-        ALLOCATE(unat1(iip1,jjp1,nlevnc), stat = error)
-        IF (error /= 0) CALL abort_gcm(modname,abort_message,1)
-        ALLOCATE(ugui1(ip1jmp1,llm), stat = error)
-        IF (error /= 0) CALL abort_gcm(modname,abort_message,1)
-        ALLOCATE(unat2(iip1,jjp1,nlevnc), stat = error)
-        IF (error /= 0) CALL abort_gcm(modname,abort_message,1)
-        ALLOCATE(ugui2(ip1jmp1,llm), stat = error)
-        IF (error /= 0) CALL abort_gcm(modname,abort_message,1)
-        unat1=0.;unat2=0.;ugui1=0.;ugui2=0.
-    ENDIF
-
-    IF (guide_T) THEN
-        ALLOCATE(tnat1(iip1,jjp1,nlevnc), stat = error)
-        IF (error /= 0) CALL abort_gcm(modname,abort_message,1)
-        ALLOCATE(tgui1(ip1jmp1,llm), stat = error)
-        IF (error /= 0) CALL abort_gcm(modname,abort_message,1)
-        ALLOCATE(tnat2(iip1,jjp1,nlevnc), stat = error)
-        IF (error /= 0) CALL abort_gcm(modname,abort_message,1)
-        ALLOCATE(tgui2(ip1jmp1,llm), stat = error)
-        IF (error /= 0) CALL abort_gcm(modname,abort_message,1)
-        tnat1=0.;tnat2=0.;tgui1=0.;tgui2=0.
-    ENDIF
-     
-    IF (guide_Q) THEN
-        ALLOCATE(qnat1(iip1,jjp1,nlevnc), stat = error)
-        IF (error /= 0) CALL abort_gcm(modname,abort_message,1)
-        ALLOCATE(qgui1(ip1jmp1,llm), stat = error)
-        IF (error /= 0) CALL abort_gcm(modname,abort_message,1)
-        ALLOCATE(qnat2(iip1,jjp1,nlevnc), stat = error)
-        IF (error /= 0) CALL abort_gcm(modname,abort_message,1)
-        ALLOCATE(qgui2(ip1jmp1,llm), stat = error)
-        IF (error /= 0) CALL abort_gcm(modname,abort_message,1)
-        qnat1=0.;qnat2=0.;qgui1=0.;qgui2=0.
-    ENDIF
-
-    IF (guide_v) THEN
-        ALLOCATE(vnat1(iip1,jjm,nlevnc), stat = error)
-        IF (error /= 0) CALL abort_gcm(modname,abort_message,1)
-        ALLOCATE(vgui1(ip1jm,llm), stat = error)
-        IF (error /= 0) CALL abort_gcm(modname,abort_message,1)
-        ALLOCATE(vnat2(iip1,jjm,nlevnc), stat = error)
-        IF (error /= 0) CALL abort_gcm(modname,abort_message,1)
-        ALLOCATE(vgui2(ip1jm,llm), stat = error)
-        IF (error /= 0) CALL abort_gcm(modname,abort_message,1)
-        vnat1=0.;vnat2=0.;vgui1=0.;vgui2=0.
-    ENDIF
-
-    IF (guide_P.OR.guide_modele) THEN
-        ALLOCATE(psnat1(iip1,jjp1), stat = error)
-        IF (error /= 0) CALL abort_gcm(modname,abort_message,1)
-        ALLOCATE(psnat2(iip1,jjp1), stat = error)
-        IF (error /= 0) CALL abort_gcm(modname,abort_message,1)
-        psnat1=0.;psnat2=0.;
-    ENDIF
-    IF (guide_P) THEN
-        ALLOCATE(psgui2(ip1jmp1), stat = error)
-        IF (error /= 0) CALL abort_gcm(modname,abort_message,1)
-        ALLOCATE(psgui1(ip1jmp1), stat = error)
-        IF (error /= 0) CALL abort_gcm(modname,abort_message,1)
-        psgui1=0.;psgui2=0.
-    ENDIF
-
-! ---------------------------------------------
-!   Lecture du premier etat de guidage.
-! ---------------------------------------------
-    IF (guide_2D) THEN
-        CALL guide_read2D(1)
-    ELSE
-        CALL guide_read(1)
-    ENDIF
-    IF (guide_v) vnat1=vnat2
-    IF (guide_u) unat1=unat2
-    IF (guide_T) tnat1=tnat2
-    IF (guide_Q) qnat1=qnat2
-    IF (guide_P.OR.guide_modele) psnat1=psnat2
-
-  END SUBROUTINE guide_init
-
-!=======================================================================
-  SUBROUTINE guide_main(itau,ucov,vcov,teta,q,masse,ps)
-    use parallel
-    USE control_mod
-    
-    IMPLICIT NONE
-  
-    INCLUDE "dimensions.h"
-    INCLUDE "paramet.h"
-    INCLUDE "comconst.h"
-    INCLUDE "comvert.h"
-
-    ! Variables entree
-    INTEGER,                       INTENT(IN)    :: itau !pas de temps
-    REAL, DIMENSION (ip1jmp1,llm), INTENT(INOUT) :: ucov,teta,q,masse
-    REAL, DIMENSION (ip1jm,llm),   INTENT(INOUT) :: vcov
-    REAL, DIMENSION (ip1jmp1),     INTENT(INOUT) :: ps
-
-    ! Variables locales
-    LOGICAL, SAVE :: first=.TRUE.
-    LOGICAL       :: f_out ! sortie guidage
-    REAL, DIMENSION (ip1jmp1,llm) :: f_add ! var aux: champ de guidage
-    REAL, DIMENSION (ip1jmp1,llm) :: p ! besoin si guide_P
-    ! Compteurs temps:
-    INTEGER, SAVE :: step_rea,count_no_rea,itau_test ! lecture guidage
-    REAL          :: ditau, dday_step
-    REAL          :: tau,reste ! position entre 2 etats de guidage
-    REAL, SAVE    :: factt ! pas de temps en fraction de jour
-    
-    INTEGER       :: l
-    
-    ijb_u=ij_begin ; ije_u=ij_end ; ijn_u=ije_u-ijb_u+1  
-    jjb_u=jj_begin ; jje_u=jj_end ; jjn_u=jje_u-jjb_u+1 
-    ijb_v=ij_begin ; ije_v=ij_end ; ijn_v=ije_v-ijb_v+1   
-    jjb_v=jj_begin ; jje_v=jj_end ; jjn_v=jje_v-jjb_v+1 
-    IF (pole_sud) THEN
-      ije_v=ij_end-iip1
-      jje_v=jj_end-1
-      ijn_v=ije_v-ijb_v+1
-      jjn_v=jje_v-jjb_v+1 
-    ENDIF
-      
-    
-    
-     PRINT *,'---> on rentre dans guide_main'
-!    CALL AllGather_Field(ucov,ip1jmp1,llm)
-!    CALL AllGather_Field(vcov,ip1jm,llm)
-!    CALL AllGather_Field(teta,ip1jmp1,llm)
-!    CALL AllGather_Field(ps,ip1jmp1,1)
-!    CALL AllGather_Field(q,ip1jmp1,llm)
-    
-!-----------------------------------------------------------------------
-! Initialisations au premier passage
-!-----------------------------------------------------------------------
-
-    IF (first) THEN
-        first=.FALSE.
-        CALL guide_init 
-        itau_test=1001
-        step_rea=1
-        count_no_rea=0
-! Calcul des constantes de rappel
-        factt=dtvr*iperiod/daysec 
-        call tau2alpha(3,iip1,jjm ,factt,tau_min_v,tau_max_v,alpha_v)
-        call tau2alpha(2,iip1,jjp1,factt,tau_min_u,tau_max_u,alpha_u)
-        call tau2alpha(1,iip1,jjp1,factt,tau_min_T,tau_max_T,alpha_T)
-        call tau2alpha(1,iip1,jjp1,factt,tau_min_P,tau_max_P,alpha_P)
-        call tau2alpha(1,iip1,jjp1,factt,tau_min_Q,tau_max_Q,alpha_Q)
-! correction de rappel dans couche limite
-        if (guide_BL) then
-             alpha_pcor(:)=1.
-        else
-            do l=1,llm
-                alpha_pcor(l)=(1.+tanh((0.85-presnivs(l)/preff)/0.05))/2.
-            enddo
-        endif
-! ini_anal: etat initial egal au guidage        
-        IF (ini_anal) THEN
-            CALL guide_interp(ps,teta)
-            IF (guide_u) ucov(ijb_u:ije_u,:)=ugui2(ijb_u:ije_u,:)
-            IF (guide_v) vcov(ijb_v:ije_v,:)=ugui2(ijb_v:ije_v,:)
-            IF (guide_T) teta(ijb_u:ije_u,:)=tgui2(ijb_u:ije_u,:)
-            IF (guide_Q) q(ijb_u:ije_u,:)=qgui2(ijb_u:ije_u,:)
-            IF (guide_P) THEN
-                ps(ijb_u:ije_u)=psgui2(ijb_u:ije_u)
-                CALL pression_p(ip1jmp1,ap,bp,ps,p)
-                CALL massdair_p(p,masse)
-            ENDIF
-            RETURN
-        ENDIF
-! Verification structure guidage
-        IF (guide_u) THEN
-            CALL writefield_p('unat',unat1)
-            CALL writefield_p('ucov',RESHAPE(ucov,(/iip1,jjp1,llm/)))
-        ENDIF
-        IF (guide_T) THEN
-            CALL writefield_p('tnat',tnat1)
-            CALL writefield_p('teta',RESHAPE(teta,(/iip1,jjp1,llm/)))
-        ENDIF
-
-    ENDIF !first
-
-!-----------------------------------------------------------------------
-! Lecture des fichiers de guidage ?
-!-----------------------------------------------------------------------
-    IF (iguide_read.NE.0) THEN
-      ditau=real(itau)
-      dday_step=real(day_step)
-      IF (iguide_read.LT.0) THEN
-          tau=ditau/dday_step/ REAL(iguide_read)
-      ELSE
-          tau= REAL(iguide_read)*ditau/dday_step
-      ENDIF
-      reste=tau-AINT(tau)
-      IF (reste.EQ.0.) THEN
-          IF (itau_test.EQ.itau) THEN
-              write(*,*)'deuxieme passage de advreel a itau=',itau
-              stop
-          ELSE
-              IF (guide_v) vnat1(:,jjb_v:jje_v,:)=vnat2(:,jjb_v:jje_v,:)
-              IF (guide_u) unat1(:,jjb_u:jje_u,:)=unat2(:,jjb_u:jje_u,:)
-              IF (guide_T) tnat1(:,jjb_u:jje_u,:)=tnat2(:,jjb_u:jje_u,:)
-              IF (guide_Q) qnat1(:,jjb_u:jje_u,:)=qnat2(:,jjb_u:jje_u,:)
-              IF (guide_P.OR.guide_modele) psnat1(:,jjb_u:jje_u)=psnat2(:,jjb_u:jje_u)
-              step_rea=step_rea+1
-              itau_test=itau
-              print*,'Lecture fichiers guidage, pas ',step_rea, &
-                    'apres ',count_no_rea,' non lectures'
-              IF (guide_2D) THEN
-                  CALL guide_read2D(step_rea)
-              ELSE
-                  CALL guide_read(step_rea)
-              ENDIF
-              count_no_rea=0
-          ENDIF
-      ELSE
-        count_no_rea=count_no_rea+1
-
-      ENDIF
-    ENDIF !iguide_read=0
-
-!-----------------------------------------------------------------------
-! Interpolation et conversion des champs de guidage
-!-----------------------------------------------------------------------
-    IF (MOD(itau,iguide_int).EQ.0) THEN
-        CALL guide_interp(ps,teta)
-    ENDIF
-! Repartition entre 2 etats de guidage
-    IF (iguide_read.NE.0) THEN
-        tau=reste
-    ELSE
-        tau=1.
-    ENDIF
-
-!-----------------------------------------------------------------------
-!   Ajout des champs de guidage 
-!-----------------------------------------------------------------------
-! Sauvegarde du guidage?
-    f_out=((MOD(itau,iguide_sav).EQ.0).AND.guide_sav)  
-    IF (f_out) CALL guide_out("S",jjp1,1,ps)
-    
-    if (guide_u) then
-        if (guide_add) then
-           f_add(ijb_u:ije_u,:)=(1.-tau)*ugui1(ijb_u:ije_u,:)+tau*ugui2(ijb_u:ije_u,:)
-        else
-           f_add(ijb_u:ije_u,:)=(1.-tau)*ugui1(ijb_u:ije_u,:)+tau*ugui2(ijb_u:ije_u,:)-ucov(ijb_u:ije_u,:)
-        endif 
-
-        if (guide_zon) CALL guide_zonave(1,jjp1,llm,f_add)
-        CALL guide_addfield(ip1jmp1,llm,f_add,alpha_u)
-        IF (f_out) CALL guide_out("U",jjp1,llm,f_add/factt)
-        ucov(ijb_u:ije_u,:)=ucov(ijb_u:ije_u,:)+f_add(ijb_u:ije_u,:)
-    endif
-
-    if (guide_T) then
-        if (guide_add) then
-           f_add(ijb_u:ije_u,:)=(1.-tau)*tgui1(ijb_u:ije_u,:)+tau*tgui2(ijb_u:ije_u,:)
-        else
-           f_add(ijb_u:ije_u,:)=(1.-tau)*tgui1(ijb_u:ije_u,:)+tau*tgui2(ijb_u:ije_u,:)-teta(ijb_u:ije_u,:)
-        endif 
-        if (guide_zon) CALL guide_zonave(2,jjp1,llm,f_add)
-        CALL guide_addfield(ip1jmp1,llm,f_add,alpha_T)
-        IF (f_out) CALL guide_out("T",jjp1,llm,f_add/factt)
-        teta(ijb_u:ije_u,:)=teta(ijb_u:ije_u,:)+f_add(ijb_u:ije_u,:)
-    endif
-
-    if (guide_P) then
-        if (guide_add) then
-           f_add(ijb_u:ije_u,1)=(1.-tau)*psgui1(ijb_u:ije_u)+tau*psgui2(ijb_u:ije_u)
-        else
-           f_add(ijb_u:ije_u,1)=(1.-tau)*psgui1(ijb_u:ije_u)+tau*psgui2(ijb_u:ije_u)-ps(ijb_u:ije_u)
-        endif 
-        if (guide_zon) CALL guide_zonave(2,jjp1,1,f_add(1:ip1jmp1,1))
-        CALL guide_addfield(ip1jmp1,1,f_add(1:ip1jmp1,1),alpha_P)
-        IF (f_out) CALL guide_out("P",jjp1,1,f_add(1:ip1jmp1,1)/factt)
-        ps(ijb_u:ije_u)=ps(ijb_u:ije_u)+f_add(ijb_u:ije_u,1)
-        CALL pression_p(ip1jmp1,ap,bp,ps,p)
-        CALL massdair_p(p,masse)
-    endif
-
-    if (guide_Q) then
-        if (guide_add) then
-           f_add(ijb_u:ije_u,:)=(1.-tau)*qgui1(ijb_u:ije_u,:)+tau*qgui2(ijb_u:ije_u,:)
-        else
-           f_add(ijb_u:ije_u,:)=(1.-tau)*qgui1(ijb_u:ije_u,:)+tau*qgui2(ijb_u:ije_u,:)-q(ijb_u:ije_u,:)
-        endif 
-        if (guide_zon) CALL guide_zonave(2,jjp1,llm,f_add)
-        CALL guide_addfield(ip1jmp1,llm,f_add,alpha_Q)
-        IF (f_out) CALL guide_out("Q",jjp1,llm,f_add/factt)
-        q(ijb_u:ije_u,:)=q(ijb_u:ije_u,:)+f_add(ijb_u:ije_u,:)
-    endif
-
-    if (guide_v) then
-        if (guide_add) then
-           f_add(ijb_v:ije_v,:)=(1.-tau)*vgui1(ijb_v:ije_v,:)+tau*vgui2(ijb_v:ije_v,:)
-        else
-           f_add(ijb_v:ije_v,:)=(1.-tau)*vgui1(ijb_v:ije_v,:)+tau*vgui2(ijb_v:ije_v,:)-vcov(ijb_v:ije_v,:)
-        endif 
-        
-        if (guide_zon) CALL guide_zonave(2,jjm,llm,f_add(1:ip1jm,:))
-        CALL guide_addfield(ip1jm,llm,f_add(1:ip1jm,:),alpha_v)
-        IF (f_out) CALL guide_out("V",jjm,llm,f_add(1:ip1jm,:)/factt)
-        vcov(ijb_v:ije_v,:)=vcov(ijb_v:ije_v,:)+f_add(ijb_v:ije_v,:)
-    endif
-
-  END SUBROUTINE guide_main
-
-!=======================================================================
-  SUBROUTINE guide_addfield(hsize,vsize,field,alpha)
-! field1=a*field1+alpha*field2
-
-    IMPLICIT NONE
-    INCLUDE "dimensions.h"
-    INCLUDE "paramet.h"
-
-    ! input variables
-    INTEGER,                      INTENT(IN)    :: hsize
-    INTEGER,                      INTENT(IN)    :: vsize
-    REAL, DIMENSION(hsize),       INTENT(IN)    :: alpha 
-    REAL, DIMENSION(hsize,vsize), INTENT(INOUT) :: field
-
-    ! Local variables
-    INTEGER :: l
-
-    IF (hsize==ip1jm) THEN
-      do l=1,vsize
-        field(ijb_v:ije_v,l)=alpha(ijb_v:ije_v)*field(ijb_v:ije_v,l)*alpha_pcor(l)
-      enddo
-    ELSE
-      do l=1,vsize
-        field(ijb_u:ije_u,l)=alpha(ijb_u:ije_u)*field(ijb_u:ije_u,l)*alpha_pcor(l)
-      enddo
-    ENDIF    
-
-  END SUBROUTINE guide_addfield
-
-!=======================================================================
-  SUBROUTINE guide_zonave(typ,hsize,vsize,field)
-
-    IMPLICIT NONE
-
-    INCLUDE "dimensions.h"
-    INCLUDE "paramet.h"
-    INCLUDE "comgeom.h"
-    INCLUDE "comconst.h"
-    
-    ! input/output variables
-    INTEGER,                           INTENT(IN)    :: typ
-    INTEGER,                           INTENT(IN)    :: vsize
-    INTEGER,                           INTENT(IN)    :: hsize
-    REAL, DIMENSION(hsize*iip1,vsize), INTENT(INOUT) :: field
-
-    ! Local variables
-    LOGICAL, SAVE                :: first=.TRUE.
-    INTEGER, DIMENSION (2), SAVE :: imin, imax ! averaging domain
-    INTEGER                      :: i,j,l,ij
-    REAL, DIMENSION (iip1)       :: lond       ! longitude in Deg.
-    REAL, DIMENSION (hsize,vsize):: fieldm     ! zon-averaged field
-
-    IF (first) THEN
-        first=.FALSE.
-!Compute domain for averaging
-        lond=rlonu*180./pi
-        imin(1)=1;imax(1)=iip1;
-        imin(2)=1;imax(2)=iip1;
-        IF (guide_reg) THEN
-            DO i=1,iim
-                IF (lond(i).LT.lon_min_g) imin(1)=i
-                IF (lond(i).LE.lon_max_g) imax(1)=i
-            ENDDO
-            lond=rlonv*180./pi
-            DO i=1,iim
-                IF (lond(i).LT.lon_min_g) imin(2)=i
-                IF (lond(i).LE.lon_max_g) imax(2)=i
-            ENDDO
-        ENDIF
-    ENDIF
-
-    fieldm=0.
-    
-    IF (hsize==jjm) THEN
-      DO l=1,vsize
-      ! Compute zonal average
-          DO j=jjb_v,jje_v
-              DO i=imin(typ),imax(typ)
-                  ij=(j-1)*iip1+i
-                  fieldm(j,l)=fieldm(j,l)+field(ij,l)
-              ENDDO
-          ENDDO 
-          fieldm(:,l)=fieldm(:,l)/ REAL(imax(typ)-imin(typ)+1)
-    ! Compute forcing
-          DO j=jjb_v,jje_v
-              DO i=1,iip1
-                  ij=(j-1)*iip1+i
-                  field(ij,l)=fieldm(j,l)
-              ENDDO
-          ENDDO
-      ENDDO
-    ELSE
-      DO l=1,vsize
-      ! Compute zonal average
-          DO j=jjb_v,jje_v
-              DO i=imin(typ),imax(typ)
-                  ij=(j-1)*iip1+i
-                  fieldm(j,l)=fieldm(j,l)+field(ij,l)
-              ENDDO
-          ENDDO 
-          fieldm(:,l)=fieldm(:,l)/ REAL(imax(typ)-imin(typ)+1)
-    ! Compute forcing
-          DO j=jjb_u,jje_u
-              DO i=1,iip1
-                  ij=(j-1)*iip1+i
-                  field(ij,l)=fieldm(j,l)
-              ENDDO
-          ENDDO
-      ENDDO
-    ENDIF    
-
-  END SUBROUTINE guide_zonave
-
-!=======================================================================
-  SUBROUTINE guide_interp(psi,teta)
-  USE parallel
-  USE mod_hallo
-  USE Bands
-  IMPLICIT NONE
-
-  include "dimensions.h"
-  include "paramet.h"
-  include "comvert.h"
-  include "comgeom2.h"
-  include "comconst.h"
-
-  REAL, DIMENSION (iip1,jjp1),     INTENT(IN) :: psi ! Psol gcm
-  REAL, DIMENSION (iip1,jjp1,llm), INTENT(IN) :: teta ! Temp. Pot. gcm
-
-  LOGICAL, SAVE                      :: first=.TRUE.
-  ! Variables pour niveaux pression:
-  REAL, DIMENSION (iip1,jjp1,nlevnc) :: plnc1,plnc2 !niveaux pression guidage
-  REAL, DIMENSION (iip1,jjp1,llm)    :: plunc,plsnc !niveaux pression modele
-  REAL, DIMENSION (iip1,jjm,llm)     :: plvnc       !niveaux pression modele
-!ym rustine temporaire pour ne pas depasser 2GB pour la stack
-!ym  => crach compilo avec la version intel 12
-  REAL, DIMENSION (:,:,:),ALLOCATABLE,SAVE  :: p           ! pression intercouches 
-  REAL, DIMENSION (:,:,:),ALLOCATABLE,SAVE    :: pls, pext   ! var intermediaire
-  REAL, DIMENSION (:,:,:),ALLOCATABLE,SAVE    :: pbarx 
-  REAL, DIMENSION (:,:,:),ALLOCATABLE,SAVE     :: pbary 
-  ! Variables pour fonction Exner (P milieu couche)
-  REAL, DIMENSION (:,:,:),ALLOCATABLE,SAVE    :: pk, pkf
-  REAL, DIMENSION (:,:,:),ALLOCATABLE,SAVE    :: alpha, beta
-  REAL, DIMENSION (:,:),ALLOCATABLE,SAVE        :: pks    
-  REAL                               :: prefkap,unskap
-  ! Pression de vapeur saturante
-  REAL, DIMENSION (ip1jmp1,llm)      :: qsat
-  !Variables intermediaires interpolation
-
-!ym rustine temporaire pour ne pas depasser 2GB pour la stack
-!ym  => crach compilo avec la version intel 12
-!  REAL, DIMENSION (iip1,jjp1,llm)    :: zu1,zu2 
-!  REAL, DIMENSION (iip1,jjm,llm)     :: zv1,zv2
-  REAL, DIMENSION (:,:,:),ALLOCATABLE,SAVE     :: zu1,zu2 
-  REAL, DIMENSION (:,:,:),ALLOCATABLE,SAVE     :: zv1,zv2
-  
-  INTEGER                            :: i,j,l,ij
-  TYPE(Request) :: Req  
-
-    print *,'Guide: conversion variables guidage'
-! -----------------------------------------------------------------
-! Calcul des niveaux de pression champs guidage
-! -----------------------------------------------------------------
-if (guide_modele) then
-    do i=1,iip1
-        do j=jjb_u,jje_u
-            do l=1,nlevnc
-                plnc2(i,j,l)=apnc(l)+bpnc(l)*psnat2(i,j)
-                plnc1(i,j,l)=apnc(l)+bpnc(l)*psnat1(i,j)
-            enddo
-        enddo
-    enddo
-else
-    do i=1,iip1
-        do j=jjb_u,jje_u
-            do l=1,nlevnc
-                plnc2(i,j,l)=apnc(l)
-                plnc1(i,j,l)=apnc(l)
-           enddo
-        enddo
-    enddo
-
-endif
-    if (first) then
-        first=.FALSE.
-        print*,'Guide: verification ordre niveaux verticaux'
-        print*,'LMDZ :'
-        do l=1,llm
-            print*,'PL(',l,')=',(ap(l)+ap(l+1))/2. &
-                  +psi(1,jje_u)*(bp(l)+bp(l+1))/2.
-        enddo
-        print*,'Fichiers guidage'
-        do l=1,nlevnc
-             print*,'PL(',l,')=',plnc2(1,jjb_u,l)
-        enddo
-        print *,'inversion de l''ordre: invert_p=',invert_p
-        if (guide_u) then
-            do l=1,nlevnc
-                print*,'U(',l,')=',unat2(1,jjb_u,l)
-            enddo
-        endif
-        if (guide_T) then
-            do l=1,nlevnc
-                print*,'T(',l,')=',tnat2(1,jjb_u,l)
-            enddo
-        endif
-        ALLOCATE( zu1(iip1,jjp1,llm),zu2(iip1,jjp1,llm)) 
-        ALLOCATE( zv1(iip1,jjm,llm),zv2(iip1,jjm,llm)) 
-        ALLOCATE( p(iip1,jjp1,llmp1) )
-        ALLOCATE( pls(iip1,jjp1,llm), pext(iip1,jjp1,llm) )
-        ALLOCATE( pbarx(iip1,jjp1,llm) )
-        ALLOCATE( pbary(iip1,jjm,llm) )
-        ALLOCATE( pk(iip1,jjp1,llm),pkf(iip1,jjp1,llm) )
-        ALLOCATE( alpha(iip1,jjp1,llm),beta(iip1,jjp1,llm) )
-        ALLOCATE( pks(iip1,jjp1) )
-      endif
-    
-! -----------------------------------------------------------------
-! Calcul niveaux pression modele 
-! -----------------------------------------------------------------
-    CALL pression_p( ip1jmp1, ap, bp, psi, p )
-    CALL exner_hyb_p(ip1jmp1,psi,p,alpha,beta,pks,pk,pkf)
-
-!    ....  Calcul de pls , pression au milieu des couches ,en Pascals
-    unskap=1./kappa
-    prefkap =  preff  ** kappa
-    DO l = 1, llm
-        DO j=jjb_u,jje_u
-            DO i =1, iip1
-                pls(i,j,l) = preff * ( pk(i,j,l)/cpp) ** unskap
-            ENDDO
-        ENDDO
-    ENDDO
-
-!   calcul des pressions pour les grilles u et v
-    do l=1,llm
-        do j=jjb_u,jje_u
-            do i=1,iip1
-                pext(i,j,l)=pls(i,j,l)*aire(i,j)
-            enddo
-        enddo
-    enddo
-
-     CALL Register_SwapFieldHallo(pext,pext,ip1jmp1,llm,jj_Nb_caldyn,1,2,Req)
-     CALL SendRequest(Req)
-     CALL WaitRequest(Req)
-
-     call massbar_p(pext, pbarx, pbary )
-    do l=1,llm
-        do j=jjb_u,jje_u
-            do i=1,iip1
-                plunc(i,j,l)=pbarx(i,j,l)/aireu(i,j)
-                plsnc(i,j,l)=pls(i,j,l)
-            enddo
-        enddo
-    enddo
-    do l=1,llm
-        do j=jjb_v,jje_v
-            do i=1,iip1
-                plvnc(i,j,l)=pbary(i,j,l)/airev(i,j)
-            enddo
-        enddo
-    enddo
-
-! -----------------------------------------------------------------
-! Interpolation champs guidage sur niveaux modele (+inversion N/S)
-! Conversion en variables gcm (ucov, vcov...)
-! -----------------------------------------------------------------
-    if (guide_P) then
-        do j=jjb_u,jje_u
-            do i=1,iim
-                ij=(j-1)*iip1+i
-                psgui1(ij)=psnat1(i,j)
-                psgui2(ij)=psnat2(i,j)
-            enddo
-            psgui1(iip1*j)=psnat1(1,j)
-            psgui2(iip1*j)=psnat2(1,j)
-        enddo
-    endif
-
-    IF (guide_u) THEN
-        CALL pres2lev(unat1(:,jjb_u:jje_u,:),zu1(:,jjb_u:jje_u,:),nlevnc,llm,            &
-                      plnc1(:,jjb_u:jje_u,:),plunc(:,jjb_u:jje_u,:),iip1,jjn_u,invert_p)
-        CALL pres2lev(unat2(:,jjb_u:jje_u,:),zu2(:,jjb_u:jje_u,:),nlevnc,llm,            &
-                      plnc2(:,jjb_u:jje_u,:),plunc(:,jjb_u:jje_u,:),iip1,jjn_u,invert_p)
-
-        do l=1,llm
-            do j=jjb_u,jje_u
-                do i=1,iim
-                    ij=(j-1)*iip1+i
-                    ugui1(ij,l)=zu1(i,j,l)*cu(i,j)
-                    ugui2(ij,l)=zu2(i,j,l)*cu(i,j)
-                enddo
-                ugui1(j*iip1,l)=ugui1((j-1)*iip1+1,l)    
-                ugui2(j*iip1,l)=ugui2((j-1)*iip1+1,l)    
-            enddo
-            do i=1,iip1
-                ugui1(i,l)=0.
-                ugui1(ip1jm+i,l)=0.
-                ugui2(i,l)=0.
-                ugui2(ip1jm+i,l)=0.
-            enddo
-        enddo
-    ENDIF
-    
-    IF (guide_T) THEN
-        CALL pres2lev(tnat1(:,jjb_u:jje_u,:),zu1(:,jjb_u:jje_u,:),nlevnc,llm,           &
-                      plnc1(:,jjb_u:jje_u,:),plsnc(:,jjb_u:jje_u,:),iip1,jjn_u,invert_p)
-        CALL pres2lev(tnat2(:,jjb_u:jje_u,:),zu2(:,jjb_u:jje_u,:),nlevnc,llm,           &
-                      plnc2(:,jjb_u:jje_u,:),plsnc(:,jjb_u:jje_u,:),iip1,jjn_u,invert_p)
-
-        do l=1,llm
-            do j=jjb_u,jje_u
-                IF (guide_teta) THEN
-		    do i=1,iim
-			ij=(j-1)*iip1+i
-			tgui1(ij,l)=zu1(i,j,l)
-			tgui2(ij,l)=zu2(i,j,l)
-		    enddo
-                ELSE
-		    do i=1,iim
-			ij=(j-1)*iip1+i
-			tgui1(ij,l)=zu1(i,j,l)*cpp/pk(i,j,l)
-			tgui2(ij,l)=zu2(i,j,l)*cpp/pk(i,j,l)
-		    enddo
-                ENDIF
-                tgui1(j*iip1,l)=tgui1((j-1)*iip1+1,l)    
-                tgui2(j*iip1,l)=tgui2((j-1)*iip1+1,l)    
-            enddo
-            do i=1,iip1
-                tgui1(i,l)=tgui1(1,l)
-                tgui1(ip1jm+i,l)=tgui1(ip1jm+1,l) 
-                tgui2(i,l)=tgui2(1,l)
-                tgui2(ip1jm+i,l)=tgui2(ip1jm+1,l) 
-            enddo
-        enddo
-    ENDIF
-
-    IF (guide_v) THEN
-        
-        CALL pres2lev(vnat1(:,jjb_v:jje_v,:),zv1(:,jjb_v:jje_v,:),nlevnc,llm,             &
-                      plnc1(:,jjb_v:jje_v,:),plvnc(:,jjb_v:jje_v,:),iip1,jjn_v,invert_p)
-        CALL pres2lev(vnat2(:,jjb_v:jje_v,:),zv2(:,jjb_v:jje_v,:),nlevnc,llm,             &
-                      plnc2(:,jjb_v:jje_v,:),plvnc(:,jjb_v:jje_v,:),iip1,jjn_v,invert_p)
-
-        do l=1,llm
-            do j=jjb_v,jje_v
-                do i=1,iim
-                    ij=(j-1)*iip1+i
-                    vgui1(ij,l)=zv1(i,j,l)*cv(i,j)
-                    vgui2(ij,l)=zv2(i,j,l)*cv(i,j)
-                enddo
-                vgui1(j*iip1,l)=vgui1((j-1)*iip1+1,l)    
-                vgui2(j*iip1,l)=vgui2((j-1)*iip1+1,l)    
-            enddo
-        enddo
-    ENDIF
-    
-    IF (guide_Q) THEN
-        ! On suppose qu'on a la bonne variable dans le fichier de guidage:
-        ! Hum.Rel si guide_hr, Hum.Spec. sinon.
-        CALL pres2lev(qnat1(:,jjb_u:jje_u,:),zu1(:,jjb_u:jje_u,:),nlevnc,llm,             &
-                      plnc1(:,jjb_u:jje_u,:),plsnc(:,jjb_u:jje_u,:),iip1,jjn_u,invert_p)
-        CALL pres2lev(qnat2(:,jjb_u:jje_u,:),zu2(:,jjb_u:jje_u,:),nlevnc,llm,             &
-                      plnc2(:,jjb_u:jje_u,:),plsnc(:,jjb_u:jje_u,:),iip1,jjn_u,invert_p)
-
-        do l=1,llm
-            do j=jjb_u,jjb_v
-                do i=1,iim
-                    ij=(j-1)*iip1+i
-                    qgui1(ij,l)=zu1(i,j,l)
-                    qgui2(ij,l)=zu2(i,j,l)
-                enddo
-                qgui1(j*iip1,l)=qgui1((j-1)*iip1+1,l)    
-                qgui2(j*iip1,l)=qgui2((j-1)*iip1+1,l)    
-            enddo
-            do i=1,iip1
-                qgui1(i,l)=qgui1(1,l)
-                qgui1(ip1jm+i,l)=qgui1(ip1jm+1,l) 
-                qgui2(i,l)=qgui2(1,l)
-                qgui2(ip1jm+i,l)=qgui2(ip1jm+1,l) 
-            enddo
-        enddo
-        IF (guide_hr) THEN
-            CALL q_sat(iip1*jjn_u*llm,teta(:,jjb_u:jje_u,:)*pk(:,jjb_u:jje_u,:)/cpp,       &
-                       plsnc(:,jjb_u:jje_u,:),qsat(ijb_u:ije_u,:))
-            qgui1(ijb_u:ije_u,:)=qgui1(ijb_u:ije_u,:)*qsat(ijb_u:ije_u,:)*0.01 !hum. rel. en %
-            qgui2(ijb_u:ije_u,:)=qgui2(ijb_u:ije_u,:)*qsat(ijb_u:ije_u,:)*0.01 
-        ENDIF
-    ENDIF
-
-  END SUBROUTINE guide_interp
-
-!=======================================================================
-  SUBROUTINE tau2alpha(typ,pim,pjm,factt,taumin,taumax,alpha)
-
-! Calcul des constantes de rappel alpha (=1/tau)
-
-    implicit none
-
-    include "dimensions.h"
-    include "paramet.h"
-    include "comconst.h"
-    include "comgeom2.h"
-    include "serre.h"
-
-! input arguments :
-    INTEGER, INTENT(IN) :: typ    ! u(2),v(3), ou scalaire(1)
-    INTEGER, INTENT(IN) :: pim,pjm ! dimensions en lat, lon
-    REAL, INTENT(IN)    :: factt   ! pas de temps en fraction de jour
-    REAL, INTENT(IN)    :: taumin,taumax
-! output arguments:
-    REAL, DIMENSION(pim,pjm), INTENT(OUT) :: alpha 
-  
-!  local variables:
-    LOGICAL, SAVE               :: first=.TRUE.
-    REAL, SAVE                  :: gamma,dxdy_min,dxdy_max
-    REAL, DIMENSION (iip1,jjp1) :: zdx,zdy
-    REAL, DIMENSION (iip1,jjp1) :: dxdys,dxdyu
-    REAL, DIMENSION (iip1,jjm)  :: dxdyv
-    real dxdy_
-    real zlat,zlon
-    real alphamin,alphamax,xi
-    integer i,j,ilon,ilat
-
-
-    alphamin=factt/taumax
-    alphamax=factt/taumin
-    IF (guide_reg.OR.guide_add) THEN
-        alpha=alphamax
-!-----------------------------------------------------------------------
-! guide_reg: alpha=alpha_min dans region, 0. sinon.
-!-----------------------------------------------------------------------
-        IF (guide_reg) THEN
-            do j=1,pjm
-                do i=1,pim
-                    if (typ.eq.2) then
-                       zlat=rlatu(j)*180./pi
-                       zlon=rlonu(i)*180./pi
-                    elseif (typ.eq.1) then
-                       zlat=rlatu(j)*180./pi
-                       zlon=rlonv(i)*180./pi
-                    elseif (typ.eq.3) then
-                       zlat=rlatv(j)*180./pi
-                       zlon=rlonv(i)*180./pi
-                    endif
-                    alpha(i,j)=alphamax/16.* &
-                              (1.+tanh((zlat-lat_min_g)/tau_lat))* &
-                              (1.+tanh((lat_max_g-zlat)/tau_lat))* &
-                              (1.+tanh((zlon-lon_min_g)/tau_lon))* &
-                              (1.+tanh((lon_max_g-zlon)/tau_lon))
-                enddo
-            enddo
-        ENDIF
-    ELSE
-!-----------------------------------------------------------------------
-! Sinon, alpha varie entre alpha_min et alpha_max suivant le zoom.
-!-----------------------------------------------------------------------
-!Calcul de l'aire des mailles
-        do j=2,jjm
-            do i=2,iip1
-               zdx(i,j)=0.5*(cu(i-1,j)+cu(i,j))/cos(rlatu(j))
-            enddo
-            zdx(1,j)=zdx(iip1,j)
-        enddo
-        do j=2,jjm
-            do i=1,iip1
-               zdy(i,j)=0.5*(cv(i,j-1)+cv(i,j))
-            enddo
-        enddo
-        do i=1,iip1
-            zdx(i,1)=zdx(i,2)
-            zdx(i,jjp1)=zdx(i,jjm)
-            zdy(i,1)=zdy(i,2)
-            zdy(i,jjp1)=zdy(i,jjm)
-        enddo
-        do j=1,jjp1
-            do i=1,iip1
-               dxdys(i,j)=sqrt(zdx(i,j)*zdx(i,j)+zdy(i,j)*zdy(i,j))
-            enddo
-        enddo
-        IF (typ.EQ.2) THEN
-            do j=1,jjp1
-                do i=1,iim
-                   dxdyu(i,j)=0.5*(dxdys(i,j)+dxdys(i+1,j))
-                enddo
-                dxdyu(iip1,j)=dxdyu(1,j)
-            enddo
-        ENDIF
-        IF (typ.EQ.3) THEN
-            do j=1,jjm
-                do i=1,iip1
-                   dxdyv(i,j)=0.5*(dxdys(i,j)+dxdys(i,j+1))
-                enddo
-            enddo
-        ENDIF
-! Premier appel: calcul des aires min et max et de gamma.
-        IF (first) THEN 
-            first=.FALSE.
-            ! coordonnees du centre du zoom
-            CALL coordij(clon,clat,ilon,ilat) 
-            ! aire de la maille au centre du zoom
-            dxdy_min=dxdys(ilon,ilat)
-            ! dxdy maximale de la maille
-            dxdy_max=0.
-            do j=1,jjp1
-                do i=1,iip1
-                     dxdy_max=max(dxdy_max,dxdys(i,j))
-                enddo
-            enddo
-            ! Calcul de gamma
-            if (abs(grossismx-1.).lt.0.1.or.abs(grossismy-1.).lt.0.1) then
-                 print*,'ATTENTION modele peu zoome'
-                 print*,'ATTENTION on prend une constante de guidage cste'
-                 gamma=0.
-            else
-                gamma=(dxdy_max-2.*dxdy_min)/(dxdy_max-dxdy_min)
-                print*,'gamma=',gamma
-                if (gamma.lt.1.e-5) then
-                  print*,'gamma =',gamma,'<1e-5'
-                  stop
-                endif
-                gamma=log(0.5)/log(gamma)
-                if (gamma4) then 
-                  gamma=min(gamma,4.)
-                endif
-                print*,'gamma=',gamma
-            endif
-        ENDIF !first
-
-        do j=1,pjm
-            do i=1,pim
-                if (typ.eq.1) then
-                   dxdy_=dxdys(i,j)
-                   zlat=rlatu(j)*180./pi
-                elseif (typ.eq.2) then
-                   dxdy_=dxdyu(i,j)
-                   zlat=rlatu(j)*180./pi
-                elseif (typ.eq.3) then
-                   dxdy_=dxdyv(i,j)
-                   zlat=rlatv(j)*180./pi
-                endif
-                if (abs(grossismx-1.).lt.0.1.or.abs(grossismy-1.).lt.0.1) then
-                ! pour une grille reguliere, xi=xxx**0=1 -> alpha=alphamin
-                    alpha(i,j)=alphamin
-                else
-                    xi=((dxdy_max-dxdy_)/(dxdy_max-dxdy_min))**gamma
-                    xi=min(xi,1.)
-                    if(lat_min_g.le.zlat .and. zlat.le.lat_max_g) then
-                        alpha(i,j)=xi*alphamin+(1.-xi)*alphamax
-                    else
-                        alpha(i,j)=0.
-                    endif
-                endif
-            enddo
-        enddo
-    ENDIF ! guide_reg
-
-  END SUBROUTINE tau2alpha
-
-!=======================================================================
-  SUBROUTINE guide_read(timestep)
-
-    IMPLICIT NONE
-
-#include "netcdf.inc"
-#include "dimensions.h"
-#include "paramet.h"
-
-    INTEGER, INTENT(IN)   :: timestep
-
-    LOGICAL, SAVE         :: first=.TRUE.
-! Identification fichiers et variables NetCDF:
-    INTEGER, SAVE         :: ncidu,varidu,ncidv,varidv,ncidQ
-    INTEGER, SAVE         :: varidQ,ncidt,varidt,ncidps,varidps
-    INTEGER               :: ncidpl,varidpl,varidap,varidbp
-! Variables auxiliaires NetCDF:
-    INTEGER, DIMENSION(4) :: start,count
-    INTEGER               :: status,rcode
-
-! -----------------------------------------------------------------
-! Premier appel: initialisation de la lecture des fichiers
-! -----------------------------------------------------------------
-    if (first) then
-         ncidpl=-99
-         print*,'Guide: ouverture des fichiers guidage '
-! Niveaux de pression si non constants
-         if (guide_modele) then
-             print *,'Lecture du guidage sur niveaux mod�le'
-             rcode = nf90_open('apbp.nc', nf90_nowrite, ncidpl)
-             rcode = nf90_inq_varid(ncidpl, 'AP', varidap)
-             rcode = nf90_inq_varid(ncidpl, 'BP', varidbp)
-             print*,'ncidpl,varidap',ncidpl,varidap
-         endif
-! Vent zonal
-         if (guide_u) then
-             rcode = nf90_open('u.nc', nf90_nowrite, ncidu)
-             rcode = nf90_inq_varid(ncidu, 'UWND', varidu)
-             print*,'ncidu,varidu',ncidu,varidu
-             if (ncidpl.eq.-99) ncidpl=ncidu
-         endif
-! Vent meridien
-         if (guide_v) then
-             rcode = nf90_open('v.nc', nf90_nowrite, ncidv)
-             rcode = nf90_inq_varid(ncidv, 'VWND', varidv)
-             print*,'ncidv,varidv',ncidv,varidv
-             if (ncidpl.eq.-99) ncidpl=ncidv
-         endif
-! Temperature
-         if (guide_T) then
-             rcode = nf90_open('T.nc', nf90_nowrite, ncidt)
-             rcode = nf90_inq_varid(ncidt, 'AIR', varidt)
-             print*,'ncidT,varidT',ncidt,varidt
-             if (ncidpl.eq.-99) ncidpl=ncidt
-         endif
-! Humidite
-         if (guide_Q) then
-             rcode = nf90_open('hur.nc', nf90_nowrite, ncidQ)
-             rcode = nf90_inq_varid(ncidQ, 'RH', varidQ)
-             print*,'ncidQ,varidQ',ncidQ,varidQ
-             if (ncidpl.eq.-99) ncidpl=ncidQ
-         endif
-! Pression de surface
-         if ((guide_P).OR.(guide_modele)) then
-             rcode = nf90_open('ps.nc', nf90_nowrite, ncidps)
-             rcode = nf90_inq_varid(ncidps, 'SP', varidps)
-             print*,'ncidps,varidps',ncidps,varidps
-         endif
-! Coordonnee verticale
-         if (.not.guide_modele) then
-              rcode = nf90_inq_varid(ncidpl, 'LEVEL', varidpl)
-              IF (rcode.NE.0) rcode = nf90_inq_varid(ncidpl, 'PRESSURE', varidpl)
-              print*,'ncidpl,varidpl',ncidpl,varidpl
-         endif
-! Coefs ap, bp pour calcul de la pression aux differents niveaux
-         if (guide_modele) then
-#ifdef NC_DOUBLE
-             status=NF_GET_VARA_DOUBLE(ncidpl,varidap,1,nlevnc,apnc)
-             status=NF_GET_VARA_DOUBLE(ncidpl,varidbp,1,nlevnc,bpnc)
-#else
-             status=NF_GET_VARA_REAL(ncidpl,varidap,1,nlevnc,apnc)
-             status=NF_GET_VARA_REAL(ncidpl,varidbp,1,nlevnc,bpnc)
-#endif
-         else
-#ifdef NC_DOUBLE
-             status=NF_GET_VARA_DOUBLE(ncidpl,varidpl,1,nlevnc,apnc)
-#else
-             status=NF_GET_VARA_REAL(ncidpl,varidpl,1,nlevnc,apnc)
-#endif
-             apnc=apnc*100.! conversion en Pascals
-             bpnc(:)=0.
-         endif
-         first=.FALSE.
-     endif ! (first)
-
-! -----------------------------------------------------------------
-!   lecture des champs u, v, T, Q, ps
-! -----------------------------------------------------------------
-
-!  dimensions pour les champs scalaires et le vent zonal
-     start(1)=1
-     start(2)=1
-     start(3)=1
-     start(4)=timestep
-
-     count(1)=iip1
-     count(2)=jjp1
-     count(3)=nlevnc
-     count(4)=1
-
-!  Vent zonal
-     if (guide_u) then
-#ifdef NC_DOUBLE
-         status=NF_GET_VARA_DOUBLE(ncidu,varidu,start,count,unat2)
-#else
-         status=NF_GET_VARA_REAL(ncidu,varidu,start,count,unat2)
-#endif
-         IF (invert_y) THEN
-           CALL invert_lat(iip1,jjp1,nlevnc,unat2)
-         ENDIF
-
-     endif
-
-!  Temperature
-     if (guide_T) then
-#ifdef NC_DOUBLE
-         status=NF_GET_VARA_DOUBLE(ncidt,varidt,start,count,tnat2)
-#else
-         status=NF_GET_VARA_REAL(ncidt,varidt,start,count,tnat2)
-#endif
-         IF (invert_y) THEN
-           CALL invert_lat(iip1,jjp1,nlevnc,tnat2)
-         ENDIF
-     endif
-
-!  Humidite
-     if (guide_Q) then
-#ifdef NC_DOUBLE
-         status=NF_GET_VARA_DOUBLE(ncidQ,varidQ,start,count,qnat2)
-#else
-         status=NF_GET_VARA_REAL(ncidQ,varidQ,start,count,qnat2)
-#endif
-         IF (invert_y) THEN
-           CALL invert_lat(iip1,jjp1,nlevnc,qnat2)
-         ENDIF
-
-     endif
-
-!  Vent meridien
-     if (guide_v) then
-         count(2)=jjm
-#ifdef NC_DOUBLE
-         status=NF_GET_VARA_DOUBLE(ncidv,varidv,start,count,vnat2)
-#else
-         status=NF_GET_VARA_REAL(ncidv,varidv,start,count,vnat2)
-#endif
-         IF (invert_y) THEN
-           CALL invert_lat(iip1,jjm,nlevnc,vnat2)
-         ENDIF
-     endif
-
-!  Pression de surface
-     if ((guide_P).OR.(guide_modele))  then
-         start(3)=timestep
-         start(4)=0
-         count(2)=jjp1
-         count(3)=1
-         count(4)=0
-#ifdef NC_DOUBLE
-         status=NF_GET_VARA_DOUBLE(ncidps,varidps,start,count,psnat2)
-#else
-         status=NF_GET_VARA_REAL(ncidps,varidps,start,count,psnat2)
-#endif
-         IF (invert_y) THEN
-           CALL invert_lat(iip1,jjp1,1,psnat2)
-         ENDIF
-     endif
-
-  END SUBROUTINE guide_read
-
-!=======================================================================
-  SUBROUTINE guide_read2D(timestep)
-
-    IMPLICIT NONE
-
-#include "netcdf.inc"
-#include "dimensions.h"
-#include "paramet.h"
-
-    INTEGER, INTENT(IN)   :: timestep
-
-    LOGICAL, SAVE         :: first=.TRUE.
-! Identification fichiers et variables NetCDF:
-    INTEGER, SAVE         :: ncidu,varidu,ncidv,varidv,ncidQ
-    INTEGER, SAVE         :: varidQ,ncidt,varidt,ncidps,varidps
-    INTEGER               :: ncidpl,varidpl,varidap,varidbp
-! Variables auxiliaires NetCDF:
-    INTEGER, DIMENSION(4) :: start,count
-    INTEGER               :: status,rcode
-! Variables for 3D extension:
-    REAL, DIMENSION (jjp1,llm) :: zu
-    REAL, DIMENSION (jjm,llm)  :: zv
-    INTEGER               :: i
-
-! -----------------------------------------------------------------
-! Premier appel: initialisation de la lecture des fichiers
-! -----------------------------------------------------------------
-    if (first) then
-         ncidpl=-99
-         print*,'Guide: ouverture des fichiers guidage '
-! Niveaux de pression si non constants
-         if (guide_modele) then
-             print *,'Lecture du guidage sur niveaux mod�le'
-             rcode = nf90_open('apbp.nc', nf90_nowrite, ncidpl)
-             rcode = nf90_inq_varid(ncidpl, 'AP', varidap)
-             rcode = nf90_inq_varid(ncidpl, 'BP', varidbp)
-             print*,'ncidpl,varidap',ncidpl,varidap
-         endif
-! Vent zonal
-         if (guide_u) then
-             rcode = nf90_open('u.nc', nf90_nowrite, ncidu)
-             rcode = nf90_inq_varid(ncidu, 'UWND', varidu)
-             print*,'ncidu,varidu',ncidu,varidu
-             if (ncidpl.eq.-99) ncidpl=ncidu
-         endif
-! Vent meridien
-         if (guide_v) then
-             rcode = nf90_open('v.nc', nf90_nowrite, ncidv)
-             rcode = nf90_inq_varid(ncidv, 'VWND', varidv)
-             print*,'ncidv,varidv',ncidv,varidv
-             if (ncidpl.eq.-99) ncidpl=ncidv
-         endif
-! Temperature
-         if (guide_T) then
-             rcode = nf90_open('T.nc', nf90_nowrite, ncidt)
-             rcode = nf90_inq_varid(ncidt, 'AIR', varidt)
-             print*,'ncidT,varidT',ncidt,varidt
-             if (ncidpl.eq.-99) ncidpl=ncidt
-         endif
-! Humidite
-         if (guide_Q) then
-             rcode = nf90_open('hur.nc', nf90_nowrite, ncidQ)
-             rcode = nf90_inq_varid(ncidQ, 'RH', varidQ)
-             print*,'ncidQ,varidQ',ncidQ,varidQ
-             if (ncidpl.eq.-99) ncidpl=ncidQ
-         endif
-! Pression de surface
-         if ((guide_P).OR.(guide_modele)) then
-             rcode = nf90_open('ps.nc', nf90_nowrite, ncidps)
-             rcode = nf90_inq_varid(ncidps, 'SP', varidps)
-             print*,'ncidps,varidps',ncidps,varidps
-         endif
-! Coordonnee verticale
-         if (.not.guide_modele) then
-              rcode = nf90_inq_varid(ncidpl, 'LEVEL', varidpl)
-              IF (rcode.NE.0) rcode = nf90_inq_varid(ncidpl, 'PRESSURE', varidpl)
-              print*,'ncidpl,varidpl',ncidpl,varidpl
-         endif
-! Coefs ap, bp pour calcul de la pression aux differents niveaux
-         if (guide_modele) then
-#ifdef NC_DOUBLE
-             status=NF_GET_VARA_DOUBLE(ncidpl,varidap,1,nlevnc,apnc)
-             status=NF_GET_VARA_DOUBLE(ncidpl,varidbp,1,nlevnc,bpnc)
-#else
-             status=NF_GET_VARA_REAL(ncidpl,varidap,1,nlevnc,apnc)
-             status=NF_GET_VARA_REAL(ncidpl,varidbp,1,nlevnc,bpnc)
-#endif
-         else
-#ifdef NC_DOUBLE
-             status=NF_GET_VARA_DOUBLE(ncidpl,varidpl,1,nlevnc,apnc)
-#else
-             status=NF_GET_VARA_REAL(ncidpl,varidpl,1,nlevnc,apnc)
-#endif
-             apnc=apnc*100.! conversion en Pascals
-             bpnc(:)=0.
-         endif
-         first=.FALSE.
-     endif ! (first)
-
-! -----------------------------------------------------------------
-!   lecture des champs u, v, T, Q, ps
-! -----------------------------------------------------------------
-
-!  dimensions pour les champs scalaires et le vent zonal
-     start(1)=1
-     start(2)=1
-     start(3)=1
-     start(4)=timestep
-
-     count(1)=1
-     count(2)=jjp1
-     count(3)=nlevnc
-     count(4)=1
-
-!  Vent zonal
-     if (guide_u) then
-#ifdef NC_DOUBLE
-         status=NF_GET_VARA_DOUBLE(ncidu,varidu,start,count,zu)
-#else
-         status=NF_GET_VARA_REAL(ncidu,varidu,start,count,zu)
-#endif
-         DO i=1,iip1
-             unat2(i,:,:)=zu(:,:)
-         ENDDO
-
-         IF (invert_y) THEN
-           CALL invert_lat(iip1,jjp1,nlevnc,unat2)
-         ENDIF
-
-     endif
-
-!  Temperature
-     if (guide_T) then
-#ifdef NC_DOUBLE
-         status=NF_GET_VARA_DOUBLE(ncidt,varidt,start,count,zu)
-#else
-         status=NF_GET_VARA_REAL(ncidt,varidt,start,count,zu)
-#endif
-         DO i=1,iip1
-             tnat2(i,:,:)=zu(:,:)
-         ENDDO
-
-         IF (invert_y) THEN
-           CALL invert_lat(iip1,jjp1,nlevnc,tnat2)
-         ENDIF
-
-     endif
-
-!  Humidite
-     if (guide_Q) then
-#ifdef NC_DOUBLE
-         status=NF_GET_VARA_DOUBLE(ncidQ,varidQ,start,count,zu)
-#else
-         status=NF_GET_VARA_REAL(ncidQ,varidQ,start,count,zu)
-#endif
-         DO i=1,iip1
-             qnat2(i,:,:)=zu(:,:)
-         ENDDO
-         
-         IF (invert_y) THEN
-           CALL invert_lat(iip1,jjp1,nlevnc,qnat2)
-         ENDIF
-
-     endif
-
-!  Vent meridien
-     if (guide_v) then
-         count(2)=jjm
-#ifdef NC_DOUBLE
-         status=NF_GET_VARA_DOUBLE(ncidv,varidv,start,count,zv)
-#else
-         status=NF_GET_VARA_REAL(ncidv,varidv,start,count,zv)
-#endif
-         DO i=1,iip1
-             vnat2(i,:,:)=zv(:,:)
-         ENDDO
-
-         IF (invert_y) THEN
-           CALL invert_lat(iip1,jjm,nlevnc,vnat2)
-         ENDIF
-
-     endif
-
-!  Pression de surface
-     if ((guide_P).OR.(guide_modele))  then
-         start(3)=timestep
-         start(4)=0
-         count(2)=jjp1
-         count(3)=1
-         count(4)=0
-#ifdef NC_DOUBLE
-         status=NF_GET_VARA_DOUBLE(ncidps,varidps,start,count,zu(:,1))
-#else
-         status=NF_GET_VARA_REAL(ncidps,varidps,start,count,zu(:,1))
-#endif
-         DO i=1,iip1
-             psnat2(i,:)=zu(:,1)
-         ENDDO
-
-         IF (invert_y) THEN
-           CALL invert_lat(iip1,jjp1,1,psnat2)
-         ENDIF
-
-     endif
-
-  END SUBROUTINE guide_read2D
-  
-!=======================================================================
-  SUBROUTINE guide_out(varname,hsize,vsize,field)
-    USE parallel
-    IMPLICIT NONE
-
-    INCLUDE "dimensions.h"
-    INCLUDE "paramet.h"
-    INCLUDE "netcdf.inc"
-    INCLUDE "comgeom2.h"
-    INCLUDE "comconst.h"
-    INCLUDE "comvert.h"
-    
-    ! Variables entree
-    CHARACTER, INTENT(IN)                          :: varname
-    INTEGER,   INTENT (IN)                         :: hsize,vsize
-    REAL, DIMENSION (iip1,hsize,vsize), INTENT(IN) :: field
-
-    ! Variables locales
-    INTEGER, SAVE :: timestep=0
-    ! Identites fichier netcdf
-    INTEGER       :: nid, id_lonu, id_lonv, id_latu, id_latv, id_tim, id_lev
-    INTEGER       :: vid_lonu,vid_lonv,vid_latu,vid_latv,vid_cu,vid_cv,vid_lev
-    INTEGER, DIMENSION (3) :: dim3
-    INTEGER, DIMENSION (4) :: dim4,count,start
-    INTEGER                :: ierr, varid
-    
-    CALL gather_field(field,iip1*hsize,vsize,0)
-    
-    IF (mpi_rank /= 0) RETURN
-    
-    print *,'Guide: output timestep',timestep,'var ',varname
-    IF (timestep.EQ.0) THEN 
-! ----------------------------------------------
-! initialisation fichier de sortie
-! ----------------------------------------------
-! Ouverture du fichier
-        ierr=NF_CREATE("guide_ins.nc",NF_CLOBBER,nid)
-! Definition des dimensions
-        ierr=NF_DEF_DIM(nid,"LONU",iip1,id_lonu) 
-        ierr=NF_DEF_DIM(nid,"LONV",iip1,id_lonv) 
-        ierr=NF_DEF_DIM(nid,"LATU",jjp1,id_latu) 
-        ierr=NF_DEF_DIM(nid,"LATV",jjm,id_latv) 
-        ierr=NF_DEF_DIM(nid,"LEVEL",llm,id_lev)
-        ierr=NF_DEF_DIM(nid,"TIME",NF_UNLIMITED,id_tim)
-
-! Creation des variables dimensions
-        ierr=NF_DEF_VAR(nid,"LONU",NF_FLOAT,1,id_lonu,vid_lonu)
-        ierr=NF_DEF_VAR(nid,"LONV",NF_FLOAT,1,id_lonv,vid_lonv)
-        ierr=NF_DEF_VAR(nid,"LATU",NF_FLOAT,1,id_latu,vid_latu)
-        ierr=NF_DEF_VAR(nid,"LATV",NF_FLOAT,1,id_latv,vid_latv)
-        ierr=NF_DEF_VAR(nid,"LEVEL",NF_FLOAT,1,id_lev,vid_lev)
-        ierr=NF_DEF_VAR(nid,"cu",NF_FLOAT,2,(/id_lonu,id_latu/),vid_cu)
-        ierr=NF_DEF_VAR(nid,"cv",NF_FLOAT,2,(/id_lonv,id_latv/),vid_cv)
-        
-        ierr=NF_ENDDEF(nid)
-
-! Enregistrement des variables dimensions
-#ifdef NC_DOUBLE
-        ierr = NF_PUT_VAR_DOUBLE(nid,vid_lonu,rlonu*180./pi)
-        ierr = NF_PUT_VAR_DOUBLE(nid,vid_lonv,rlonv*180./pi)
-        ierr = NF_PUT_VAR_DOUBLE(nid,vid_latu,rlatu*180./pi)
-        ierr = NF_PUT_VAR_DOUBLE(nid,vid_latv,rlatv*180./pi)
-        ierr = NF_PUT_VAR_DOUBLE(nid,vid_lev,presnivs)
-        ierr = NF_PUT_VAR_DOUBLE(nid,vid_cu,cu)
-        ierr = NF_PUT_VAR_DOUBLE(nid,vid_cv,cv)
-#else
-        ierr = NF_PUT_VAR_REAL(nid,vid_lonu,rlonu*180./pi)
-        ierr = NF_PUT_VAR_REAL(nid,vid_lonv,rlonv*180./pi)
-        ierr = NF_PUT_VAR_REAL(nid,vid_latu,rlatu*180./pi)
-        ierr = NF_PUT_VAR_REAL(nid,vid_latv,rlatv*180./pi)
-        ierr = NF_PUT_VAR_REAL(nid,vid_lev,presnivs)
-        ierr = NF_PUT_VAR_REAL(nid,vid_cu,cu)
-        ierr = NF_PUT_VAR_REAL(nid,vid_cv,cv)
-#endif
-! --------------------------------------------------------------------
-! Cr�ation des variables sauvegard�es
-! --------------------------------------------------------------------
-        ierr = NF_REDEF(nid)
-! Surface pressure (GCM)
-        dim3=(/id_lonv,id_latu,id_tim/)
-        ierr = NF_DEF_VAR(nid,"SP",NF_FLOAT,3,dim3,varid)
-! Surface pressure (guidage)
-        IF (guide_P) THEN
-            dim3=(/id_lonv,id_latu,id_tim/)
-            ierr = NF_DEF_VAR(nid,"ps",NF_FLOAT,3,dim3,varid)
-        ENDIF
-! Zonal wind
-        IF (guide_u) THEN
-            dim4=(/id_lonu,id_latu,id_lev,id_tim/)
-            ierr = NF_DEF_VAR(nid,"ucov",NF_FLOAT,4,dim4,varid)
-        ENDIF
-! Merid. wind
-        IF (guide_v) THEN
-            dim4=(/id_lonv,id_latv,id_lev,id_tim/)
-            ierr = NF_DEF_VAR(nid,"vcov",NF_FLOAT,4,dim4,varid)
-        ENDIF
-! Pot. Temperature
-        IF (guide_T) THEN
-            dim4=(/id_lonv,id_latu,id_lev,id_tim/)
-            ierr = NF_DEF_VAR(nid,"teta",NF_FLOAT,4,dim4,varid)
-        ENDIF
-! Specific Humidity
-        IF (guide_Q) THEN
-            dim4=(/id_lonv,id_latu,id_lev,id_tim/)
-            ierr = NF_DEF_VAR(nid,"q",NF_FLOAT,4,dim4,varid)
-        ENDIF
-        
-        ierr = NF_ENDDEF(nid)
-        ierr = NF_CLOSE(nid)
-    ENDIF ! timestep=0
-
-! --------------------------------------------------------------------
-! Enregistrement du champ
-! --------------------------------------------------------------------
-    ierr=NF_OPEN("guide_ins.nc",NF_WRITE,nid)
-
-    SELECT CASE (varname)
-    CASE ("S")
-        timestep=timestep+1
-        ierr = NF_INQ_VARID(nid,"SP",varid)
-        start=(/1,1,timestep,0/)
-        count=(/iip1,jjp1,1,0/)
-#ifdef NC_DOUBLE
-        ierr = NF_PUT_VARA_DOUBLE(nid,varid,start,count,field)
-#else
-        ierr = NF_PUT_VARA_REAL(nid,varid,start,count,field)
-#endif
-    CASE ("P")
-        ierr = NF_INQ_VARID(nid,"ps",varid)
-        start=(/1,1,timestep,0/)
-        count=(/iip1,jjp1,1,0/)
-#ifdef NC_DOUBLE
-        ierr = NF_PUT_VARA_DOUBLE(nid,varid,start,count,field)
-#else
-        ierr = NF_PUT_VARA_REAL(nid,varid,start,count,field)
-#endif
-    CASE ("U")
-        ierr = NF_INQ_VARID(nid,"ucov",varid)
-        start=(/1,1,1,timestep/)
-        count=(/iip1,jjp1,llm,1/)
-#ifdef NC_DOUBLE
-        ierr = NF_PUT_VARA_DOUBLE(nid,varid,start,count,field)
-#else
-        ierr = NF_PUT_VARA_REAL(nid,varid,start,count,field)
-#endif
-    CASE ("V")
-        ierr = NF_INQ_VARID(nid,"vcov",varid)
-        start=(/1,1,1,timestep/)
-        count=(/iip1,jjm,llm,1/)
-#ifdef NC_DOUBLE
-        ierr = NF_PUT_VARA_DOUBLE(nid,varid,start,count,field)
-#else
-        ierr = NF_PUT_VARA_REAL(nid,varid,start,count,field)
-#endif
-    CASE ("T")
-        ierr = NF_INQ_VARID(nid,"teta",varid)
-        start=(/1,1,1,timestep/)
-        count=(/iip1,jjp1,llm,1/)
-#ifdef NC_DOUBLE
-        ierr = NF_PUT_VARA_DOUBLE(nid,varid,start,count,field)
-#else
-        ierr = NF_PUT_VARA_REAL(nid,varid,start,count,field)
-#endif
-    CASE ("Q")
-        ierr = NF_INQ_VARID(nid,"q",varid)
-        start=(/1,1,1,timestep/)
-        count=(/iip1,jjp1,llm,1/)
-#ifdef NC_DOUBLE
-        ierr = NF_PUT_VARA_DOUBLE(nid,varid,start,count,field)
-#else
-        ierr = NF_PUT_VARA_REAL(nid,varid,start,count,field)
-#endif
-    END SELECT
- 
-    ierr = NF_CLOSE(nid)
-
-  END SUBROUTINE guide_out
-    
-  
-!===========================================================================
-  subroutine correctbid(iim,nl,x)
-    integer iim,nl
-    real x(iim+1,nl)
-    integer i,l
-    real zz
-
-    do l=1,nl
-        do i=2,iim-1
-            if(abs(x(i,l)).gt.1.e10) then
-               zz=0.5*(x(i-1,l)+x(i+1,l))
-              print*,'correction ',i,l,x(i,l),zz
-               x(i,l)=zz
-            endif
-         enddo
-     enddo
-     return
-  end subroutine correctbid
-
-!===========================================================================
-END MODULE guide_p_mod
Index: LMDZ5/branches/testing/libf/dyn3dmem/infotrac.F90
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/infotrac.F90	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dmem/infotrac.F90	(revision 1707)
@@ -32,4 +32,7 @@
   SUBROUTINE infotrac_init
     USE control_mod
+#ifdef REPROBUS
+    USE CHEM_REP, ONLY : Init_chem_rep_trac
+#endif
     IMPLICIT NONE
 !=======================================================================
@@ -61,10 +64,10 @@
     CHARACTER(len=1), DIMENSION(3)  :: txts
     CHARACTER(len=2), DIMENSION(9)  :: txtp
-    CHARACTER(len=13)               :: str1,str2
+    CHARACTER(len=23)               :: str1,str2
   
     INTEGER :: nqtrue  ! number of tracers read from tracer.def, without higer order of moment
     INTEGER :: iq, new_iq, iiq, jq, ierr
-    INTEGER, EXTERNAL :: lnblnk
- 
+
+    character(len=*),parameter :: modname="infotrac_init"
 !-----------------------------------------------------------------------
 ! Initialization :
@@ -85,9 +88,36 @@
     
 
-    IF (config_inca=='none') THEN
-       type_trac='lmdz'
+    ! Coherence test between parameter type_trac, config_inca and preprocessing keys
+    IF (type_trac=='inca') THEN
+       WRITE(lunout,*) 'You have choosen to couple with INCA chemestry model : type_trac=', &
+            type_trac,' config_inca=',config_inca
+       IF (config_inca/='aero' .AND. config_inca/='chem') THEN
+          WRITE(lunout,*) 'Incoherence between type_trac and config_inca. Model stops. Modify run.def'
+          CALL abort_gcm('infotrac_init','Incoherence between type_trac and config_inca',1)
+       END IF
+#ifndef INCA
+       WRITE(lunout,*) 'To run this option you must add cpp key INCA and compile with INCA code'
+       CALL abort_gcm('infotrac_init','You must compile with cpp key INCA',1)
+#endif
+    ELSE IF (type_trac=='repr') THEN
+       WRITE(lunout,*) 'You have choosen to couple with REPROBUS chemestry model : type_trac=', type_trac
+#ifndef REPROBUS
+       WRITE(lunout,*) 'To run this option you must add cpp key REPROBUS and compile with REPRPBUS code'
+       CALL abort_gcm('infotrac_init','You must compile with cpp key REPROBUS',1)
+#endif
+    ELSE IF (type_trac == 'lmdz') THEN
+       WRITE(lunout,*) 'Tracers are treated in LMDZ only : type_trac=', type_trac
     ELSE
-       type_trac='inca'
-    END IF
+       WRITE(lunout,*) 'type_trac=',type_trac,' not possible. Model stops'
+       CALL abort_gcm('infotrac_init','bad parameter',1)
+    END IF
+
+
+    ! Test if config_inca is other then none for run without INCA
+    IF (type_trac/='inca' .AND. config_inca/='none') THEN
+       WRITE(lunout,*) 'config_inca will now be changed to none as you do not couple with INCA model'
+       config_inca='none'
+    END IF
+
 
 !-----------------------------------------------------------------------
@@ -97,25 +127,43 @@
 !
 !-----------------------------------------------------------------------
-    IF (type_trac == 'lmdz') THEN
+    IF (type_trac == 'lmdz' .OR. type_trac == 'repr') THEN
        OPEN(90,file='traceur.def',form='formatted',status='old', iostat=ierr)
        IF(ierr.EQ.0) THEN
-          WRITE(lunout,*) 'Open traceur.def : ok'
+          WRITE(lunout,*) trim(modname),': Open traceur.def : ok'
           READ(90,*) nqtrue
        ELSE 
-          WRITE(lunout,*) 'Problem in opening traceur.def'
-          WRITE(lunout,*) 'ATTENTION using defaut values'
-          nqtrue=4 ! Defaut value
-       END IF
-       ! Attention! Only for planet_type=='earth'
-       nbtr=nqtrue-2
-    ELSE
-       ! nbtr has been read from INCA by init_cont_lmdz() in gcm.F 
+          WRITE(lunout,*) trim(modname),': Problem in opening traceur.def'
+          WRITE(lunout,*) trim(modname),': WARNING using defaut values'
+          if (planet_type=='earth') then
+            nqtrue=4 ! Default value for Earth
+          else
+            nqtrue=1 ! Default value for other planets
+          endif
+       END IF
+       if ( planet_type=='earth') then
+         ! For Earth, water vapour & liquid tracers are not in the physics
+         nbtr=nqtrue-2
+       else
+         ! Other planets (for now); we have the same number of tracers
+         ! in the dynamics than in the physics
+         nbtr=nqtrue
+       endif
+    ELSE ! type_trac=inca
+       ! nbtr has been read from INCA by init_const_lmdz() in gcm.F 
        nqtrue=nbtr+2
     END IF
 
-    IF (nqtrue < 2) THEN
-       WRITE(lunout,*) 'nqtrue=',nqtrue, ' is not allowded. 2 tracers is the minimum'
+    IF ((planet_type=="earth").and.(nqtrue < 2)) THEN
+       WRITE(lunout,*) trim(modname),': nqtrue=',nqtrue, ' is not allowded. 2 tracers is the minimum'
        CALL abort_gcm('infotrac_init','Not enough tracers',1)
     END IF
+    
+! Transfert number of tracers to Reprobus
+    IF (type_trac == 'repr') THEN
+#ifdef REPROBUS
+       CALL Init_chem_rep_trac(nbtr)
+#endif
+    END IF
+       
 !
 ! Allocate variables depending on nqtrue and nbtr
@@ -152,12 +200,14 @@
 !    Get choice of advection schema from file tracer.def or from INCA
 !---------------------------------------------------------------------
-    IF (type_trac == 'lmdz') THEN
+    IF (type_trac == 'lmdz' .OR. type_trac == 'repr') THEN
        IF(ierr.EQ.0) THEN
           ! Continue to read tracer.def
           DO iq=1,nqtrue
-             READ(90,999) hadv(iq),vadv(iq),tnom_0(iq)
+             READ(90,*) hadv(iq),vadv(iq),tnom_0(iq)
           END DO
           CLOSE(90)  
-       ELSE ! Without tracer.def
+       ELSE ! Without tracer.def, set default values 
+         if (planet_type=="earth") then
+          ! for Earth, default is to have 4 tracers
           hadv(1) = 14
           vadv(1) = 14
@@ -172,8 +222,13 @@
           vadv(4) = 10
           tnom_0(4) = 'PB'
+         else ! default for other planets
+          hadv(1) = 10
+          vadv(1) = 10
+          tnom_0(1) = 'dummy'
+         endif ! of if (planet_type=="earth")
        END IF
        
-       WRITE(lunout,*) 'Valeur de traceur.def :'
-       WRITE(lunout,*) 'nombre de traceurs ',nqtrue
+       WRITE(lunout,*) trim(modname),': Valeur de traceur.def :'
+       WRITE(lunout,*) trim(modname),': nombre de traceurs ',nqtrue
        DO iq=1,nqtrue
           WRITE(lunout,*) hadv(iq),vadv(iq),tnom_0(iq)
@@ -217,5 +272,5 @@
           new_iq=new_iq+10 ! 9 tracers added
        ELSE
-          WRITE(lunout,*) 'This choice of advection schema is not available'
+          WRITE(lunout,*) trim(modname),': This choice of advection schema is not available',iq,hadv(iq),vadv(iq)
           CALL abort_gcm('infotrac_init','Bad choice of advection schema - 1',1)
        END IF
@@ -227,8 +282,8 @@
        nqtot = new_iq
 
-       WRITE(lunout,*) 'The choice of advection schema for one or more tracers'
+       WRITE(lunout,*) trim(modname),': The choice of advection schema for one or more tracers'
        WRITE(lunout,*) 'makes it necessary to add tracers'
-       WRITE(lunout,*) nqtrue,' is the number of true tracers'
-       WRITE(lunout,*) nqtot, ' is the total number of tracers needed'
+       WRITE(lunout,*) trim(modname)//': ',nqtrue,' is the number of true tracers'
+       WRITE(lunout,*) trim(modname)//': ',nqtot, ' is the total number of tracers needed'
 
     ELSE
@@ -258,5 +313,6 @@
           iadv(new_iq)=11
        ELSE
-          WRITE(lunout,*)'This choice of advection schema is not available'
+          WRITE(lunout,*)trim(modname),': This choice of advection schema is not available',iq,hadv(iq),vadv(iq)
+
           CALL abort_gcm('infotrac_init','Bad choice of advection schema - 2',1)
        END IF
@@ -265,7 +321,7 @@
        tname(new_iq)= tnom_0(iq)
        IF (iadv(new_iq)==0) THEN
-          ttext(new_iq)=str1(1:lnblnk(str1))
+          ttext(new_iq)=trim(str1)
        ELSE
-          ttext(new_iq)=str1(1:lnblnk(str1))//descrq(iadv(new_iq))
+          ttext(new_iq)=trim(tnom_0(iq))//descrq(iadv(new_iq))
        END IF
 
@@ -276,6 +332,6 @@
              new_iq=new_iq+1
              iadv(new_iq)=-20
-             ttext(new_iq)=str2(1:lnblnk(str2))//txts(jq)
-             tname(new_iq)=str1(1:lnblnk(str1))//txts(jq)
+             ttext(new_iq)=trim(str2)//txts(jq)
+             tname(new_iq)=trim(str1)//txts(jq)
           END DO
        ELSE IF (iadv(new_iq)==30) THEN
@@ -283,6 +339,6 @@
              new_iq=new_iq+1
              iadv(new_iq)=-30
-             ttext(new_iq)=str2(1:lnblnk(str2))//txtp(jq)
-             tname(new_iq)=str1(1:lnblnk(str1))//txtp(jq)
+             ttext(new_iq)=trim(str2)//txtp(jq)
+             tname(new_iq)=trim(str1)//txtp(jq)
           END DO
        END IF
@@ -303,8 +359,9 @@
 
 
-    WRITE(lunout,*) 'Information stored in infotrac :'
-    WRITE(lunout,*) 'iadv  niadv tname  ttext :'
+    WRITE(lunout,*) trim(modname),': Information stored in infotrac :'
+    WRITE(lunout,*) trim(modname),': iadv  niadv tname  ttext :'
     DO iq=1,nqtot
-       WRITE(lunout,*) iadv(iq),niadv(iq), tname(iq), ttext(iq)
+       WRITE(lunout,*) iadv(iq),niadv(iq),&
+       ' ',trim(tname(iq)),' ',trim(ttext(iq))
     END DO
 
@@ -315,8 +372,8 @@
     DO iq=1,nqtot
        IF (iadv(iq)/=10 .AND. iadv(iq)/=14 .AND. iadv(iq)/=0) THEN
-          WRITE(lunout,*)'STOP : The option iadv=',iadv(iq),' is not tested in this version of LMDZ'
+          WRITE(lunout,*)trim(modname),' STOP : The option iadv=',iadv(iq),' is not tested in this version of LMDZ'
           CALL abort_gcm('infotrac_init','In this version only iadv=10 and iadv=14 is tested!',1)
        ELSE IF (iadv(iq)==14 .AND. iq/=1) THEN
-          WRITE(lunout,*)'STOP : The option iadv=',iadv(iq),' is not tested in this version of LMDZ'
+          WRITE(lunout,*)trim(modname),'STOP : The option iadv=',iadv(iq),' is not tested in this version of LMDZ'
           CALL abort_gcm('infotrac_init','In this version iadv=14 is only permitted for water vapour!',1)
        END IF
@@ -329,6 +386,4 @@
     DEALLOCATE(tracnam)
 
-999 FORMAT (i2,1x,i2,1x,a15)
-
   END SUBROUTINE infotrac_init
 
Index: LMDZ5/branches/testing/libf/dyn3dmem/iniacademic.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/iniacademic.F	(revision 1669)
+++ 	(revision )
@@ -1,220 +1,0 @@
-!
-! $Id: iniacademic.F 1403 2010-07-01 09:02:53Z fairhead $
-!
-c
-c
-      SUBROUTINE iniacademic(vcov,ucov,teta,q,masse,ps,phis,time_0)
-
-      USE filtreg_mod
-      USE infotrac, ONLY : nqtot
-      USE control_mod
- 
-
-c%W%    %G%
-c=======================================================================
-c
-c   Author:    Frederic Hourdin      original: 15/01/93
-c   -------
-c
-c   Subject:
-c   ------
-c
-c   Method:
-c   --------
-c
-c   Interface:
-c   ----------
-c
-c      Input:
-c      ------
-c
-c      Output:
-c      -------
-c
-c=======================================================================
-      IMPLICIT NONE
-c-----------------------------------------------------------------------
-c   Declararations:
-c   ---------------
-
-#include "dimensions.h"
-#include "paramet.h"
-#include "comvert.h"
-#include "comconst.h"
-#include "comgeom.h"
-#include "academic.h"
-#include "ener.h"
-#include "temps.h"
-#include "iniprint.h"
-#include "logic.h"
-
-c   Arguments:
-c   ----------
-
-      real time_0
-
-c   variables dynamiques
-      REAL vcov(ip1jm,llm),ucov(ip1jmp1,llm) ! vents covariants
-      REAL teta(ip1jmp1,llm)                 ! temperature potentielle
-      REAL q(ip1jmp1,llm,nqtot)               ! champs advectes
-      REAL ps(ip1jmp1)                       ! pression  au sol
-      REAL masse(ip1jmp1,llm)                ! masse d'air
-      REAL phis(ip1jmp1)                     ! geopotentiel au sol
-
-c   Local:
-c   ------
-
-      REAL p (ip1jmp1,llmp1  )               ! pression aux interfac.des couches
-      REAL pks(ip1jmp1)                      ! exner au  sol
-      REAL pk(ip1jmp1,llm)                   ! exner au milieu des couches
-      REAL pkf(ip1jmp1,llm)                  ! exner filt.au milieu des couches
-      REAL phi(ip1jmp1,llm)                  ! geopotentiel
-      REAL ddsin,tetarappelj,tetarappell,zsig
-      real tetajl(jjp1,llm)
-      INTEGER i,j,l,lsup,ij
-
-      real zz,ran1
-      integer idum
-
-      REAL alpha(ip1jmp1,llm),beta(ip1jmp1,llm),zdtvr
-
-c-----------------------------------------------------------------------
-! 1. Initializations for Earth-like case
-! --------------------------------------
-      if (planet_type=="earth") then
-c
-        time_0=0.
-        day_ref=0
-        annee_ref=0
-
-        im         = iim
-        jm         = jjm
-        day_ini    = 0
-        omeg       = 4.*asin(1.)/86400.
-        rad    = 6371229.
-        g      = 9.8
-        daysec = 86400.
-        dtvr    = daysec/REAL(day_step)
-        zdtvr=dtvr
-        kappa  = 0.2857143
-        cpp    = 1004.70885
-        preff     = 101325.
-        pa        =  50000.
-        etot0      = 0.
-        ptot0      = 0.
-        ztot0      = 0.
-        stot0      = 0.
-        ang0       = 0.
-
-        if (llm.eq.1) then
-          ! specific initializations for the shallow water case
-          kappa=1
-        endif
-        
-        CALL iniconst
-        CALL inigeom
-        CALL inifilr
-
-        if (llm.eq.1) then
-          ! initialize fields for the shallow water case, if required
-          if (.not.read_start) then
-            phis(:)=0.
-            q(:,:,1)=1.e-10
-            q(:,:,2)=1.e-15
-            q(:,:,3:nqtot)=0.
-            CALL sw_case_williamson91_6(vcov,ucov,teta,masse,ps)
-          endif
-        endif
-
-        if (iflag_phys.eq.2) then
-          ! initializations for the academic case
-          ps(:)=1.e5
-          phis(:)=0.
-c---------------------------------------------------------------------
-
-          taurappel=10.*daysec
-
-c---------------------------------------------------------------------
-c   Calcul de la temperature potentielle :
-c   --------------------------------------
-
-          DO l=1,llm
-            zsig=ap(l)/preff+bp(l)
-            if (zsig.gt.0.3) then
-             lsup=l
-             tetarappell=1./8.*(-log(zsig)-.5)
-             DO j=1,jjp1
-             ddsin=sin(rlatu(j))-sin(pi/20.)
-             tetajl(j,l)=300.*(1+1./18.*(1.-3.*ddsin*ddsin)+tetarappell)
-             ENDDO
-            else
-c   Choix isotherme au-dessus de 300 mbar
-             do j=1,jjp1
-               tetajl(j,l)=tetajl(j,lsup)*(0.3/zsig)**kappa
-             enddo
-            endif ! of if (zsig.gt.0.3)
-          ENDDO ! of DO l=1,llm
-
-          do l=1,llm
-            do j=1,jjp1
-              do i=1,iip1
-                 ij=(j-1)*iip1+i
-                 tetarappel(ij,l)=tetajl(j,l)
-              enddo
-            enddo
-          enddo
-
-c       call dump2d(jjp1,llm,tetajl,'TEQ   ')
-
-          CALL pression ( ip1jmp1, ap, bp, ps, p       )
-          CALL exner_hyb( ip1jmp1, ps, p,alpha,beta, pks, pk, pkf )
-          CALL massdair(p,masse)
-
-c  intialisation du vent et de la temperature
-          teta(:,:)=tetarappel(:,:)
-          CALL geopot(ip1jmp1,teta,pk,pks,phis,phi)
-          call ugeostr(phi,ucov)
-          vcov=0.
-          q(:,:,1   )=1.e-10
-          q(:,:,2   )=1.e-15
-          q(:,:,3:nqtot)=0.
-
-
-c   perturbation aleatoire sur la temperature
-          idum  = -1
-          zz = ran1(idum)
-          idum  = 0
-          do l=1,llm
-            do ij=iip2,ip1jm
-              teta(ij,l)=teta(ij,l)*(1.+0.005*ran1(idum))
-            enddo
-          enddo
-
-          do l=1,llm
-            do ij=1,ip1jmp1,iip1
-              teta(ij+iim,l)=teta(ij,l)
-            enddo
-          enddo
-
-
-
-c     PRINT *,' Appel test_period avec tetarappel '
-c     CALL  test_period ( ucov,vcov,tetarappel,q,p,phis )
-c     PRINT *,' Appel test_period avec teta '
-c     CALL  test_period ( ucov,vcov,teta,q,p,phis )
-
-c   initialisation d'un traceur sur une colonne
-          j=jjp1*3/4
-          i=iip1/2
-          ij=(j-1)*iip1+i
-          q(ij,:,3)=1.
-        endif ! of if (iflag_phys.eq.2)
-        
-      else
-        write(lunout,*)"iniacademic: planet types other than earth",
-     &                 " not implemented (yet)."
-        stop
-      endif ! of if (planet_type=="earth")
-      return
-      END
-c-----------------------------------------------------------------------
Index: LMDZ5/branches/testing/libf/dyn3dmem/iniacademic.F90
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/iniacademic.F90	(revision 1707)
+++ LMDZ5/branches/testing/libf/dyn3dmem/iniacademic.F90	(revision 1707)
@@ -0,0 +1,277 @@
+!
+! $Id: iniacademic.F90 1625 2012-05-09 13:14:48Z lguez $
+!
+SUBROUTINE iniacademic(vcov,ucov,teta,q,masse,ps,phis,time_0)
+
+  USE filtreg_mod
+  USE infotrac, ONLY : nqtot
+  USE control_mod, ONLY: day_step,planet_type
+#ifdef CPP_IOIPSL
+  USE IOIPSL
+#else
+  ! if not using IOIPSL, we still need to use (a local version of) getin
+  USE ioipsl_getincom
+#endif
+  USE Write_Field
+
+  !   Author:    Frederic Hourdin      original: 15/01/93
+  ! The forcing defined here is from Held and Suarez, 1994, Bulletin
+  ! of the American Meteorological Society, 75, 1825.
+
+  IMPLICIT NONE
+
+  !   Declararations:
+  !   ---------------
+
+  include "dimensions.h"
+  include "paramet.h"
+  include "comvert.h"
+  include "comconst.h"
+  include "comgeom.h"
+  include "academic.h"
+  include "ener.h"
+  include "temps.h"
+  include "iniprint.h"
+  include "logic.h"
+
+  !   Arguments:
+  !   ----------
+
+  real time_0
+
+  !   variables dynamiques
+  REAL vcov(ip1jm,llm),ucov(ip1jmp1,llm) ! vents covariants
+  REAL teta(ip1jmp1,llm)                 ! temperature potentielle
+  REAL q(ip1jmp1,llm,nqtot)               ! champs advectes
+  REAL ps(ip1jmp1)                       ! pression  au sol
+  REAL masse(ip1jmp1,llm)                ! masse d'air
+  REAL phis(ip1jmp1)                     ! geopotentiel au sol
+
+  !   Local:
+  !   ------
+
+  REAL p (ip1jmp1,llmp1  )               ! pression aux interfac.des couches
+  REAL pks(ip1jmp1)                      ! exner au  sol
+  REAL pk(ip1jmp1,llm)                   ! exner au milieu des couches
+  REAL pkf(ip1jmp1,llm)                  ! exner filt.au milieu des couches
+  REAL phi(ip1jmp1,llm)                  ! geopotentiel
+  REAL ddsin,zsig,tetapv,w_pv  ! variables auxiliaires
+  real tetastrat ! potential temperature in the stratosphere, in K
+  real tetajl(jjp1,llm)
+  INTEGER i,j,l,lsup,ij
+
+  REAL teta0,ttp,delt_y,delt_z,eps ! Constantes pour profil de T
+  REAL k_f,k_c_a,k_c_s         ! Constantes de rappel
+  LOGICAL ok_geost             ! Initialisation vent geost. ou nul
+  LOGICAL ok_pv                ! Polar Vortex
+  REAL phi_pv,dphi_pv,gam_pv   ! Constantes pour polar vortex 
+
+  real zz,ran1
+  integer idum
+
+  REAL alpha(ip1jmp1,llm),beta(ip1jmp1,llm),zdtvr
+  
+  character(len=*),parameter :: modname="iniacademic"
+  character(len=80) :: abort_message
+
+  !-----------------------------------------------------------------------
+  ! 1. Initializations for Earth-like case
+  ! --------------------------------------
+  !
+  ! initialize planet radius, rotation rate,...
+  call conf_planete
+
+  time_0=0.
+  day_ref=1
+  annee_ref=0
+
+  im         = iim
+  jm         = jjm
+  day_ini    = 1
+  dtvr    = daysec/REAL(day_step)
+  zdtvr=dtvr
+  etot0      = 0.
+  ptot0      = 0.
+  ztot0      = 0.
+  stot0      = 0.
+  ang0       = 0.
+
+  if (llm == 1) then
+     ! specific initializations for the shallow water case
+     kappa=1
+  endif
+
+  CALL iniconst
+  CALL inigeom
+  CALL inifilr
+
+  if (llm == 1) then
+     ! initialize fields for the shallow water case, if required
+     if (.not.read_start) then
+        phis(:)=0.
+        q(:,:,:)=0
+        CALL sw_case_williamson91_6(vcov,ucov,teta,masse,ps)
+     endif
+  endif
+
+  academic_case: if (iflag_phys >= 2) then
+     ! initializations
+
+     ! 1. local parameters
+     ! by convention, winter is in the southern hemisphere
+     ! Geostrophic wind or no wind?
+     ok_geost=.TRUE.
+     CALL getin('ok_geost',ok_geost)
+     ! Constants for Newtonian relaxation and friction
+     k_f=1.                !friction 
+     CALL getin('k_j',k_f)
+     k_f=1./(daysec*k_f)
+     k_c_s=4.  !cooling surface
+     CALL getin('k_c_s',k_c_s)
+     k_c_s=1./(daysec*k_c_s)
+     k_c_a=40. !cooling free atm
+     CALL getin('k_c_a',k_c_a)
+     k_c_a=1./(daysec*k_c_a)
+     ! Constants for Teta equilibrium profile
+     teta0=315.     ! mean Teta (S.H. 315K)
+     CALL getin('teta0',teta0)
+     ttp=200.       ! Tropopause temperature (S.H. 200K)
+     CALL getin('ttp',ttp)
+     eps=0.         ! Deviation to N-S symmetry(~0-20K)
+     CALL getin('eps',eps)
+     delt_y=60.     ! Merid Temp. Gradient (S.H. 60K)
+     CALL getin('delt_y',delt_y)
+     delt_z=10.     ! Vertical Gradient (S.H. 10K)
+     CALL getin('delt_z',delt_z)
+     ! Polar vortex
+     ok_pv=.false.
+     CALL getin('ok_pv',ok_pv)
+     phi_pv=-50.            ! Latitude of edge of vortex
+     CALL getin('phi_pv',phi_pv)
+     phi_pv=phi_pv*pi/180.
+     dphi_pv=5.             ! Width of the edge
+     CALL getin('dphi_pv',dphi_pv)
+     dphi_pv=dphi_pv*pi/180.
+     gam_pv=4.              ! -dT/dz vortex (in K/km)
+     CALL getin('gam_pv',gam_pv)
+
+     ! 2. Initialize fields towards which to relax
+     ! Friction
+     knewt_g=k_c_a
+     DO l=1,llm
+        zsig=presnivs(l)/preff
+        knewt_t(l)=(k_c_s-k_c_a)*MAX(0.,(zsig-0.7)/0.3)
+        kfrict(l)=k_f*MAX(0.,(zsig-0.7)/0.3)
+     ENDDO
+     DO j=1,jjp1
+        clat4((j-1)*iip1+1:j*iip1)=cos(rlatu(j))**4
+     ENDDO
+
+     ! Potential temperature 
+     DO l=1,llm
+        zsig=presnivs(l)/preff
+        tetastrat=ttp*zsig**(-kappa)
+        tetapv=tetastrat
+        IF ((ok_pv).AND.(zsig.LT.0.1)) THEN
+           tetapv=tetastrat*(zsig*10.)**(kappa*cpp*gam_pv/1000./g)
+        ENDIF
+        DO j=1,jjp1
+           ! Troposphere
+           ddsin=sin(rlatu(j))
+           tetajl(j,l)=teta0-delt_y*ddsin*ddsin+eps*ddsin &
+                -delt_z*(1.-ddsin*ddsin)*log(zsig)
+           if (planet_type=="giant") then
+             tetajl(j,l)=teta0+(delt_y*                   &
+                ((sin(rlatu(j)*3.14159*eps+0.0001))**2)   &
+                / ((rlatu(j)*3.14159*eps+0.0001)**2))     &
+                -delt_z*log(zsig)
+           endif
+           ! Profil stratospherique isotherme (+vortex)
+           w_pv=(1.-tanh((rlatu(j)-phi_pv)/dphi_pv))/2.
+           tetastrat=tetastrat*(1.-w_pv)+tetapv*w_pv             
+           tetajl(j,l)=MAX(tetajl(j,l),tetastrat)  
+        ENDDO
+     ENDDO
+
+     !          CALL writefield('theta_eq',tetajl)
+
+     do l=1,llm
+        do j=1,jjp1
+           do i=1,iip1
+              ij=(j-1)*iip1+i
+              tetarappel(ij,l)=tetajl(j,l)
+           enddo
+        enddo
+     enddo
+
+     ! 3. Initialize fields (if necessary)
+     IF (.NOT. read_start) THEN
+        ! surface pressure
+        if (iflag_phys>2) then
+           ! specific value for CMIP5 aqua/terra planets
+           ! "Specify the initial dry mass to be equivalent to
+           !  a global mean surface pressure (101325 minus 245) Pa."
+           ps(:)=101080.  
+        else
+           ! use reference surface pressure
+           ps(:)=preff
+        endif
+        
+        ! ground geopotential
+        phis(:)=0.
+
+        CALL pression ( ip1jmp1, ap, bp, ps, p       )
+        if (pressure_exner) then
+          CALL exner_hyb( ip1jmp1, ps, p,alpha,beta, pks, pk, pkf )
+        else
+          call exner_milieu(ip1jmp1,ps,p,beta,pks,pk,pkf)
+        endif
+        CALL massdair(p,masse)
+
+        ! bulk initialization of temperature
+        teta(:,:)=tetarappel(:,:)
+
+        ! geopotential
+        CALL geopot(ip1jmp1,teta,pk,pks,phis,phi)
+
+        ! winds
+        if (ok_geost) then
+           call ugeostr(phi,ucov)
+        else
+           ucov(:,:)=0.
+        endif
+        vcov(:,:)=0.
+
+        ! bulk initialization of tracers
+        if (planet_type=="earth") then
+           ! Earth: first two tracers will be water
+           do i=1,nqtot
+              if (i == 1) q(:,:,i)=1.e-10
+              if (i == 2) q(:,:,i)=1.e-15
+              if (i.gt.2) q(:,:,i)=0.
+           enddo
+        else
+           q(:,:,:)=0
+        endif ! of if (planet_type=="earth")
+
+        ! add random perturbation to temperature
+        idum  = -1
+        zz = ran1(idum)
+        idum  = 0
+        do l=1,llm
+           do ij=iip2,ip1jm
+              teta(ij,l)=teta(ij,l)*(1.+0.005*ran1(idum))
+           enddo
+        enddo
+
+        ! maintain periodicity in longitude
+        do l=1,llm
+           do ij=1,ip1jmp1,iip1
+              teta(ij+iim,l)=teta(ij,l)
+           enddo
+        enddo
+
+     ENDIF ! of IF (.NOT. read_start)
+  endif academic_case
+
+END SUBROUTINE iniacademic
Index: LMDZ5/branches/testing/libf/dyn3dmem/iniconst.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/iniconst.F	(revision 1669)
+++ 	(revision )
@@ -1,65 +1,0 @@
-!
-! $Id: iniconst.F 1403 2010-07-01 09:02:53Z fairhead $
-!
-      SUBROUTINE iniconst
-
-      USE control_mod
-
-      IMPLICIT NONE
-c
-c      P. Le Van
-c
-c-----------------------------------------------------------------------
-c   Declarations:
-c   -------------
-c
-#include "dimensions.h"
-#include "paramet.h"
-#include "comconst.h"
-#include "temps.h"
-#include "comvert.h"
-#include "iniprint.h"
-
-
-c
-c
-c
-c-----------------------------------------------------------------------
-c   dimension des boucles:
-c   ----------------------
-
-      im      = iim
-      jm      = jjm
-      lllm    = llm
-      imp1    = iim 
-      jmp1    = jjm + 1
-      lllmm1  = llm - 1
-      lllmp1  = llm + 1
-
-      if (planet_type=="earth") then
-        disvert_type=1
-      else
-        disvert_type=2
-      endif
-
-c-----------------------------------------------------------------------
-
-      dtdiss  = idissip * dtvr
-      dtphys  = iphysiq * dtvr
-      unsim   = 1./iim
-      pi      = 2.*ASIN( 1. )
-
-c-----------------------------------------------------------------------
-c
-
-      r       = cpp * kappa
-
-      write(lunout,*)'iniconst: R  CP  Kappa ',  r , cpp,  kappa
-c
-c-----------------------------------------------------------------------
-
-       CALL disvert(pa,preff,ap,bp,dpres,presnivs,nivsigs,nivsig)
-c
-c
-       RETURN
-       END
Index: LMDZ5/branches/testing/libf/dyn3dmem/iniconst.F90
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/iniconst.F90	(revision 1707)
+++ LMDZ5/branches/testing/libf/dyn3dmem/iniconst.F90	(revision 1707)
@@ -0,0 +1,84 @@
+!
+! $Id: iniconst.F90 1625 2012-05-09 13:14:48Z lguez $
+!
+SUBROUTINE iniconst
+
+  USE control_mod
+#ifdef CPP_IOIPSL
+  use IOIPSL
+#else
+  ! if not using IOIPSL, we still need to use (a local version of) getin
+  use ioipsl_getincom
+#endif
+
+  IMPLICIT NONE
+  !
+  !      P. Le Van
+  !
+  !   Declarations:
+  !   -------------
+  !
+  include "dimensions.h"
+  include "paramet.h"
+  include "comconst.h"
+  include "temps.h"
+  include "comvert.h"
+  include "iniprint.h"
+
+  character(len=*),parameter :: modname="iniconst"
+  character(len=80) :: abort_message
+  !
+  !
+  !
+  !-----------------------------------------------------------------------
+  !   dimension des boucles:
+  !   ----------------------
+
+  im      = iim
+  jm      = jjm
+  lllm    = llm
+  imp1    = iim 
+  jmp1    = jjm + 1
+  lllmm1  = llm - 1
+  lllmp1  = llm + 1
+
+  !-----------------------------------------------------------------------
+
+  dtphys  = iphysiq * dtvr
+  unsim   = 1./iim
+  pi      = 2.*ASIN( 1. )
+
+  !-----------------------------------------------------------------------
+  !
+
+  r       = cpp * kappa
+
+  write(lunout,*) trim(modname),': R  CP  Kappa ',r,cpp,kappa
+  !
+  !-----------------------------------------------------------------------
+
+  ! vertical discretization: default behavior depends on planet_type flag
+  if (planet_type=="earth") then
+     disvert_type=1
+  else
+     disvert_type=2
+  endif
+  ! but user can also specify using one or the other in run.def:
+  call getin('disvert_type',disvert_type)
+  write(lunout,*) trim(modname),': disvert_type=',disvert_type
+
+  pressure_exner = disvert_type == 1 ! default value
+  call getin('pressure_exner', pressure_exner)
+
+  if (disvert_type==1) then
+     ! standard case for Earth (automatic generation of levels)
+     call disvert(pa,preff,ap,bp,dpres,presnivs,nivsigs,nivsig, scaleheight)
+  else if (disvert_type==2) then
+     ! standard case for planets (levels generated using z2sig.def file)
+     call disvert_noterre
+  else
+     write(abort_message,*) "Wrong value for disvert_type: ", disvert_type
+     call abort_gcm(modname,abort_message,0)
+  endif
+
+END SUBROUTINE iniconst
Index: LMDZ5/branches/testing/libf/dyn3dmem/inidissip.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/inidissip.F	(revision 1669)
+++ 	(revision )
@@ -1,226 +1,0 @@
-!
-! $Id: inidissip.F 1403 2010-07-01 09:02:53Z fairhead $
-!
-      SUBROUTINE inidissip ( lstardis,nitergdiv,nitergrot,niterh  ,
-     *                       tetagdiv,tetagrot,tetatemp             )
-c=======================================================================
-c   initialisation de la dissipation horizontale
-c=======================================================================
-c-----------------------------------------------------------------------
-c   declarations:
-c   -------------
-
-      USE control_mod
-
-      IMPLICIT NONE
-#include "dimensions.h"
-#include "paramet.h"
-#include "comdissipn.h"
-#include "comconst.h"
-#include "comvert.h"
-#include "logic.h"
-
-      LOGICAL lstardis
-      INTEGER nitergdiv,nitergrot,niterh
-      REAL    tetagdiv,tetagrot,tetatemp
-      REAL fact,zvert(llm),zz
-      REAL zh(ip1jmp1),zu(ip1jmp1),zv(ip1jm),deltap(ip1jmp1,llm)
-      REAL ullm,vllm,umin,vmin,zhmin,zhmax
-      REAL zllm,z1llm
-
-      INTEGER l,ij,idum,ii
-      REAL tetamin
-      REAL pseudoz
-
-      REAL ran1
-
-
-c-----------------------------------------------------------------------
-c
-c   calcul des valeurs propres des operateurs par methode iterrative:
-c   -----------------------------------------------------------------
-
-      crot     = -1.
-      cdivu    = -1.
-      cdivh    = -1.
-
-c   calcul de la valeur propre de divgrad:
-c   --------------------------------------
-      idum = 0
-      DO l = 1, llm
-       DO ij = 1, ip1jmp1
-        deltap(ij,l) = 1.
-       ENDDO
-      ENDDO
-
-      idum  = -1
-      zh(1) = RAN1(idum)-.5
-      idum  = 0
-      DO ij = 2, ip1jmp1
-        zh(ij) = RAN1(idum) -.5
-      ENDDO
-
-      CALL filtreg (zh,jjp1,1,2,1,.TRUE.,1)
-
-      CALL minmax(iip1*jjp1,zh,zhmin,zhmax )
-
-      IF ( zhmin .GE. zhmax  )     THEN
-         PRINT*,'  Inidissip  zh min max  ',zhmin,zhmax
-         STOP'probleme generateur alleatoire dans inidissip'
-      ENDIF
-
-      zllm = ABS( zhmax )
-      DO l = 1,50
-         IF(lstardis) THEN
-            CALL divgrad2(1,zh,deltap,niterh,zh)
-         ELSE
-            CALL divgrad (1,zh,niterh,zh)
-         ENDIF
-
-        CALL minmax(iip1*jjp1,zh,zhmin,zhmax )
-
-         zllm  = ABS( zhmax )
-         z1llm = 1./zllm
-         DO ij = 1,ip1jmp1
-            zh(ij) = zh(ij)* z1llm
-         ENDDO
-      ENDDO
-
-      IF(lstardis) THEN
-         cdivh = 1./ zllm
-      ELSE
-         cdivh = zllm ** ( -1./niterh )
-      ENDIF
-
-c   calcul des valeurs propres de gradiv (ii =1) et  nxgrarot(ii=2)
-c   -----------------------------------------------------------------
-      print*,'calcul des valeurs propres'
-
-      DO  20  ii = 1, 2
-c
-         DO ij = 1, ip1jmp1
-           zu(ij)  = RAN1(idum) -.5
-         ENDDO
-         CALL filtreg (zu,jjp1,1,2,1,.TRUE.,1)
-         DO ij = 1, ip1jm
-            zv(ij) = RAN1(idum) -.5
-         ENDDO
-         CALL filtreg (zv,jjm,1,2,1,.FALSE.,1)
-
-         CALL minmax(iip1*jjp1,zu,umin,ullm )
-         CALL minmax(iip1*jjm, zv,vmin,vllm )
-
-         ullm = ABS ( ullm )
-         vllm = ABS ( vllm )
-
-         DO  5  l = 1, 50
-            IF(ii.EQ.1) THEN
-ccccc             CALL covcont( 1,zu,zv,zu,zv )
-               IF(lstardis) THEN
-                  CALL gradiv2( 1,zu,zv,nitergdiv,zu,zv )
-               ELSE
-                  CALL gradiv ( 1,zu,zv,nitergdiv,zu,zv )
-               ENDIF
-            ELSE
-               IF(lstardis) THEN
-                  CALL nxgraro2( 1,zu,zv,nitergrot,zu,zv )
-               ELSE
-                  CALL nxgrarot( 1,zu,zv,nitergrot,zu,zv )
-               ENDIF
-            ENDIF
-
-            CALL minmax(iip1*jjp1,zu,umin,ullm )
-            CALL minmax(iip1*jjm, zv,vmin,vllm )
-
-            ullm = ABS  ( ullm )
-            vllm = ABS  ( vllm )
-
-            zllm  = MAX( ullm,vllm )
-            z1llm = 1./ zllm
-            DO ij = 1, ip1jmp1
-              zu(ij) = zu(ij)* z1llm
-            ENDDO
-            DO ij = 1, ip1jm
-               zv(ij) = zv(ij)* z1llm
-            ENDDO
- 5       CONTINUE
-
-         IF ( ii.EQ.1 ) THEN
-            IF(lstardis) THEN
-               cdivu  = 1./zllm
-            ELSE
-               cdivu  = zllm **( -1./nitergdiv )
-            ENDIF
-         ELSE
-            IF(lstardis) THEN
-               crot   = 1./ zllm
-            ELSE
-               crot   = zllm **( -1./nitergrot )
-            ENDIF
-         ENDIF
-
- 20   CONTINUE
-
-c   petit test pour les operateurs non star:
-c   ----------------------------------------
-
-c     IF(.NOT.lstardis) THEN
-         fact    = rad*24./REAL(jjm)
-         fact    = fact*fact
-         PRINT*,'coef u ', fact/cdivu, 1./cdivu
-         PRINT*,'coef r ', fact/crot , 1./crot
-         PRINT*,'coef h ', fact/cdivh, 1./cdivh
-c     ENDIF
-
-c-----------------------------------------------------------------------
-c   variation verticale du coefficient de dissipation:
-c   --------------------------------------------------
-
-      if (ok_strato .and. llm==39) then
-         do l=1,llm
-            pseudoz=8.*log(preff/presnivs(l))
-            zvert(l)=1+
-     s      (tanh((pseudoz-dissip_zref)/dissip_deltaz)+1.)/2.
-     s      *(dissip_factz-1.)
-         enddo 
-      else
-         DO l=1,llm
-            zvert(l)=1.
-         ENDDO
-         fact=2.
-         DO l = 1, llm
-            zz      = 1. - preff/presnivs(l)
-            zvert(l)= fact -( fact-1.)/( 1.+zz*zz )
-         ENDDO
-      endif
-
-
-      PRINT*,'Constantes de temps de la diffusion horizontale'
-
-      tetamin =  1.e+6
-
-      DO l=1,llm
-        tetaudiv(l)   = zvert(l)/tetagdiv
-        tetaurot(l)   = zvert(l)/tetagrot
-        tetah(l)      = zvert(l)/tetatemp
-
-        IF( tetamin.GT. (1./tetaudiv(l)) ) tetamin = 1./ tetaudiv(l)
-        IF( tetamin.GT. (1./tetaurot(l)) ) tetamin = 1./ tetaurot(l)
-        IF( tetamin.GT. (1./   tetah(l)) ) tetamin = 1./    tetah(l)
-      ENDDO
-
-      PRINT *,' INIDI tetamin dtvr ',tetamin,dtvr,iperiod
-      idissip = INT( tetamin/( 2.*dtvr*iperiod) ) * iperiod
-      PRINT *,' INIDI tetamin idissip ',tetamin,idissip
-      idissip = MAX(iperiod,idissip)
-      dtdiss  = idissip * dtvr
-      PRINT *,' INIDI idissip dtdiss ',idissip,dtdiss
-
-      DO l = 1,llm
-         PRINT*,zvert(l),dtdiss*tetaudiv(l),dtdiss*tetaurot(l),
-     *                   dtdiss*tetah(l)
-      ENDDO
-
-c
-      RETURN
-      END
Index: LMDZ5/branches/testing/libf/dyn3dmem/inidissip.F90
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/inidissip.F90	(revision 1707)
+++ LMDZ5/branches/testing/libf/dyn3dmem/inidissip.F90	(revision 1707)
@@ -0,0 +1,223 @@
+!
+! $Id: inidissip.F90 1611 2012-01-25 14:31:54Z lguez $
+!
+SUBROUTINE inidissip ( lstardis,nitergdiv,nitergrot,niterh  , &
+     tetagdiv,tetagrot,tetatemp, vert_prof_dissip)
+  !=======================================================================
+  !   initialisation de la dissipation horizontale
+  !=======================================================================
+  !-----------------------------------------------------------------------
+  !   declarations:
+  !   -------------
+
+  USE control_mod, only : dissip_period,iperiod
+
+  IMPLICIT NONE
+  include "dimensions.h"
+  include "paramet.h"
+  include "comdissipn.h"
+  include "comconst.h"
+  include "comvert.h"
+  include "logic.h"
+  include "iniprint.h"
+
+  LOGICAL,INTENT(in) :: lstardis
+  INTEGER,INTENT(in) :: nitergdiv,nitergrot,niterh
+  REAL,INTENT(in) :: tetagdiv,tetagrot,tetatemp
+
+  integer, INTENT(in):: vert_prof_dissip
+  ! Vertical profile of horizontal dissipation
+  ! Allowed values:
+  ! 0: rational fraction, function of pressure
+  ! 1: tanh of altitude
+
+! Local variables:
+  REAL fact,zvert(llm),zz
+  REAL zh(ip1jmp1),zu(ip1jmp1), gx(ip1jmp1), divgra(ip1jmp1)
+  real zv(ip1jm), gy(ip1jm), deltap(ip1jmp1,llm)
+  REAL ullm,vllm,umin,vmin,zhmin,zhmax
+  REAL zllm
+
+  INTEGER l,ij,idum,ii
+  REAL tetamin
+  REAL pseudoz
+  character (len=80) :: abort_message
+
+  REAL ran1
+
+
+  !-----------------------------------------------------------------------
+  !
+  !   calcul des valeurs propres des operateurs par methode iterrative:
+  !   -----------------------------------------------------------------
+
+  crot     = -1.
+  cdivu    = -1.
+  cdivh    = -1.
+
+  !   calcul de la valeur propre de divgrad:
+  !   --------------------------------------
+  idum = 0
+  DO l = 1, llm
+     DO ij = 1, ip1jmp1
+        deltap(ij,l) = 1.
+     ENDDO
+  ENDDO
+
+  idum  = -1
+  zh(1) = RAN1(idum)-.5
+  idum  = 0
+  DO ij = 2, ip1jmp1
+     zh(ij) = RAN1(idum) -.5
+  ENDDO
+
+  CALL filtreg (zh,jjp1,1,2,1,.TRUE.,1)
+
+  CALL minmax(iip1*jjp1,zh,zhmin,zhmax )
+
+  IF ( zhmin .GE. zhmax  )     THEN
+     write(lunout,*)'  Inidissip  zh min max  ',zhmin,zhmax
+     abort_message='probleme generateur alleatoire dans inidissip'
+     call abort_gcm('inidissip',abort_message,1)
+  ENDIF
+
+  zllm = ABS( zhmax )
+  DO l = 1,50
+     IF(lstardis) THEN
+        CALL divgrad2(1,zh,deltap,niterh,divgra)
+     ELSE
+        CALL divgrad (1,zh,niterh,divgra)
+     ENDIF
+
+     zllm  = ABS(maxval(divgra))
+     zh = divgra / zllm
+  ENDDO
+
+  IF(lstardis) THEN
+     cdivh = 1./ zllm
+  ELSE
+     cdivh = zllm ** ( -1./niterh )
+  ENDIF
+
+  !   calcul des valeurs propres de gradiv (ii =1) et  nxgrarot(ii=2)
+  !   -----------------------------------------------------------------
+  write(lunout,*)'inidissip: calcul des valeurs propres'
+
+  DO    ii = 1, 2
+     !
+     DO ij = 1, ip1jmp1
+        zu(ij)  = RAN1(idum) -.5
+     ENDDO
+     CALL filtreg (zu,jjp1,1,2,1,.TRUE.,1)
+     DO ij = 1, ip1jm
+        zv(ij) = RAN1(idum) -.5
+     ENDDO
+     CALL filtreg (zv,jjm,1,2,1,.FALSE.,1)
+
+     CALL minmax(iip1*jjp1,zu,umin,ullm )
+     CALL minmax(iip1*jjm, zv,vmin,vllm )
+
+     ullm = ABS ( ullm )
+     vllm = ABS ( vllm )
+
+     DO    l = 1, 50
+        IF(ii.EQ.1) THEN
+           !cccc             CALL covcont( 1,zu,zv,zu,zv )
+           IF(lstardis) THEN
+              CALL gradiv2( 1,zu,zv,nitergdiv,gx,gy )
+           ELSE
+              CALL gradiv ( 1,zu,zv,nitergdiv,gx,gy )
+           ENDIF
+        ELSE
+           IF(lstardis) THEN
+              CALL nxgraro2( 1,zu,zv,nitergrot,gx,gy )
+           ELSE
+              CALL nxgrarot( 1,zu,zv,nitergrot,gx,gy )
+           ENDIF
+        ENDIF
+
+        zllm = max(abs(maxval(gx)), abs(maxval(gy)))
+        zu = gx / zllm
+        zv = gy / zllm
+     end DO
+
+     IF ( ii.EQ.1 ) THEN
+        IF(lstardis) THEN
+           cdivu  = 1./zllm
+        ELSE
+           cdivu  = zllm **( -1./nitergdiv )
+        ENDIF
+     ELSE
+        IF(lstardis) THEN
+           crot   = 1./ zllm
+        ELSE
+           crot   = zllm **( -1./nitergrot )
+        ENDIF
+     ENDIF
+
+  end DO
+
+  !   petit test pour les operateurs non star:
+  !   ----------------------------------------
+
+  !     IF(.NOT.lstardis) THEN
+  fact    = rad*24./REAL(jjm)
+  fact    = fact*fact
+  write(lunout,*)'inidissip: coef u ', fact/cdivu, 1./cdivu
+  write(lunout,*)'inidissip: coef r ', fact/crot , 1./crot
+  write(lunout,*)'inidissip: coef h ', fact/cdivh, 1./cdivh
+  !     ENDIF
+
+  !-----------------------------------------------------------------------
+  !   variation verticale du coefficient de dissipation:
+  !   --------------------------------------------------
+
+  if (vert_prof_dissip == 1) then
+     do l=1,llm
+        pseudoz=8.*log(preff/presnivs(l))
+        zvert(l)=1+ &
+             (tanh((pseudoz-dissip_zref)/dissip_deltaz)+1.)/2. &
+             *(dissip_factz-1.)
+     enddo
+  else
+     DO l=1,llm
+        zvert(l)=1.
+     ENDDO
+     fact=2.
+     DO l = 1, llm
+        zz      = 1. - preff/presnivs(l)
+        zvert(l)= fact -( fact-1.)/( 1.+zz*zz )
+     ENDDO
+  endif
+
+
+  write(lunout,*)'inidissip: Constantes de temps de la diffusion horizontale'
+
+  tetamin =  1.e+6
+
+  DO l=1,llm
+     tetaudiv(l)   = zvert(l)/tetagdiv
+     tetaurot(l)   = zvert(l)/tetagrot
+     tetah(l)      = zvert(l)/tetatemp
+
+     IF( tetamin.GT. (1./tetaudiv(l)) ) tetamin = 1./ tetaudiv(l)
+     IF( tetamin.GT. (1./tetaurot(l)) ) tetamin = 1./ tetaurot(l)
+     IF( tetamin.GT. (1./   tetah(l)) ) tetamin = 1./    tetah(l)
+  ENDDO
+
+  ! If dissip_period=0 calculate value for dissipation period, else keep value read from gcm.def
+  IF (dissip_period == 0) THEN
+     dissip_period = INT( tetamin/( 2.*dtvr*iperiod) ) * iperiod
+     write(lunout,*)'inidissip: tetamin dtvr iperiod dissip_period(intermed) ',tetamin,dtvr,iperiod,dissip_period
+     dissip_period = MAX(iperiod,dissip_period)
+  END IF
+
+  dtdiss  = dissip_period * dtvr
+  write(lunout,*)'inidissip: dissip_period=',dissip_period,' dtdiss=',dtdiss,' dtvr=',dtvr
+
+  DO l = 1,llm
+     write(lunout,*)zvert(l),dtdiss*tetaudiv(l),dtdiss*tetaurot(l), &
+          dtdiss*tetah(l)
+  ENDDO
+
+END SUBROUTINE inidissip
Index: LMDZ5/branches/testing/libf/dyn3dmem/inigrads.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/inigrads.F	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dmem/inigrads.F	(revision 1707)
@@ -9,5 +9,5 @@
       implicit none
 
-      integer if,im,jm,lm,i,j,l,lnblnk
+      integer if,im,jm,lm,i,j,l
       real x(im),y(jm),z(lm),fx,fy,fz,dt
       real xmin,xmax,ymin,ymax
@@ -40,5 +40,5 @@
       ivar(if)=0
 
-      fichier(if)=file(1:lnblnk(file))
+      fichier(if)=trim(file)
 
       firsttime(if)=.true.
@@ -70,7 +70,7 @@
 
       print*,4*(ifd(if)-iid(if))*(jfd(if)-jid(if))
-      print*,file(1:lnblnk(file))//'.dat'
+      print*,trim(file)//'.dat'
 
-      OPEN (unit(if)+1,FILE=file(1:lnblnk(file))//'.dat'
+      OPEN (unit(if)+1,FILE=trim(file)//'.dat'
      s   ,FORM='unformatted',
      s   ACCESS='direct'
Index: LMDZ5/branches/testing/libf/dyn3dmem/initfluxsto_p.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/initfluxsto_p.F	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dmem/initfluxsto_p.F	(revision 1707)
@@ -1,4 +1,4 @@
 !
-! $Id: initfluxsto_p.F 1279 2009-12-10 09:02:56Z fairhead $
+! $Id$
 !
       subroutine initfluxsto_p
@@ -203,9 +203,10 @@
      .              llm, nivsigs, zvertiid)
 c pour le fichier def
-      nivd(1) = 1
-      call histvert(filedid, 'sig_s', 'Niveaux sigma',
-     .  'sigma_level',
-     .              1, nivd, dvertiid)
-
+      if (mpi_rank==0) then
+         nivd(1) = 1
+         call histvert(filedid, 'sig_s', 'Niveaux sigma',
+     .        'sigma_level',
+     .        1, nivd, dvertiid)
+      endif
 C
 C  Appels a histdef pour la definition des variables a sauvegarder
@@ -282,9 +283,9 @@
       call histend(fileid)
       call histend(filevid)
-      call histend(filedid)
+      if (mpi_rank==0) call histend(filedid)
       if (ok_sync) then
         call histsync(fileid)
         call histsync(filevid)
-        call histsync(filedid)
+        if (mpi_rank==0) call histsync(filedid)
       endif
 	
Index: LMDZ5/branches/testing/libf/dyn3dmem/integrd_loc.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/integrd_loc.F	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dmem/integrd_loc.F	(revision 1707)
@@ -4,5 +4,5 @@
       SUBROUTINE integrd_loc
      $  (  nq,vcovm1,ucovm1,tetam1,psm1,massem1,
-     $     dv,du,dteta,dq,dp,vcov,ucov,teta,q,ps0,masse,phis,finvmaold)
+     $     dv,du,dteta,dq,dp,vcov,ucov,teta,q,ps0,masse,phis) !,finvmaold)
       USE parallel
       USE control_mod
@@ -37,23 +37,32 @@
 #include "temps.h"
 #include "serre.h"
-      include 'mpif.h'
+#include "iniprint.h"
+!      include 'mpif.h'
 
 c   Arguments:
 c   ----------
 
-      INTEGER nq
-
-      REAL vcov(ijb_v:ije_v,llm),ucov(ijb_u:ije_u,llm)
-      REAL teta(ijb_u:ije_u,llm)
-      REAL q(ijb_u:ije_u,llm,nq)
-      REAL ps0(ijb_u:ije_u),masse(ijb_u:ije_u,llm),phis(ijb_u:ije_u)
-
-      REAL vcovm1(ijb_v:ije_v,llm),ucovm1(ijb_u:ije_u,llm)
-      REAL tetam1(ijb_u:ije_u,llm),psm1(ijb_u:ije_u)
-      REAL massem1(ijb_u:ije_u,llm)
-
-      REAL dv(ijb_v:ije_v,llm),du(ijb_u:ije_u,llm)
-      REAL dteta(ijb_u:ije_u,llm),dp(ijb_u:ije_u)
-      REAL dq(ijb_u:ije_u,llm,nq), finvmaold(ijb_u:ije_u,llm)
+      INTEGER,intent(in) :: nq ! number of tracers to handle in this routine
+
+      REAL,INTENT(INOUT) :: vcov(ijb_v:ije_v,llm) ! covariant meridional wind
+      REAL,INTENT(INOUT) :: ucov(ijb_u:ije_u,llm) ! covariant zonal wind
+      REAL,INTENT(INOUT) :: teta(ijb_u:ije_u,llm) ! potential temperature
+      REAL,INTENT(INOUT) :: q(ijb_u:ije_u,llm,nq) ! advected tracers
+      REAL,INTENT(INOUT) :: ps0(ijb_u:ije_u) ! surface pressure
+      REAL,INTENT(INOUT) :: masse(ijb_u:ije_u,llm) ! atmospheric mass
+      REAL,INTENT(INOUT) :: phis(ijb_u:ije_u) ! ground geopotential !!! unused
+      ! values at previous time step
+      REAL,INTENT(INOUT) :: vcovm1(ijb_v:ije_v,llm)
+      REAL,INTENT(INOUT) :: ucovm1(ijb_u:ije_u,llm)
+      REAL,INTENT(INOUT) :: tetam1(ijb_u:ije_u,llm)
+      REAL,INTENT(INOUT) :: psm1(ijb_u:ije_u)
+      REAL,INTENT(INOUT) :: massem1(ijb_u:ije_u,llm)
+      ! the tendencies to add
+      REAL,INTENT(INOUT) :: dv(ijb_v:ije_v,llm)
+      REAL,INTENT(INOUT) :: du(ijb_u:ije_u,llm)
+      REAL,INTENT(INOUT) :: dteta(ijb_u:ije_u,llm)
+      REAL,INTENT(INOUT) :: dp(ijb_u:ije_u)
+      REAL,INTENT(INOUT) :: dq(ijb_u:ije_u,llm,nq) !!! unused
+!      REAL,INTENT(INOUT) ::finvmaold(ijb_u:ije_u,llm) !!! unused
 
 c   Local:
@@ -62,9 +71,10 @@
       REAL vscr( ijb_v:ije_v ),uscr( ijb_u:ije_u )
       REAL hscr( ijb_u:ije_u ),pscr(ijb_u:ije_u)
-      REAL massescr( ijb_u:ije_u,llm ), finvmasse(ijb_u:ije_u,llm)
+      REAL massescr( ijb_u:ije_u,llm )
+!      REAL finvmasse(ijb_u:ije_u,llm)
       REAL tpn,tps,tppn(iim),tpps(iim)
       REAL qpn,qps,qppn(iim),qpps(iim)
 
-      INTEGER  l,ij,iq
+      INTEGER  l,ij,iq,i,j
 
       REAL SSUM
@@ -74,5 +84,5 @@
       LOGICAL,SAVE :: checksum_all=.TRUE.
       INTEGER :: stop_it
-      INTEGER :: ierr,j
+      INTEGER :: ierr
 
 c-----------------------------------------------------------------------
@@ -137,8 +147,14 @@
 !     &                   MPI_LOGICAL,MPI_LOR,COMM_LMDZ,ierr)
       IF( .NOT. checksum ) THEN
-         PRINT*,' Au point ij = ',stop_it, ' , pression sol neg. '
-     &         , ps(stop_it)
-         STOP' dans integrd'
-      ENDIF
+          write(lunout,*) "integrd: negative surface pressure ",
+     &                                                ps(stop_it)
+         write(lunout,*) " at node ij =", stop_it
+         ! since ij=j+(i-1)*jjp1 , we have
+!         j=modulo(stop_it,jjp1)
+!         i=1+(stop_it-j)/jjp1
+!         write(lunout,*) " lon = ",rlonv(i)*180./pi, " deg",
+!     &                   " lat = ",rlatu(j)*180./pi, " deg"
+      ENDIF
+
 c$OMP END MASTER
 c$OMP BARRIER
@@ -160,5 +176,5 @@
         call WriteField_u('int_dteta',dteta)
         call WriteField_u('int_dp',dp)
-        call WriteField_u('int_finvmaold',finvmaold)
+!        call WriteField_u('int_finvmaold',finvmaold)
         do j=1,nq
           call WriteField_u('int_q'//trim(int2str(j)),
@@ -206,18 +222,20 @@
       CALL massdair_loc (     p  , masse         )
 
-c      CALL   SCOPY( ijp1llm  , masse, 1, finvmasse,  1      )
-      ijb=ij_begin
-      ije=ij_end
-      
-c$OMP DO SCHEDULE(STATIC,OMP_CHUNK) 
-      DO  l = 1,llm
-        finvmasse(ijb:ije,l)=masse(ijb:ije,l)
-      ENDDO
-c$OMP END DO NOWAIT
-
-      jjb=jj_begin
-      jje=jj_end
-      CALL filtreg_p( finvmasse,jjb_u,jje_u,jjb,jje, jjp1, llm,
-     &                -2, 2, .TRUE., 1  )
+! Ehouarn : we don't use/need finvmaold and finvmasse,
+!           so might as well not compute them
+!c      CALL   SCOPY( ijp1llm  , masse, 1, finvmasse,  1      )
+!      ijb=ij_begin
+!      ije=ij_end
+!      
+!c$OMP DO SCHEDULE(STATIC,OMP_CHUNK) 
+!      DO  l = 1,llm
+!        finvmasse(ijb:ije,l)=masse(ijb:ije,l)
+!      ENDDO
+!c$OMP END DO NOWAIT
+
+!      jjb=jj_begin
+!      jje=jj_end
+!      CALL filtreg_p( finvmasse,jjb_u,jje_u,jjb,jje, jjp1, llm,
+!     &                -2, 2, .TRUE., 1  )
 c
 
@@ -320,5 +338,4 @@
 
           CALL qminimum_loc( q, nq, deltap )
-	 endif ! of if (planet_type.eq."earth")
 c
 c    .....  Calcul de la valeur moyenne, unique  aux poles pour  q .....
@@ -371,11 +388,15 @@
       ENDIF
       
-c         CALL  SCOPY( ijp1llm , finvmasse, 1, finvmaold, 1 )
-
-c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)
-      DO l = 1, llm      
-        finvmaold(ijb:ije,l)=finvmasse(ijb:ije,l)        
-      ENDDO
-c$OMP END DO NOWAIT
+! Ehouarn: forget about finvmaold
+!c         CALL  SCOPY( ijp1llm , finvmasse, 1, finvmaold, 1 )
+
+!c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)
+!      DO l = 1, llm      
+!        finvmaold(ijb:ije,l)=finvmasse(ijb:ije,l)        
+!      ENDDO
+!c$OMP END DO NOWAIT
+
+      endif ! of if (planet_type.eq."earth")
+
 c
 c
Index: LMDZ5/branches/testing/libf/dyn3dmem/leapfrog_loc.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/leapfrog_loc.F	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dmem/leapfrog_loc.F	(revision 1707)
@@ -1,4 +1,4 @@
 ! 
-! $Id: leapfrog_p.F 1299 2010-01-20 14:27:21Z fairhead $
+! $Id$
 !
 c
@@ -78,5 +78,5 @@
 #include "iniprint.h"
 #include "academic.h"
-      include "mpif.h"
+!      include "mpif.h"
       
       INTEGER         longcles
@@ -119,8 +119,8 @@
 
 c   tendances physiques
-!      REAL,SAVE,ALLOCATABLE :: dvfi(:,:),dufi(:,:)
-!      REAL,SAVE,ALLOCATABLE :: dtetafi(:,:)
-!      REAL,SAVE,ALLOCATABLE :: dpfi(:)
-!      REAL,DIMENSION(:,:,:),ALLOCATABLE,SAVE :: dqfi
+      REAL,SAVE,ALLOCATABLE :: dvfi(:,:),dufi(:,:)
+      REAL,SAVE,ALLOCATABLE :: dtetafi(:,:)
+      REAL,SAVE,ALLOCATABLE :: dpfi(:)
+      REAL,DIMENSION(:,:,:),ALLOCATABLE,SAVE :: dqfi
 
 c   variables pour le fichier histoire
@@ -150,4 +150,5 @@
       REAL :: secondes
 
+      logical :: physic
       LOGICAL first,callinigrads
 
@@ -174,5 +175,5 @@
 
       character*80 dynhist_file, dynhistave_file
-      character*20 modname
+      character(len=*),parameter :: modname="leapfrog_loc"
       character*80 abort_message
 
@@ -195,5 +196,4 @@
 
       INTEGER :: true_itau
-      LOGICAL :: verbose=.true.
       INTEGER :: iapptrac
       INTEGER :: AdjustCount
@@ -215,7 +215,8 @@
       itaufin   = nday*day_step
       itaufinp1 = itaufin +1
-      modname="leapfrog_p"
 
       itau = 0
+      physic=.true.
+      if (iflag_phys==0.or.iflag_phys==2) physic=.false.
       CALL init_nan
       CALL leapfrog_allocate
@@ -236,5 +237,6 @@
 
 c Allocate variables depending on dynamic variable nqtot
-!c$OMP MASTER
+!$OMP MASTER
+      if (firstcall) then
 !      
 !      ALLOCATE(p(ijb_u:ije_u,llmp1))
@@ -252,9 +254,9 @@
 !      ALLOCATE(dvdis(ijb_v:ije_v,llm),dudis(ijb_u:ije_u,llm))
 !      ALLOCATE(dtetadis(ijb_u:ije_u,llm))
-!      ALLOCATE(dvfi(ijb_v:ije_v,llm),dufi(ijb_u:ije_u,llm))
-!      ALLOCATE(dtetafi(ijb_u:ije_u,llm))
-!      ALLOCATE(dpfi(ijb_u:ije_u))
+      ALLOCATE(dvfi(ijb_v:ije_v,llm),dufi(ijb_u:ije_u,llm))
+      ALLOCATE(dtetafi(ijb_u:ije_u,llm))
+      ALLOCATE(dpfi(ijb_u:ije_u))
 !      ALLOCATE(dq(ijb_u:ije_u,llm,nqtot))
-!      ALLOCATE(dqfi(ijb_u:ije_u,llm,nqtot))
+      ALLOCATE(dqfi(ijb_u:ije_u,llm,nqtot))
 !      ALLOCATE(dqfi_tmp(iip1,llm,nqtot))
 !      ALLOCATE(finvmaold(ijb_u:ije_u,llm))
@@ -265,6 +267,7 @@
 !      ALLOCATE(vcont(ijb_v:ije_v,llm),ucont(ijb_u:ije_u,llm))
 !      ALLOCATE(vnat(ijb_v:ije_v,llm),unat(ijb_u:ije_u,llm))
-!c$OMP END MASTER      
-!c$OMP BARRIER
+      endif
+!$OMP END MASTER      
+!$OMP BARRIER
 
 !                CALL dynredem1_loc("restart.nc",0.0,
@@ -277,9 +280,12 @@
 
 c$OMP MASTER
-      dq=0.
+      dq(:,:,:)=0.
       CALL pression ( ijnb_u, ap, bp, ps, p       )
 c$OMP END MASTER
+      if (pressure_exner) then
       CALL exner_hyb_loc( ijnb_u, ps, p,alpha,beta, pks, pk, pkf)
-
+      else 
+        CALL exner_milieu_loc( ijnb_u, ps, p, beta, pks, pk, pkf )
+      endif
 c-----------------------------------------------------------------------
 c   Debut de l'integration temporelle:
@@ -287,9 +293,15 @@
 c et du parallelisme !!
 
-   1  CONTINUE
-
-      jD_cur = jD_ref + day_ini - day_ref + int (itau * dtvr / daysec) 
-      jH_cur = jH_ref +                                                 &
-     &          (itau * dtvr / daysec - int(itau * dtvr / daysec)) 
+   1  CONTINUE ! Matsuno Forward step begins here
+
+      jD_cur = jD_ref + day_ini - day_ref +                             &
+     &          itau/day_step
+      jH_cur = jH_ref + start_time +                                    &
+     &         mod(itau,day_step)/float(day_step) 
+      if (jH_cur > 1.0 ) then
+        jD_cur = jD_cur +1.
+        jH_cur = jH_cur -1.
+      endif
+
 
 #ifdef CPP_IOIPSL
@@ -323,9 +335,10 @@
          psm1= ps
          
-         finvmaold = masse
-c$OMP END MASTER
-c$OMP BARRIER
-         CALL filtreg_p ( finvmaold ,jjb_u,jje_u,jjb_u,jje_u,jjp1, llm,
-     &                    -2,2, .TRUE., 1 )
+! Ehouarn: finvmaold is actually not used       
+!         finvmaold = masse
+c$OMP END MASTER
+c$OMP BARRIER
+!         CALL filtreg_p ( finvmaold ,jjb_u,jje_u,jjb_u,jje_u,jjp1, llm,
+!     &                    -2,2, .TRUE., 1 )
        else
 ! Save fields obtained at previous time step as '...m1'
@@ -343,5 +356,5 @@
            tetam1   (ijb:ije,l) = teta  (ijb:ije,l)
            massem1  (ijb:ije,l) = masse (ijb:ije,l)
-           finvmaold(ijb:ije,l)=masse(ijb:ije,l)
+!           finvmaold(ijb:ije,l)=masse(ijb:ije,l)
                  
            if (pole_sud) ije=ij_end-iip1
@@ -353,6 +366,7 @@
 
 
-          CALL filtreg_p(finvmaold ,jjb_u,jje_u,jj_begin,jj_end,jjp1, 
-     .                    llm, -2,2, .TRUE., 1 )
+! Ehouarn: finvmaold not used
+!          CALL filtreg_p(finvmaold ,jjb_u,jje_u,jj_begin,jj_end,jjp1, 
+!     .                    llm, -2,2, .TRUE., 1 )
 
        endif ! of if (FirstCaldyn)
@@ -370,9 +384,9 @@
 cym      call minmax(ijp1llm,q(:,:,3),zqmin,zqmax)
 
-   2  CONTINUE
+   2  CONTINUE ! Matsuno backward or leapfrog step begins here
 
 c$OMP MASTER
       ItCount=ItCount+1
-      if (MOD(ItCount,1)==0) then
+      if (MOD(ItCount,1)==1) then
         debug=.true.
       else
@@ -399,12 +413,14 @@
       ! Purely Matsuno time stepping
          IF( MOD(itau,iconser) .EQ.0.AND.  forward    ) conser = .TRUE.
-         IF( MOD(itau,idissip ).EQ.0.AND..NOT.forward ) apdiss = .TRUE.
+         IF( MOD(itau,dissip_period ).EQ.0.AND..NOT.forward ) 
+     s        apdiss = .TRUE.
          IF( MOD(itau,iphysiq ).EQ.0.AND..NOT.forward 
-     s          .and. iflag_phys.EQ.1                 ) apphys = .TRUE.
+     s          .and. physic                        ) apphys = .TRUE.
       ELSE
       ! Leapfrog/Matsuno time stepping 
          IF( MOD(itau   ,iconser) .EQ. 0              ) conser = .TRUE.
-         IF( MOD(itau+1,idissip)  .EQ. 0              ) apdiss = .TRUE.
-         IF( MOD(itau+1,iphysiq).EQ.0.AND.iflag_phys.EQ.1) apphys=.TRUE.
+         IF( MOD(itau+1,dissip_period).EQ.0 .AND. .NOT. forward )
+     s        apdiss = .TRUE.
+         IF( MOD(itau+1,iphysiq).EQ.0.AND.physic) apphys=.TRUE.
       END IF
 
@@ -450,6 +466,6 @@
 c$OMP MASTER 
            call allgather_timer_average
-        verbose=.TRUE.
-        if (Verbose) then
+
+        if (prt_level > 9) then
         
         print *,'*********************************'
@@ -622,4 +638,5 @@
       call start_timer(timer_caldyn)
 
+      ! compute geopotential phi()
       CALL geopot_loc  ( ip1jmp1, teta  , pk , pks,  phis  , phi   )
 
@@ -697,6 +714,6 @@
 
        CALL integrd_loc ( 2,vcovm1,ucovm1,tetam1,psm1,massem1 ,
-     $         dv,du,dteta,dq,dp,vcov,ucov,teta,q,ps,masse,phis ,
-     $              finvmaold                                    )
+     $         dv,du,dteta,dq,dp,vcov,ucov,teta,q,ps,masse,phis)
+!     $              finvmaold                                    )
 
 !       CALL FTRACE_REGION_END("integrd")
@@ -1081,8 +1098,19 @@
 !$OMP DO SCHEDULE(STATIC,OMP_CHUNK) 
        do l=1,llm
-       teta(ijb:ije,l)=teta(ijb:ije,l)
-     &  -iphysiq*dtvr*(teta(ijb:ije,l)-tetarappel(ijb:ije,l))/taurappel
+       teta(ijb:ije,l)=teta(ijb:ije,l) -dtvr*
+     &        (teta(ijb:ije,l)-tetarappel(ijb:ije,l))*
+     &                 (knewt_g+knewt_t(l)*clat4(ijb:ije))        
        enddo
 !$OMP END DO
+
+!$OMP MASTER
+       if (planet_type.eq."giant") then
+         ! add an intrinsic heat flux at the base of the atmosphere
+         teta(ijb:ije,1) = teta(ijb:ije,1)
+     &        + dtvr * aire(ijb:ije) * ihf / cpp / masse(ijb:ije,1)
+       endif
+!$OMP END MASTER
+!$OMP BARRIER
+
 
        call Register_Hallo_u(ucov,llm,0,1,1,0,Request_Physic)
@@ -1092,6 +1120,37 @@
        call WaitRequest(Request_Physic)     
 c$OMP BARRIER
-       call friction_loc(ucov,vcov,iphysiq*dtvr)
+       call friction_loc(ucov,vcov,dtvr)
 !$OMP BARRIER
+
+        ! Sponge layer (if any)
+        IF (ok_strato) THEN
+          ! set dufi,dvfi,... to zero
+          ijb=ij_begin
+          ije=ij_end
+!$OMP DO SCHEDULE(STATIC,OMP_CHUNK)
+          do l=1,llm
+            dufi(ijb:ije,l)=0
+            dtetafi(ijb:ije,l)=0
+            dqfi(ijb:ije,l,1:nqtot)=0
+          enddo
+!$OMP END DO
+!$OMP MASTER
+          dpfi(ijb:ije)=0
+!$OMP END MASTER
+          ijb=ij_begin
+          ije=ij_end
+          if (pole_sud) ije=ije-iip1
+!$OMP DO SCHEDULE(STATIC,OMP_CHUNK)
+          do l=1,llm
+            dvfi(ijb:ije,l)=0
+          enddo
+!$OMP END DO
+
+          CALL top_bound_loc(vcov,ucov,teta,masse,dufi,dvfi,dtetafi)
+          CALL addfi_loc( dtvr, leapf, forward   ,
+     $                  ucov, vcov, teta , q   ,ps ,
+     $                 dufi, dvfi, dtetafi , dqfi ,dpfi  )
+!$OMP BARRIER
+        ENDIF ! of IF (ok_strato) 
       ENDIF ! of IF(iflag_phys.EQ.2)
 
@@ -1099,5 +1158,9 @@
         CALL pression_loc ( ip1jmp1, ap, bp, ps, p                  )
 c$OMP BARRIER
-        CALL exner_hyb_loc( ip1jmp1, ps, p,alpha,beta, pks, pk, pkf )
+        if (pressure_exner) then
+        CALL exner_hyb_loc( ijnb_u, ps, p,alpha,beta, pks, pk, pkf )
+        else 
+          CALL exner_milieu_loc( ijnb_u, ps, p, beta, pks, pk, pkf )
+        endif
 c$OMP BARRIER
 
@@ -1496,9 +1559,9 @@
 c$OMP BARRIER
 
-              if (planet_type.eq."earth") then
+!              if (planet_type.eq."earth") then
 ! Write an Earth-format restart file
                 CALL dynredem1_loc("restart.nc",0.0,
      &                           vcov,ucov,teta,q,masse,ps)
-              endif ! of if (planet_type.eq."earth")
+!              endif ! of if (planet_type.eq."earth")
 
 !              CLOSE(99)
@@ -1608,8 +1671,8 @@
 
               IF(itau.EQ.itaufin) THEN
-                if (planet_type.eq."earth") then
+!                if (planet_type.eq."earth") then
                    CALL dynredem1_loc("restart.nc",0.0,
      .                               vcov,ucov,teta,q,masse,ps)
-                endif ! of if (planet_type.eq."earth")
+!               endif ! of if (planet_type.eq."earth")
               ENDIF ! of IF(itau.EQ.itaufin)
 
Index: LMDZ5/branches/testing/libf/dyn3dmem/limit_netcdf.F90
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/limit_netcdf.F90	(revision 1669)
+++ 	(revision )
@@ -1,629 +1,0 @@
-!
-! $Id: limit_netcdf.F90 1425 2010-09-02 13:45:23Z lguez $
-!-------------------------------------------------------------------------------
-!
-SUBROUTINE limit_netcdf(interbar, extrap, oldice, masque)
-!
-!-------------------------------------------------------------------------------
-! Author : L. Fairhead, 27/01/94
-!-------------------------------------------------------------------------------
-! Purpose: Boundary conditions files building for new model using climatologies.
-!          Both grids have to be regular.
-!-------------------------------------------------------------------------------
-! Note: This routine is designed to work for Earth
-!-------------------------------------------------------------------------------
-! Modification history:
-!  * 23/03/1994: Z. X. Li
-!  *    09/1999: L. Fairhead (netcdf reading in LMDZ.3.3)
-!  *    07/2001: P. Le Van
-!  *    11/2009: L. Guez     (ozone day & night climatos, see etat0_netcdf.F90)
-!  *    12/2009: D. Cugnet   (f77->f90, calendars, files from coupled runs)
-!-------------------------------------------------------------------------------
-  USE control_mod
-#ifdef CPP_EARTH
-  USE dimphy
-  USE ioipsl,             ONLY : ioget_year_len
-  USE phys_state_var_mod, ONLY : pctsrf
-  USE netcdf,             ONLY : NF90_OPEN,    NF90_CREATE,  NF90_CLOSE,       &
-                   NF90_DEF_DIM, NF90_DEF_VAR, NF90_PUT_VAR, NF90_PUT_ATT,     &
-                   NF90_NOERR,   NF90_NOWRITE, NF90_DOUBLE,  NF90_GLOBAL,      &
-		   NF90_CLOBBER, NF90_ENDDEF,  NF90_UNLIMITED, NF90_FLOAT
-  USE inter_barxy_m, only: inter_barxy
-#endif
-  IMPLICIT NONE
-!-------------------------------------------------------------------------------
-! Arguments:
-#include "dimensions.h"
-#include "paramet.h"
-#include "iniprint.h"
-  LOGICAL,                    INTENT(IN) :: interbar ! barycentric interpolation
-  LOGICAL,                    INTENT(IN) :: extrap   ! SST extrapolation flag
-  LOGICAL,                    INTENT(IN) :: oldice   ! old way ice computation
-  REAL, DIMENSION(iip1,jjp1), INTENT(IN) :: masque   ! land mask
-#ifndef CPP_EARTH
-  WRITE(lunout,*)'limit_netcdf: Earth-specific routine, needs Earth physics'
-#else
-!-------------------------------------------------------------------------------
-! Local variables:
-#include "logic.h"
-#include "comvert.h"
-#include "comgeom2.h"
-#include "comconst.h"
-#include "indicesol.h"
-
-!--- For fractionary sub-cell use (old coding used soil index: 0,1,2,3) --------
-  LOGICAL, PARAMETER :: fracterre=.TRUE.
-
-!--- INPUT NETCDF FILES NAMES --------------------------------------------------
-  CHARACTER(LEN=25) :: icefile, sstfile, dumstr
-  CHARACTER(LEN=25), PARAMETER :: famipsst='amipbc_sst_1x1.nc        ',        &
-                                  famipsic='amipbc_sic_1x1.nc        ',        &
-                                  fclimsst='amipbc_sst_1x1_clim.nc   ',        &
-                                  fclimsic='amipbc_sic_1x1_clim.nc   ',        &
-                                  fcpldsst='cpl_atm_sst.nc           ',        &
-                                  fcpldsic='cpl_atm_sic.nc           ',        &
-                                  frugo   ='Rugos.nc                 ',        &
-                                  falbe   ='Albedo.nc                '
-
-!--- OUTPUT VARIABLES FOR NETCDF FILE ------------------------------------------
-  REAL,   DIMENSION(klon)                :: fi_ice, verif
-  REAL,   DIMENSION(:,:),   POINTER      :: phy_rug=>NULL(), phy_ice=>NULL()
-  REAL,   DIMENSION(:,:),   POINTER      :: phy_sst=>NULL(), phy_alb=>NULL()
-  REAL,   DIMENSION(:,:),   ALLOCATABLE  :: phy_bil
-  REAL,   DIMENSION(:,:,:), ALLOCATABLE  :: pctsrf_t
-  INTEGER                                :: nbad
-
-!--- VARIABLES FOR OUTPUT FILE WRITING -----------------------------------------
-  INTEGER :: ierr, nid, ndim, ntim, k
-  INTEGER, DIMENSION(2) :: dims
-  INTEGER :: id_tim,  id_SST,  id_BILS, id_RUG, id_ALB
-  INTEGER :: id_FOCE, id_FSIC, id_FTER, id_FLIC
-  INTEGER :: NF90_FORMAT
-  LOGICAL :: lCPL                    !--- T: IPCC-IPSL cpl model output files
-  INTEGER :: ndays                   !--- Depending on the output calendar
-
-!--- INITIALIZATIONS -----------------------------------------------------------
-#ifdef NC_DOUBLE
-  NF90_FORMAT=NF90_DOUBLE
-#else
-  NF90_FORMAT=NF90_FLOAT
-#endif
-
-  pi    = 4.*ATAN(1.)
-  rad   = 6371229.
-  daysec= 86400.
-  omeg  = 2.*pi/daysec
-  g     = 9.8
-  kappa = 0.2857143
-  cpp   = 1004.70885
-  dtvr  = daysec/FLOAT(day_step)
-  CALL inigeom
-
-!--- Beware: anneeref (from gcm.def) is used to determine output time sampling
-  ndays=ioget_year_len(anneeref)
-
-!--- RUGOSITY TREATMENT --------------------------------------------------------
-  WRITE(lunout,*) 'Traitement de la rugosite'
-  CALL get_2Dfield(frugo,'RUG',interbar,ndays,phy_rug,mask=masque(1:iim,:))
-
-!--- OCEAN TREATMENT -----------------------------------------------------------
-  PRINT*, 'Traitement de la glace oceanique' ; icefile=''; lCPL=.FALSE.
-
-! Input SIC file selection
-  icefile='fake'
-  IF(NF90_OPEN(famipsic,NF90_NOWRITE,nid)==NF90_NOERR) icefile=TRIM(famipsic)
-  IF(NF90_OPEN(fclimsic,NF90_NOWRITE,nid)==NF90_NOERR) icefile=TRIM(fclimsic)
-  IF(NF90_OPEN(fcpldsic,NF90_NOWRITE,nid)==NF90_NOERR) icefile=TRIM(fcpldsic)
-  SELECT CASE(icefile)
-    CASE(famipsic); dumstr='Amip.'
-    CASE(fclimsic); dumstr='Amip climatologique.'
-    CASE(fcpldsic); dumstr='de sortie du modele couplé IPSL/IPCC.';lCPL=.TRUE.
-    CASE('fake');   CALL abort_gcm('limit_netcdf','Fichier SIC non reconnu.',1)
-  END SELECT
-  ierr=NF90_CLOSE(nid)
-  WRITE(lunout,*)'Pour la glace de mer a ete choisi un fichier '//TRIM(dumstr)
-
-  CALL get_2Dfield(icefile,'SIC',interbar,ndays,phy_ice,flag=oldice,lCPL=lCPL)
-
-  ALLOCATE(pctsrf_t(klon,nbsrf,ndays))
-  DO k=1,ndays
-    fi_ice=phy_ice(:,k)
-    WHERE(fi_ice>=1.0  ) fi_ice=1.0
-    WHERE(fi_ice<EPSFRA) fi_ice=0.0
-    IF(fracterre) THEN
-      pctsrf_t(:,is_ter,k)=pctsrf(:,is_ter)       ! land soil
-      pctsrf_t(:,is_lic,k)=pctsrf(:,is_lic)       ! land ice
-      IF(lCPL) THEN                               ! SIC=pICE*(1-LIC-TER)
-        pctsrf_t(:,is_sic,k)=fi_ice*(1-pctsrf(:,is_lic)-pctsrf(:,is_ter))
-      ELSE                                        ! SIC=pICE-LIC
-        pctsrf_t(:,is_sic,k)=fi_ice-pctsrf_t(:,is_lic,k)
-      END IF
-      WHERE(pctsrf_t(:,is_sic,k)<=0) pctsrf_t(:,is_sic,k)=0.
-      WHERE(1.0-zmasq<EPSFRA)
-        pctsrf_t(:,is_sic,k)=0.0
-        pctsrf_t(:,is_oce,k)=0.0
-      ELSEWHERE
-        WHERE(pctsrf_t(:,is_sic,k)>=1.0-zmasq)
-          pctsrf_t(:,is_sic,k)=1.0-zmasq
-          pctsrf_t(:,is_oce,k)=0.0
-        ELSEWHERE
-          pctsrf_t(:,is_oce,k)=1.0-zmasq-pctsrf_t(:,is_sic,k)
-          WHERE(pctsrf_t(:,is_oce,k)<EPSFRA)
-            pctsrf_t(:,is_oce,k)=0.0
-            pctsrf_t(:,is_sic,k)=1.0-zmasq
-          END WHERE
-        END WHERE
-      END WHERE
-      nbad=COUNT(pctsrf_t(:,is_oce,k)<0.0)
-      IF(nbad>0) WRITE(lunout,*) 'pb sous maille pour nb point = ',nbad
-      nbad=COUNT(abs(sum(pctsrf_t(:,:,k),dim=2)-1.0)>EPSFRA)
-      IF(nbad>0) WRITE(lunout,*) 'pb sous surface pour nb points = ',nbad
-    ELSE 
-      pctsrf_t(:,is_ter,k)=pctsrf(:,is_ter)
-      WHERE(NINT(pctsrf(:,is_ter))==1)
-        pctsrf_t(:,is_sic,k)=0.
-        pctsrf_t(:,is_oce,k)=0.                  
-        WHERE(fi_ice>=1.e-5)
-          pctsrf_t(:,is_lic,k)=fi_ice
-          pctsrf_t(:,is_ter,k)=pctsrf_t(:,is_ter,k)-pctsrf_t(:,is_lic,k)
-        ELSEWHERE
-          pctsrf_t(:,is_lic,k)=0.0
-        END WHERE
-      ELSEWHERE
-        pctsrf_t(:,is_lic,k) = 0.0 
-        WHERE(fi_ice>=1.e-5)
-          pctsrf_t(:,is_ter,k)=0.0
-          pctsrf_t(:,is_sic,k)=fi_ice
-          pctsrf_t(:,is_oce,k)=1.0-pctsrf_t(:,is_sic,k)
-        ELSEWHERE
-          pctsrf_t(:,is_sic,k)=0.0
-          pctsrf_t(:,is_oce,k)=1.0
-        END WHERE
-      END WHERE
-      verif=sum(pctsrf_t(:,:,k),dim=2)
-      nbad=COUNT(verif<1.0-1.e-5.OR.verif>1.0+1.e-5)
-      IF(nbad>0) WRITE(lunout,*) 'pb sous maille pour nb point = ',nbad
-    END IF 
-  END DO
-  DEALLOCATE(phy_ice)
-
-!--- SST TREATMENT -------------------------------------------------------------
-  WRITE(lunout,*) 'Traitement de la sst' ; sstfile=''; lCPL=.FALSE.
-
-! Input SST file selection
-  sstfile='fake'
-  IF(NF90_OPEN(famipsst,NF90_NOWRITE,nid)==NF90_NOERR) sstfile=TRIM(famipsst)
-  IF(NF90_OPEN(fclimsst,NF90_NOWRITE,nid)==NF90_NOERR) sstfile=TRIM(fclimsst)
-  IF(NF90_OPEN(fcpldsst,NF90_NOWRITE,nid)==NF90_NOERR) sstfile=TRIM(fcpldsst)
-  SELECT CASE(icefile)
-    CASE(famipsic); dumstr='Amip.'
-    CASE(fclimsic); dumstr='Amip climatologique.'
-    CASE(fcpldsic); dumstr='de sortie du modele couplé IPSL/IPCC.';lCPL=.TRUE.
-    CASE('fake');   CALL abort_gcm('limit_netcdf','Fichier SST non reconnu',1)
-  END SELECT
-  ierr=NF90_CLOSE(nid)
-  WRITE(lunout,*)'Pour la temperature de mer a ete choisi un fichier '//TRIM(dumstr)
-
-  CALL get_2Dfield(trim(sstfile),'SST',interbar,ndays,phy_sst,flag=extrap)
-
-!--- ALBEDO TREATMENT ----------------------------------------------------------
-  WRITE(lunout,*) 'Traitement de l albedo'
-  CALL get_2Dfield(falbe,'ALB',interbar,ndays,phy_alb)
-
-!--- REFERENCE GROUND HEAT FLUX TREATMENT --------------------------------------
-  ALLOCATE(phy_bil(klon,ndays)); phy_bil=0.0
-
-!--- OUTPUT FILE WRITING -------------------------------------------------------
-  WRITE(lunout,*) 'Ecriture du fichier limit'
-
-  !--- File creation
-  ierr=NF90_CREATE("limit.nc",NF90_CLOBBER,nid)
-  ierr=NF90_PUT_ATT(nid,NF90_GLOBAL,"title","Fichier conditions aux limites")
-
-  !--- Dimensions creation
-  ierr=NF90_DEF_DIM(nid,"points_physiques",klon,ndim)
-  ierr=NF90_DEF_DIM(nid,"time",NF90_UNLIMITED,ntim)
-
-  dims=(/ndim,ntim/)
-
-  !--- Variables creation
-  ierr=NF90_DEF_VAR(nid,"TEMPS",NF90_FORMAT,(/ntim/),id_tim)
-  ierr=NF90_DEF_VAR(nid,"FOCE", NF90_FORMAT,dims,id_FOCE)
-  ierr=NF90_DEF_VAR(nid,"FSIC", NF90_FORMAT,dims,id_FSIC)
-  ierr=NF90_DEF_VAR(nid,"FTER", NF90_FORMAT,dims,id_FTER)
-  ierr=NF90_DEF_VAR(nid,"FLIC", NF90_FORMAT,dims,id_FLIC)
-  ierr=NF90_DEF_VAR(nid,"SST",  NF90_FORMAT,dims,id_SST)
-  ierr=NF90_DEF_VAR(nid,"BILS", NF90_FORMAT,dims,id_BILS)
-  ierr=NF90_DEF_VAR(nid,"ALB",  NF90_FORMAT,dims,id_ALB)
-  ierr=NF90_DEF_VAR(nid,"RUG",  NF90_FORMAT,dims,id_RUG)
-
-  !--- Attributes creation
-  ierr=NF90_PUT_ATT(nid,id_tim, "title","Jour dans l annee")
-  ierr=NF90_PUT_ATT(nid,id_FOCE,"title","Fraction ocean")
-  ierr=NF90_PUT_ATT(nid,id_FSIC,"title","Fraction glace de mer")
-  ierr=NF90_PUT_ATT(nid,id_FTER,"title","Fraction terre")
-  ierr=NF90_PUT_ATT(nid,id_FLIC,"title","Fraction land ice")
-  ierr=NF90_PUT_ATT(nid,id_SST ,"title","Temperature superficielle de la mer")
-  ierr=NF90_PUT_ATT(nid,id_BILS,"title","Reference flux de chaleur au sol")
-  ierr=NF90_PUT_ATT(nid,id_ALB, "title","Albedo a la surface")
-  ierr=NF90_PUT_ATT(nid,id_RUG, "title","Rugosite")
-
-  ierr=NF90_ENDDEF(nid)
-
-  !--- Variables saving
-  ierr=NF90_PUT_VAR(nid,id_tim,(/(REAL(k),k=1,ndays)/))
-  ierr=NF90_PUT_VAR(nid,id_FOCE,pctsrf_t(:,is_oce,:),(/1,1/),(/klon,ndays/))
-  ierr=NF90_PUT_VAR(nid,id_FSIC,pctsrf_t(:,is_sic,:),(/1,1/),(/klon,ndays/))
-  ierr=NF90_PUT_VAR(nid,id_FTER,pctsrf_t(:,is_ter,:),(/1,1/),(/klon,ndays/))
-  ierr=NF90_PUT_VAR(nid,id_FLIC,pctsrf_t(:,is_lic,:),(/1,1/),(/klon,ndays/))
-  ierr=NF90_PUT_VAR(nid,id_SST ,phy_sst(:,:),(/1,1/),(/klon,ndays/))
-  ierr=NF90_PUT_VAR(nid,id_BILS,phy_bil(:,:),(/1,1/),(/klon,ndays/))
-  ierr=NF90_PUT_VAR(nid,id_ALB ,phy_alb(:,:),(/1,1/),(/klon,ndays/))
-  ierr=NF90_PUT_VAR(nid,id_RUG ,phy_rug(:,:),(/1,1/),(/klon,ndays/))
-
-  ierr=NF90_CLOSE(nid)
-
-  DEALLOCATE(pctsrf_t,phy_sst,phy_bil,phy_alb,phy_rug)
-#endif
-! of #ifdef CPP_EARTH
-
-
-!===============================================================================
-!
-  CONTAINS
-!
-!===============================================================================
-
-
-!-------------------------------------------------------------------------------
-!
-SUBROUTINE get_2Dfield(fnam, mode, ibar, ndays, champo, flag, mask, lCPL)
-!
-!-----------------------------------------------------------------------------
-! Comments:
-!   There are two assumptions concerning the NetCDF files, that are satisfied
-!   with files that are conforming NC convention:
-!     1) The last dimension of the variables used is the time record.
-!     2) Dimensional variables have the same names as corresponding dimensions.
-!-----------------------------------------------------------------------------
-  USE netcdf, ONLY: NF90_OPEN, NF90_INQ_VARID, NF90_INQUIRE_VARIABLE, &
-       NF90_CLOSE, NF90_INQ_DIMID, NF90_INQUIRE_DIMENSION, NF90_GET_VAR, &
-       NF90_GET_ATT
-  USE dimphy, ONLY : klon
-  USE phys_state_var_mod, ONLY : pctsrf
-  USE control_mod
-  use pchsp_95_m, only: pchsp_95
-  use pchfe_95_m, only: pchfe_95
-  use arth_m, only: arth
-
-  IMPLICIT NONE
-#include "dimensions.h"
-#include "paramet.h"
-#include "comgeom2.h"
-#include "indicesol.h"
-#include "iniprint.h"
-!-----------------------------------------------------------------------------
-! Arguments:
-  CHARACTER(LEN=*),  INTENT(IN)     :: fnam     ! NetCDF file name
-  CHARACTER(LEN=3),  INTENT(IN)     :: mode     ! RUG, SIC, SST or ALB
-  LOGICAL,           INTENT(IN)     :: ibar     ! interp on pressure levels
-  INTEGER,           INTENT(IN)     :: ndays    ! current year number of days
-  REAL,    POINTER,  DIMENSION(:, :) :: champo   ! output field = f(t)
-  LOGICAL, OPTIONAL, INTENT(IN)     :: flag     ! extrapol. (SST) old ice (SIC)
-  REAL,    OPTIONAL, DIMENSION(iim, jjp1), INTENT(IN) :: mask
-  LOGICAL, OPTIONAL, INTENT(IN)     :: lCPL     ! Coupled model flag (for ICE)
-!------------------------------------------------------------------------------
-! Local variables:
-!--- NetCDF
-  INTEGER :: ncid, varid                  ! NetCDF identifiers
-  CHARACTER(LEN=30)               :: dnam       ! dimension name
-  CHARACTER(LEN=80)               :: varname    ! NetCDF variable name
-!--- dimensions
-  INTEGER,           DIMENSION(4) :: dids       ! NetCDF dimensions identifiers
-  REAL, ALLOCATABLE, DIMENSION(:) :: dlon_ini   ! initial longitudes vector
-  REAL, ALLOCATABLE, DIMENSION(:) :: dlat_ini   ! initial latitudes  vector
-  REAL, POINTER,     DIMENSION(:) :: dlon, dlat ! reordered lon/lat  vectors
-!--- fields
-  INTEGER :: imdep, jmdep, lmdep                ! dimensions of 'champ'
-  REAL, ALLOCATABLE, DIMENSION(:, :) :: champ   ! wanted field on initial grid
-  REAL, ALLOCATABLE, DIMENSION(:) :: yder, timeyear
-  REAL,              DIMENSION(iim, jjp1) :: champint   ! interpolated field
-  REAL, ALLOCATABLE, DIMENSION(:, :, :)    :: champtime
-  REAL, ALLOCATABLE, DIMENSION(:, :, :)    :: champan
-!--- input files
-  CHARACTER(LEN=20)                 :: cal_in   ! calendar
-  INTEGER                           :: ndays_in ! number of days
-!--- misc
-  INTEGER :: i, j, k, l                         ! loop counters
-  REAL, ALLOCATABLE, DIMENSION(:, :) :: work     ! used for extrapolation
-  CHARACTER(LEN=25)                 :: title    ! for messages
-  LOGICAL                           :: extrp    ! flag for extrapolation
-  REAL                              :: chmin, chmax
-  INTEGER ierr
-  integer n_extrap ! number of extrapolated points
-  logical skip
-!------------------------------------------------------------------------------
-!---Variables depending on keyword 'mode' -------------------------------------
-  NULLIFY(champo)
-  SELECT CASE(mode)
-    CASE('RUG'); varname='RUGOS';  title='Rugosite'
-    CASE('SIC'); varname='sicbcs'; title='Sea-ice'
-    CASE('SST'); varname='tosbcs'; title='SST'
-    CASE('ALB'); varname='ALBEDO'; title='Albedo'
-  END SELECT
-  extrp=.FALSE. 
-  IF ( PRESENT(flag) ) THEN 
-    IF ( flag .AND. mode=='SST' ) extrp=.TRUE. 
-  END IF
-
-!--- GETTING SOME DIMENSIONAL VARIABLES FROM FILE -----------------------------
-  ierr=NF90_OPEN(fnam, NF90_NOWRITE, ncid);             CALL ncerr(ierr, fnam)
-  ierr=NF90_INQ_VARID(ncid, varname, varid);            CALL ncerr(ierr, fnam)
-  ierr=NF90_INQUIRE_VARIABLE(ncid, varid, dimids=dids); CALL ncerr(ierr, fnam)
-
-!--- Longitude
-  ierr=NF90_INQUIRE_DIMENSION(ncid, dids(1), name=dnam, len=imdep)
-  CALL ncerr(ierr, fnam); ALLOCATE(dlon_ini(imdep), dlon(imdep))
-  ierr=NF90_INQ_VARID(ncid, dnam, varid);                CALL ncerr(ierr, fnam)
-  ierr=NF90_GET_VAR(ncid, varid, dlon_ini);              CALL ncerr(ierr, fnam)
-  WRITE(lunout, *) 'variable ', dnam, 'dimension ', imdep
-
-!--- Latitude
-  ierr=NF90_INQUIRE_DIMENSION(ncid, dids(2), name=dnam, len=jmdep)
-  CALL ncerr(ierr, fnam); ALLOCATE(dlat_ini(jmdep), dlat(jmdep))
-  ierr=NF90_INQ_VARID(ncid, dnam, varid);                CALL ncerr(ierr, fnam)
-  ierr=NF90_GET_VAR(ncid, varid, dlat_ini);              CALL ncerr(ierr, fnam)
-  WRITE(lunout, *) 'variable ', dnam, 'dimension ', jmdep
-
-!--- Time (variable is not needed - it is rebuilt - but calendar is)
-  ierr=NF90_INQUIRE_DIMENSION(ncid, dids(3), name=dnam, len=lmdep)
-  CALL ncerr(ierr, fnam); ALLOCATE(timeyear(lmdep))
-  ierr=NF90_INQ_VARID(ncid, dnam, varid);                CALL ncerr(ierr, fnam)
-  cal_in=' '
-  ierr=NF90_GET_ATT(ncid, varid, 'calendar', cal_in)
-  IF(ierr/=NF90_NOERR) THEN
-    SELECT CASE(mode)
-      CASE('RUG', 'ALB'); cal_in='360d'
-      CASE('SIC', 'SST'); cal_in='gregorian'
-    END SELECT
-    WRITE(lunout, *)'ATTENTION: variable "time" sans attribut "calendrier" ' &
-         // 'dans '//TRIM(fnam)//'. On choisit la valeur par defaut.'
-  END IF
-  WRITE(lunout, *) 'variable ', dnam, 'dimension ', lmdep, 'calendrier ', &
-       cal_in
-
-!--- CONSTRUCTING THE INPUT TIME VECTOR FOR INTERPOLATION --------------------
-  !--- Determining input file number of days, depending on calendar
-  ndays_in=year_len(anneeref, cal_in)
-
-!--- Time vector reconstruction (time vector from file is not trusted)
-!--- If input records are not monthly, time sampling has to be constant !
-  timeyear=mid_months(anneeref, cal_in, lmdep)
-  IF (lmdep /= 12) WRITE(lunout, '(a, i3, a)') 'Note : les fichiers de ' &
-       // TRIM(mode) // ' ne comportent pas 12, mais ', lmdep, &
-       ' enregistrements.'
-
-!--- GETTING THE FIELD AND INTERPOLATING IT ----------------------------------
-  ALLOCATE(champ(imdep, jmdep), champtime(iim, jjp1, lmdep))
-  IF(extrp) ALLOCATE(work(imdep, jmdep))
-
-  WRITE(lunout, *)
-  WRITE(lunout, '(a, i3, a)')'LECTURE ET INTERPOLATION HORIZ. DE ', lmdep, &
-       ' CHAMPS.'
-  ierr=NF90_INQ_VARID(ncid, varname, varid);             CALL ncerr(ierr, fnam)
-  DO l=1, lmdep
-    ierr=NF90_GET_VAR(ncid, varid, champ, (/1, 1, l/), (/imdep, jmdep, 1/))
-    CALL ncerr(ierr, fnam)
-    CALL conf_dat2d(title, imdep, jmdep, dlon_ini, dlat_ini, dlon, dlat, &
-         champ, ibar)
-
-    IF (extrp) CALL extrapol(champ, imdep, jmdep, 999999., .TRUE., .TRUE., 2, &
-         work)
-
-    IF(ibar.AND..NOT.(mode=='SIC'.AND.flag)) THEN
-      IF(l==1) THEN
-        WRITE(lunout, *)                                                      &
-  '-------------------------------------------------------------------------'
-        WRITE(lunout, *)                                                     &
-  'Utilisation de l''interpolation barycentrique pour '//TRIM(title)//' $$$'
-        WRITE(lunout, *)                                                      &
-  '-------------------------------------------------------------------------'
-      END IF
-      IF(mode=='RUG') champ=LOG(champ)
-      CALL inter_barxy(dlon, dlat(:jmdep-1), champ, rlonu(:iim),     &
-                         rlatv, champint)
-      IF(mode=='RUG') THEN
-        champint=EXP(champint)
-        WHERE(NINT(mask)/=1) champint=0.001
-      END IF
-    ELSE
-      SELECT CASE(mode)
-        CASE('RUG');       CALL rugosite(imdep, jmdep, dlon, dlat, champ,    &
-                                    iim, jjp1, rlonv, rlatu, champint, mask)
-        CASE('SIC');       CALL sea_ice (imdep, jmdep, dlon, dlat, champ,    &
-                                    iim, jjp1, rlonv, rlatu, champint)
-        CASE('SST', 'ALB'); CALL grille_m(imdep, jmdep, dlon, dlat, champ,    &
-                                    iim, jjp1, rlonv, rlatu, champint)
-      END SELECT
-    END IF
-    champtime(:, :, l)=champint
-  END DO
-  ierr=NF90_CLOSE(ncid);                                 CALL ncerr(ierr, fnam)
-
-  DEALLOCATE(dlon_ini, dlat_ini, dlon, dlat, champ)
-  IF(extrp) DEALLOCATE(work)
-
-!--- TIME INTERPOLATION ------------------------------------------------------
-  WRITE(lunout, *)
-  WRITE(lunout, *)'INTERPOLATION TEMPORELLE.'
-  WRITE(lunout, "(2x, ' Vecteur temps en entree: ', 10f6.1)") timeyear
-  WRITE(lunout, "(2x, ' Vecteur temps en sortie de 0 a ', i3)") ndays
-  ALLOCATE(yder(lmdep), champan(iip1, jjp1, ndays))
-  skip = .false.
-  n_extrap = 0
-  DO j=1, jjp1
-    DO i=1, iim
-      yder = pchsp_95(timeyear, champtime(i, j, :), ibeg=2, iend=2, &
-           vc_beg=0., vc_end=0.)
-      CALL pchfe_95(timeyear, champtime(i, j, :), yder, skip, &
-           arth(0., real(ndays_in) / ndays, ndays), champan(i, j, :), ierr)
-      if (ierr < 0) stop 1
-      n_extrap = n_extrap + ierr
-    END DO
-  END DO
-  if (n_extrap /= 0) then
-     print *, "get_2Dfield pchfe_95: n_extrap = ", n_extrap
-  end if
-  champan(iip1, :, :)=champan(1, :, :)
-  DEALLOCATE(yder, champtime, timeyear)
-
-!--- Checking the result
-  DO j=1, jjp1
-    CALL minmax(iip1, champan(1, j, 10), chmin, chmax)
-    WRITE(lunout, *)' '//TRIM(title)//' au temps 10 ', chmin, chmax, j
-  END DO
-
-!--- SPECIAL FILTER FOR SST: SST>271.38 --------------------------------------
-  IF(mode=='SST') THEN
-    WRITE(lunout, *) 'Filtrage de la SST: SST >= 271.38'
-    WHERE(champan<271.38) champan=271.38
-  END IF
-
-!--- SPECIAL FILTER FOR SIC: 0.0<SIC<1.0 -------------------------------------
-  IF(mode=='SIC') THEN
-    WRITE(lunout, *) 'Filtrage de la SIC: 0.0 < Sea-ice < 1.0'
-    IF(.NOT.lCPL) champan(:, :, :)=champan(:, :, :)/100.
-    champan(iip1, :, :)=champan(1, :, :)
-    WHERE(champan>1.0) champan=1.0
-    WHERE(champan<0.0) champan=0.0
-  END IF
-
-!--- DYNAMICAL TO PHYSICAL GRID ----------------------------------------------
-  ALLOCATE(champo(klon, ndays))
-  DO k=1, ndays
-    CALL gr_dyn_fi(1, iip1, jjp1, klon, champan(1, 1, k), champo(1, k))
-  END DO
-  DEALLOCATE(champan)
-
-END SUBROUTINE get_2Dfield
-!
-!-------------------------------------------------------------------------------
-
-
-
-!-------------------------------------------------------------------------------
-!
-FUNCTION year_len(y,cal_in)
-!
-!-------------------------------------------------------------------------------
-  USE ioipsl, ONLY : ioget_calendar,ioconf_calendar,lock_calendar,ioget_year_len
-  IMPLICIT NONE
-!-------------------------------------------------------------------------------
-! Arguments:
-  INTEGER                       :: year_len
-  INTEGER,           INTENT(IN) :: y
-  CHARACTER(LEN=*),  INTENT(IN) :: cal_in
-!-------------------------------------------------------------------------------
-! Local variables:
-  CHARACTER(LEN=20)             :: cal_out              ! calendar (for outputs)
-!-------------------------------------------------------------------------------
-!--- Getting the input calendar to reset at the end of the function
-  CALL ioget_calendar(cal_out)
-
-!--- Unlocking calendar and setting it to wanted one
-  CALL lock_calendar(.FALSE.); CALL ioconf_calendar(TRIM(cal_in))
-
-!--- Getting the number of days in this year
-  year_len=ioget_year_len(y)
-
-!--- Back to original calendar
-  CALL lock_calendar(.FALSE.); CALL ioconf_calendar(TRIM(cal_out))
-
-END FUNCTION year_len
-!
-!-------------------------------------------------------------------------------
-
-
-!-------------------------------------------------------------------------------
-!
-FUNCTION mid_months(y,cal_in,nm)
-!
-!-------------------------------------------------------------------------------
-  USE ioipsl, ONLY : ioget_calendar,ioconf_calendar,lock_calendar,ioget_mon_len
-  IMPLICIT NONE
-!-------------------------------------------------------------------------------
-! Arguments:
-  INTEGER,                INTENT(IN) :: y               ! year
-  CHARACTER(LEN=*),       INTENT(IN) :: cal_in          ! calendar
-  INTEGER,                INTENT(IN) :: nm              ! months/year number
-  REAL,    DIMENSION(nm)             :: mid_months      ! mid-month times
-!-------------------------------------------------------------------------------
-! Local variables:
-  CHARACTER(LEN=99)                  :: mess            ! error message
-  CHARACTER(LEN=20)                  :: cal_out         ! calendar (for outputs)
-  INTEGER, DIMENSION(nm)             :: mnth            ! months lengths (days)
-  INTEGER                            :: m               ! months counter
-  INTEGER                            :: nd              ! number of days
-!-------------------------------------------------------------------------------
-  nd=year_len(y,cal_in)
-
-  IF(nm==12) THEN
-
-  !--- Getting the input calendar to reset at the end of the function
-    CALL ioget_calendar(cal_out)
-
-  !--- Unlocking calendar and setting it to wanted one
-    CALL lock_calendar(.FALSE.); CALL ioconf_calendar(TRIM(cal_in))
-
-  !--- Getting the length of each month
-    DO m=1,nm; mnth(m)=ioget_mon_len(y,m); END DO
-
-  !--- Back to original calendar
-    CALL lock_calendar(.FALSE.); CALL ioconf_calendar(TRIM(cal_out))
-
-  ELSE IF(MODULO(nd,nm)/=0) THEN
-    WRITE(mess,'(a,i3,a,i3,a)')'Unconsistent calendar: ',nd,' days/year, but ',&
-      nm,' months/year. Months number should divide days number.'
-    CALL abort_gcm('mid_months',TRIM(mess),1)
-
-  ELSE
-    mnth=(/(m,m=1,nm,nd/nm)/)
-  END IF
-
-!--- Mid-months times
-  mid_months(1)=0.5*FLOAT(mnth(1))
-  DO k=2,nm
-    mid_months(k)=mid_months(k-1)+0.5*FLOAT(mnth(k-1)+mnth(k))
-  END DO
-
-END FUNCTION mid_months
-!
-!-------------------------------------------------------------------------------
-
-
-!-------------------------------------------------------------------------------
-!
-SUBROUTINE ncerr(ncres,fnam)
-!
-!-------------------------------------------------------------------------------
-! Purpose: NetCDF errors handling.
-!-------------------------------------------------------------------------------
-  USE netcdf, ONLY : NF90_NOERR, NF90_STRERROR
-  IMPLICIT NONE
-!-------------------------------------------------------------------------------
-! Arguments:
-  INTEGER,          INTENT(IN) :: ncres
-  CHARACTER(LEN=*), INTENT(IN) :: fnam
-!-------------------------------------------------------------------------------
-#include "iniprint.h"
-  IF(ncres/=NF90_NOERR) THEN
-    WRITE(lunout,*)'Problem with file '//TRIM(fnam)//' in routine limit_netcdf.'
-    CALL abort_gcm('limit_netcdf',NF90_STRERROR(ncres),1)
-  END IF
-
-END SUBROUTINE ncerr
-!
-!-------------------------------------------------------------------------------
-
-
-END SUBROUTINE limit_netcdf
Index: LMDZ5/branches/testing/libf/dyn3dmem/limy.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/limy.F	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dmem/limy.F	(revision 1707)
@@ -1,5 +1,5 @@
-!
-! $Header$
-!
+c
+c $Id$
+c
       SUBROUTINE limy(s0,sy,sm,pente_max)
 c
@@ -40,5 +40,5 @@
       REAL qbyv(ip1jm,llm)
 
-      REAL qpns,qpsn,apn,aps,dyn1,dys1,dyn2,dys2
+      REAL qpns,qpsn,appn,apps,dyn1,dys1,dyn2,dys2
       Logical extremum,first
       save first
@@ -52,5 +52,6 @@
       REAL      SSUM
       integer ismax,ismin
-      EXTERNAL  SSUM, ismin,ismax
+      EXTERNAL  SSUM, convflu,ismin,ismax
+      EXTERNAL filtreg
 
       data first/.true./
@@ -116,14 +117,14 @@
 
 c     print*,dyqv(iip1+1)
-c     apn=abs(dyq(1)/dyqv(iip1+1))
+c     appn=abs(dyq(1)/dyqv(iip1+1))
 c     print*,dyq(ip1jm+1)
 c     print*,dyqv(ip1jm-iip1+1)
-c     aps=abs(dyq(ip1jm+1)/dyqv(ip1jm-iip1+1))
+c     apps=abs(dyq(ip1jm+1)/dyqv(ip1jm-iip1+1))
 c     do ij=2,iim
-c        apn=amax1(abs(dyq(ij)/dyqv(ij)),apn)
-c        aps=amax1(abs(dyq(ip1jm+ij)/dyqv(ip1jm-iip1+ij)),aps)
+c        appn=amax1(abs(dyq(ij)/dyqv(ij)),appn)
+c        apps=amax1(abs(dyq(ip1jm+ij)/dyqv(ip1jm-iip1+ij)),apps)
 c     enddo
-c     apn=min(pente_max/apn,1.)
-c     aps=min(pente_max/aps,1.)
+c     appn=min(pente_max/appn,1.)
+c     apps=min(pente_max/apps,1.)
 
 
@@ -131,13 +132,13 @@
 
 c     if(dyqv(ismin(iim,dyqv,1))*dyqv(ismax(iim,dyqv,1)).le.0.)
-c    &   apn=0.
+c    &   appn=0.
 c     if(dyqv(ismax(iim,dyqv(ip1jm-iip1+1),1)+ip1jm-iip1+1)*
 c    &   dyqv(ismin(iim,dyqv(ip1jm-iip1+1),1)+ip1jm-iip1+1).le.0.)
-c    &   aps=0.
+c    &   apps=0.
 
 c   limitation des pentes aux poles
 c     do ij=1,iip1
-c        dyq(ij)=apn*dyq(ij)
-c        dyq(ip1jm+ij)=aps*dyq(ip1jm+ij)
+c        dyq(ij)=appn*dyq(ij)
+c        dyq(ip1jm+ij)=apps*dyq(ip1jm+ij)
 c     enddo
 
Index: LMDZ5/branches/testing/libf/dyn3dmem/logic.h
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/logic.h	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dmem/logic.h	(revision 1707)
@@ -1,21 +1,27 @@
 !
-! $Id: logic.h 1319 2010-02-23 21:29:54Z fairhead $
+! $Id$
 !
 !
-!
+! NB: keep items of different kinds in seperate common blocs to avoid
+!     "misaligned commons" issues
 !-----------------------------------------------------------------------
 ! INCLUDE 'logic.h'
 
-      COMMON/logic/ purmats,iflag_phys,forward,leapf,apphys,            &
+      COMMON/logicl/ purmats,forward,leapf,apphys,                      &
      &  statcl,conser,apdiss,apdelq,saison,ecripar,fxyhypb,ysinus       &
      &  ,read_start,ok_guide,ok_strato,ok_gradsfile                     &
-     &  ,ok_limit,ok_etat0
+     &  ,ok_limit,ok_etat0,grilles_gcm_netcdf,hybrid
 
+      COMMON/logici/ iflag_phys,iflag_trac
+      
       LOGICAL purmats,forward,leapf,apphys,statcl,conser,               &
      & apdiss,apdelq,saison,ecripar,fxyhypb,ysinus                      &
      &  ,read_start,ok_guide,ok_strato,ok_gradsfile                     &
-     &  ,ok_limit,ok_etat0
+     &  ,ok_limit,ok_etat0,grilles_gcm_netcdf
+      logical hybrid ! vertical coordinate is hybrid if true (sigma otherwise)
+                     ! (only used if disvert_type==2)
 
-      INTEGER iflag_phys
-!$OMP THREADPRIVATE(/logic/)
+      integer iflag_phys,iflag_trac
+!$OMP THREADPRIVATE(/logicl/)
+!$OMP THREADPRIVATE(/logici/)
 !-----------------------------------------------------------------------
Index: LMDZ5/branches/testing/libf/dyn3dmem/mod_const_mpi.F90
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/mod_const_mpi.F90	(revision 1707)
+++ LMDZ5/branches/testing/libf/dyn3dmem/mod_const_mpi.F90	(revision 1707)
@@ -0,0 +1,77 @@
+! 
+! $Id: mod_const_para.F90 1279 2009-12-10 09:02:56Z fairhead $
+!
+MODULE mod_const_mpi
+
+  INTEGER,SAVE :: COMM_LMDZ
+  INTEGER,SAVE :: MPI_REAL_LMDZ
+ 
+
+CONTAINS 
+
+  SUBROUTINE Init_const_mpi
+#ifdef CPP_IOIPSL
+    USE IOIPSL
+#else
+! if not using IOIPSL, we still need to use (a local version of) getin
+    USE ioipsl_getincom
+#endif
+
+    IMPLICIT NONE
+#ifdef CPP_MPI
+    INCLUDE 'mpif.h'
+#endif
+    INTEGER             :: ierr
+    INTEGER             :: comp_id
+    INTEGER             :: thread_required
+    INTEGER             :: thread_provided
+    CHARACTER(len = 6)  :: type_ocean
+
+!$OMP MASTER
+    type_ocean = 'force '
+    CALL getin('type_ocean', type_ocean)
+!$OMP END MASTER
+!$OMP BARRIER
+
+    IF (type_ocean=='couple') THEN
+#ifdef CPP_COUPLE
+!$OMP MASTER
+       CALL prism_init_comp_proto (comp_id, 'lmdz.x', ierr)
+       CALL prism_get_localcomm_proto(COMM_LMDZ,ierr)
+!$OMP END MASTER
+#endif
+#ifdef CPP_MPI
+      MPI_REAL_LMDZ=MPI_REAL8
+#endif
+    ELSE
+      CALL init_mpi
+    ENDIF
+
+  END SUBROUTINE Init_const_mpi
+  
+  SUBROUTINE Init_mpi
+  IMPLICIT NONE
+#ifdef CPP_MPI
+     INCLUDE 'mpif.h'
+#endif
+    INTEGER             :: ierr
+    INTEGER             :: thread_required
+    INTEGER             :: thread_provided
+
+#ifdef CPP_MPI
+!$OMP MASTER
+      thread_required=MPI_THREAD_SERIALIZED
+
+      CALL MPI_INIT_THREAD(thread_required,thread_provided,ierr)
+      IF (thread_provided < thread_required) THEN
+        PRINT *,'Warning : The multithreaded level of MPI librairy do not provide the requiered level',  &
+                ' in mod_const_mpi::Init_const_mpi'
+      ENDIF
+      COMM_LMDZ=MPI_COMM_WORLD
+      MPI_REAL_LMDZ=MPI_REAL8
+!$OMP END MASTER
+#endif
+
+   END SUBROUTINE Init_mpi
+    
+END MODULE mod_const_mpi
Index: LMDZ5/branches/testing/libf/dyn3dmem/mod_const_para.F90
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/mod_const_para.F90	(revision 1669)
+++ 	(revision )
@@ -1,77 +1,0 @@
-! 
-! $Id: mod_const_para.F90 1279 2009-12-10 09:02:56Z fairhead $
-!
-MODULE mod_const_mpi
-
-  INTEGER,SAVE :: COMM_LMDZ
-  INTEGER,SAVE :: MPI_REAL_LMDZ
- 
-
-CONTAINS 
-
-  SUBROUTINE Init_const_mpi
-#ifdef CPP_IOIPSL
-    USE IOIPSL
-#else
-! if not using IOIPSL, we still need to use (a local version of) getin
-    USE ioipsl_getincom
-#endif
-
-    IMPLICIT NONE
-#ifdef CPP_MPI
-    INCLUDE 'mpif.h'
-#endif
-    INTEGER             :: ierr
-    INTEGER             :: comp_id
-    INTEGER             :: thread_required
-    INTEGER             :: thread_provided
-    CHARACTER(len = 6)  :: type_ocean
-
-!$OMP MASTER
-    type_ocean = 'force '
-    CALL getin('type_ocean', type_ocean)
-!$OMP END MASTER
-!$OMP BARRIER
-
-    IF (type_ocean=='couple') THEN
-#ifdef CPP_COUPLE
-!$OMP MASTER
-       CALL prism_init_comp_proto (comp_id, 'lmdz.x', ierr)
-       CALL prism_get_localcomm_proto(COMM_LMDZ,ierr)
-!$OMP END MASTER
-#endif
-#ifdef CPP_MPI
-      MPI_REAL_LMDZ=MPI_REAL8
-#endif
-    ELSE
-      CALL init_mpi
-    ENDIF
-
-  END SUBROUTINE Init_const_mpi
-  
-  SUBROUTINE Init_mpi
-  IMPLICIT NONE
-#ifdef CPP_MPI
-     INCLUDE 'mpif.h'
-#endif
-    INTEGER             :: ierr
-    INTEGER             :: thread_required
-    INTEGER             :: thread_provided
-
-#ifdef CPP_MPI
-!$OMP MASTER
-      thread_required=MPI_THREAD_SERIALIZED
-
-      CALL MPI_INIT_THREAD(thread_required,thread_provided,ierr)
-      IF (thread_provided < thread_required) THEN
-        PRINT *,'Warning : The multithreaded level of MPI librairy do not provide the requiered level',  &
-                ' in mod_const_mpi::Init_const_mpi'
-      ENDIF
-      COMM_LMDZ=MPI_COMM_WORLD
-      MPI_REAL_LMDZ=MPI_REAL8
-!$OMP END MASTER
-#endif
-
-   END SUBROUTINE Init_mpi
-    
-END MODULE mod_const_mpi
Index: LMDZ5/branches/testing/libf/dyn3dmem/mod_filtreg_p.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/mod_filtreg_p.F	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dmem/mod_filtreg_p.F	(revision 1707)
@@ -210,24 +210,39 @@
                IF( ifiltre.EQ.-2 )   THEN
                   DO j = jdfil,jffil
-                     CALL DGEMM("N", "N", iim, nbniv_loc, iim, 1.0, 
+#ifdef BLAS
+                     CALL SGEMM("N", "N", iim, nbniv_loc, iim, 1.0, 
      &                    matrinvn(1,1,j), iim, 
      &                    champ_loc(1,j,1), iip1*(jje-jjb+1), 0.0,
      &                    champ_fft(1,j,1), iip1*(jje-jjb+1))
+#else
+                     champ_fft(:,j,:)=
+     &                    matmul(matrinvn(:,:,j),champ_loc(:iim,j,:))
+#endif
                   ENDDO
                   
                ELSE IF ( griscal )     THEN
                   DO j = jdfil,jffil
-                     CALL DGEMM("N", "N", iim, nbniv_loc, iim, 1.0, 
+#ifdef BLAS
+                     CALL SGEMM("N", "N", iim, nbniv_loc, iim, 1.0, 
      &                    matriceun(1,1,j), iim, 
      &                    champ_loc(1,j,1), iip1*(jje-jjb+1), 0.0,
      &                    champ_fft(1,j,1), iip1*(jje-jjb+1))
+#else
+                     champ_fft(:,j,:)=
+     &                    matmul(matriceun(:,:,j),champ_loc(:iim,j,:))
+#endif
                   ENDDO
                   
                ELSE 
                   DO j = jdfil,jffil
-                     CALL DGEMM("N", "N", iim, nbniv_loc, iim, 1.0, 
+#ifdef BLAS
+                     CALL SGEMM("N", "N", iim, nbniv_loc, iim, 1.0, 
      &                    matricevn(1,1,j), iim, 
      &                    champ_loc(1,j,1), iip1*(jje-jjb+1), 0.0, 
      &                    champ_fft(1,j,1), iip1*(jje-jjb+1))
+#else
+                     champ_fft(:,j,:)=
+     &                    matmul(matricevn(:,:,j),champ_loc(:iim,j,:))
+#endif
                   ENDDO
                   
@@ -238,8 +253,14 @@
                IF( ifiltre.EQ.-2 )   THEN
                   DO j = jdfil,jffil
-                     CALL DGEMM("N", "N", iim, nbniv_loc, iim, 1.0, 
+#ifdef BLAS
+                     CALL SGEMM("N", "N", iim, nbniv_loc, iim, 1.0, 
      &                    matrinvs(1,1,j-jfiltsu+1), iim, 
      &                    champ_loc(1,j,1), iip1*(jje-jjb+1), 0.0, 
      &                    champ_fft(1,j,1), iip1*(jje-jjb+1))
+#else
+                     champ_fft(:,j,:)=
+     &                    matmul(matrinvs(:,:,j-jfiltsu+1),
+     &                           champ_loc(:iim,j,:))
+#endif
                   ENDDO
                   
@@ -247,8 +268,14 @@
                   
                   DO j = jdfil,jffil
-                     CALL DGEMM("N", "N", iim, nbniv_loc, iim, 1.0, 
+#ifdef BLAS
+                     CALL SGEMM("N", "N", iim, nbniv_loc, iim, 1.0, 
      &                    matriceus(1,1,j-jfiltsu+1), iim, 
      &                    champ_loc(1,j,1), iip1*(jje-jjb+1), 0.0, 
      &                    champ_fft(1,j,1), iip1*(jje-jjb+1))
+#else
+                     champ_fft(:,j,:)=
+     &                    matmul(matriceus(:,:,j-jfiltsu+1),
+     &                           champ_loc(:iim,j,:))
+#endif
                   ENDDO
                   
@@ -256,8 +283,14 @@
                   
                   DO j = jdfil,jffil
-                     CALL DGEMM("N", "N", iim, nbniv_loc, iim, 1.0, 
+#ifdef BLAS
+                     CALL SGEMM("N", "N", iim, nbniv_loc, iim, 1.0, 
      &                    matricevs(1,1,j-jfiltsv+1), iim, 
      &                    champ_loc(1,j,1), iip1*(jje-jjb+1), 0.0, 
      &                    champ_fft(1,j,1), iip1*(jje-jjb+1))
+#else
+                     champ_fft(:,j,:)=
+     &                    matmul(matricevs(:,:,j-jfiltsv+1),
+     &                           champ_loc(:iim,j,:))
+#endif
                   ENDDO
                   
@@ -269,5 +302,5 @@
                
 c     !-------------------------------------!
-c     ! Dés-agregation des niveau verticaux !
+c     ! DÃ©s-agregation des niveau verticaux !
 c     ! uniquement necessaire pour une      !
 c     ! execution OpenMP                    !
@@ -402,2 +435,3 @@
       END SUBROUTINE filtreg_p
       END MODULE mod_filtreg_p
+
Index: LMDZ5/branches/testing/libf/dyn3dmem/mod_interface_dyn_phys.F90
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/mod_interface_dyn_phys.F90	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dmem/mod_interface_dyn_phys.F90	(revision 1707)
@@ -1,4 +1,4 @@
 ! 
-! $Id: mod_interface_dyn_phys.F90 1279 2009-12-10 09:02:56Z fairhead $
+! $Id$
 !
 MODULE mod_interface_dyn_phys
@@ -7,7 +7,6 @@
   
   
-#ifdef CPP_EARTH
+#ifdef CPP_PHYS
 ! Interface with parallel physics,
-! for now this routine only works with Earth physics
 CONTAINS
   
@@ -56,4 +55,4 @@
   END SUBROUTINE Init_interface_dyn_phys 
 #endif
-! of #ifdef CPP_EARTH
+! of #ifdef CPP_PHYS
 END MODULE mod_interface_dyn_phys
Index: LMDZ5/branches/testing/libf/dyn3dmem/parallel.F90
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/parallel.F90	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dmem/parallel.F90	(revision 1707)
@@ -1,4 +1,4 @@
 ! 
-! $Id: parallel.F90 1279 2009-12-10 09:02:56Z fairhead $
+! $Id$
 !
   module parallel
@@ -94,5 +94,7 @@
       integer, dimension(3) :: blocklen,type
       integer :: comp_id
-
+      character(len=4)  :: num
+      character(len=20) :: filename
+ 
 #ifdef CPP_OMP    
       INTEGER :: OMP_GET_NUM_THREADS
@@ -126,5 +128,16 @@
         mpi_rank=0
       ENDIF
-  
+
+
+! Open text output file with mpi_rank in suffix of file name 
+      IF (lunout /= 5 .and. lunout /= 6) THEN
+         WRITE(num,'(I4.4)') mpi_rank
+         filename='lmdz.out_'//num
+         IF (mpi_rank .NE. 0) THEN
+            OPEN(UNIT=lunout,FILE=TRIM(filename),ACTION='write', &
+               STATUS='unknown',FORM='formatted',IOSTAT=ierr) 
+         ENDIF
+      ENDIF
+
       
       allocate(jj_begin_para(0:mpi_size-1))
@@ -376,7 +389,8 @@
       integer :: ierr
       integer :: i
-      deallocate(jj_begin_para)
-      deallocate(jj_end_para)
-      deallocate(jj_nb_para)
+
+      if (allocated(jj_begin_para)) deallocate(jj_begin_para)
+      if (allocated(jj_end_para))   deallocate(jj_end_para)
+      if (allocated(jj_nb_para))    deallocate(jj_nb_para)
 
       if (type_ocean == 'couple') then
@@ -643,5 +657,10 @@
           enddo
           
-        endif
+        else
+          ! Ehouarn: When in debug mode, ifort complains (for call MPI_GATHERV
+          !          below) about Buffer_Recv() being not allocated.
+          !          So make a dummy allocation.
+          allocate(Buffer_Recv(1))
+        endif ! of if (MPI_Rank==rank)
   
 !$OMP CRITICAL (MPI)
@@ -717,23 +736,22 @@
         
    
-    /*  
-  Subroutine verif_hallo(Field,ij,ll,up,down)
-    implicit none
-#include "dimensions.h"
-#include "paramet.h"    
-    include 'mpif.h'
-    
-      INTEGER :: ij,ll
-      REAL, dimension(ij,ll) :: Field
-      INTEGER :: up,down 
-      
-      REAL,dimension(ij,ll): NewField
-      
-      NewField=0
-      
-      ijb=ij_begin
-      ije=ij_end
-      if (pole_nord) 
-      NewField(ij_be       
-*/
+!  Subroutine verif_hallo(Field,ij,ll,up,down)
+!    implicit none
+!#include "dimensions.h"
+!#include "paramet.h"    
+!    include 'mpif.h'
+!    
+!      INTEGER :: ij,ll
+!      REAL, dimension(ij,ll) :: Field
+!      INTEGER :: up,down 
+!      
+!      REAL,dimension(ij,ll): NewField
+!      
+!      NewField=0
+!      
+!      ijb=ij_begin
+!      ije=ij_end
+!      if (pole_nord) 
+!      NewField(ij_be       
+
   end module parallel
Index: LMDZ5/branches/testing/libf/dyn3dmem/paramet.h
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/paramet.h	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dmem/paramet.h	(revision 1707)
@@ -1,4 +1,4 @@
 !
-! $Header$
+! $Id$
 !
 !
Index: LMDZ5/branches/testing/libf/dyn3dmem/temps.h
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/temps.h	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dmem/temps.h	(revision 1707)
@@ -1,4 +1,4 @@
 !
-! $Id: temps.h 1279 2009-12-10 09:02:56Z fairhead $
+! $Id$
 !
 !  ATTENTION!!!!: ce fichier include est compatible format fixe/format libre
@@ -14,10 +14,12 @@
 
       COMMON/temps/itaufin, dt, day_ini, day_end, annee_ref, day_ref,   &
-     &             itau_dyn, itau_phy, jD_ref, jH_ref, calend
+     &             itau_dyn, itau_phy, jD_ref, jH_ref, calend,          &
+     &             start_time
+
 
       INTEGER   itaufin
       INTEGER itau_dyn, itau_phy
       INTEGER day_ini, day_end, annee_ref, day_ref
-      REAL      dt, jD_ref, jH_ref
+      REAL      dt, jD_ref, jH_ref, start_time
       CHARACTER (len=10) :: calend
 
Index: LMDZ5/branches/testing/libf/dyn3dmem/ugeostr.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/ugeostr.F	(revision 1669)
+++ 	(revision )
@@ -1,69 +1,0 @@
-!
-! $Id: ugeostr.F 1403 2010-07-01 09:02:53Z fairhead $
-!
-      subroutine ugeostr(phi,ucov)
-
-
-c  Calcul du vent covariant geostrophique a partir du champs de
-c  geopotentiel en supposant que le vent au sol est nul.
-
-      implicit none
-
-#include "dimensions.h"
-#include "paramet.h"
-#include "comconst.h"
-#include "comgeom2.h"
-
-      real ucov(iip1,jjp1,llm),phi(iip1,jjp1,llm)
-      real um(jjm,llm),fact,u(iip1,jjm,llm)
-      integer i,j,l
-
-      real zlat
-
-      um(:,:)=0 ! initialize um()
-
-      DO j=1,jjm
-
-         if (abs(sin(rlatv(j))).lt.1.e-4) then
-             zlat=1.e-4
-         else
-             zlat=rlatv(j)
-         endif
-         fact=cos(zlat)
-         fact=fact*fact
-         fact=fact*fact
-         fact=fact*fact
-         fact=(1.-fact)/
-     s    (2.*omeg*sin(zlat)*(rlatu(j+1)-rlatu(j)))
-         fact=-fact/rad
-         DO l=1,llm
-            DO i=1,iim
-               u(i,j,l)=fact*(phi(i,j+1,l)-phi(i,j,l))
-               um(j,l)=um(j,l)+u(i,j,l)/REAL(iim)
-            ENDDO
-         ENDDO
-      ENDDO
-      call dump2d(jjm,llm,um,'Vent-u geostrophique')
-
-c
-c-----------------------------------------------------------------------
-c   calcul des champ de vent:
-c   -------------------------
-
-      DO 301 l=1,llm
-         DO 302 i=1,iip1
-            ucov(i,1,l)=0.
-            ucov(i,jjp1,l)=0.
-302      CONTINUE
-         DO 304 j=2,jjm
-            DO 305 i=1,iim
-               ucov(i,j,l) = 0.5*(u(i,j,l)+u(i,j-1,l))*cu(i,j)
-305         CONTINUE
-            ucov(iip1,j,l)=ucov(1,j,l)
-304      CONTINUE
-301   CONTINUE
-
-      print*,301
-
-      return
-      end
Index: LMDZ5/branches/testing/libf/dyn3dmem/ugeostr.F90
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/ugeostr.F90	(revision 1707)
+++ LMDZ5/branches/testing/libf/dyn3dmem/ugeostr.F90	(revision 1707)
@@ -0,0 +1,68 @@
+!
+! $Id: ugeostr.F90 1492 2011-03-08 08:10:25Z fairhead $
+!
+subroutine ugeostr(phi,ucov)
+
+  ! Calcul du vent covariant geostrophique a partir du champ de
+  ! geopotentiel.
+  ! We actually compute: (1 - cos^8 \phi) u_g
+  ! to have a wind going smoothly to 0 at the equator.
+  ! We assume that the surface pressure is uniform so that model
+  ! levels are pressure levels.
+
+  implicit none
+
+  include "dimensions.h"
+  include "paramet.h"
+  include "comconst.h"
+  include "comgeom2.h"
+
+  real ucov(iip1,jjp1,llm),phi(iip1,jjp1,llm)
+  real um(jjm,llm),fact,u(iip1,jjm,llm)
+  integer i,j,l
+
+  real zlat
+
+  um(:,:)=0 ! initialize um()
+
+  DO j=1,jjm
+
+     if (abs(sin(rlatv(j))).lt.1.e-4) then
+        zlat=1.e-4
+     else
+        zlat=rlatv(j)
+     endif
+     fact=cos(zlat)
+     fact=fact*fact
+     fact=fact*fact
+     fact=fact*fact
+     fact=(1.-fact)/ &
+          (2.*omeg*sin(zlat)*(rlatu(j+1)-rlatu(j)))
+     fact=-fact/rad
+     DO l=1,llm
+        DO i=1,iim
+           u(i,j,l)=fact*(phi(i,j+1,l)-phi(i,j,l))
+           um(j,l)=um(j,l)+u(i,j,l)/REAL(iim)
+        ENDDO
+     ENDDO
+  ENDDO
+  call dump2d(jjm,llm,um,'Vent-u geostrophique')
+
+  !   calcul des champ de vent:
+
+  DO l=1,llm
+     DO i=1,iip1
+        ucov(i,1,l)=0.
+        ucov(i,jjp1,l)=0.
+     end DO
+     DO  j=2,jjm
+        DO  i=1,iim
+           ucov(i,j,l) = 0.5*(u(i,j,l)+u(i,j-1,l))*cu(i,j)
+        end DO
+        ucov(iip1,j,l)=ucov(1,j,l)
+     end DO
+  end DO
+
+  print *, 301
+
+end subroutine ugeostr
Index: LMDZ5/branches/testing/libf/dyn3dmem/vlsplt_loc.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/vlsplt_loc.F	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dmem/vlsplt_loc.F	(revision 1707)
@@ -1,2 +1,5 @@
+!
+! $Id$
+!
       SUBROUTINE vlx_loc(q,pente_max,masse,u_m,ijb_x,ije_x)
 
@@ -372,5 +375,5 @@
       REAL qbyv(ijb_v:ije_v,llm)
 
-      REAL qpns,qpsn,apn,aps,dyn1,dys1,dyn2,dys2,newmasse,fn,fs
+      REAL qpns,qpsn,appn,apps,dyn1,dys1,dyn2,dys2,newmasse,fn,fs
 c     REAL newq,oldmasse
       Logical extremum,first,testcpu
@@ -543,14 +546,14 @@
 C     PRINT*,dyq(1)
 C     PRINT*,dyqv(iip1+1)
-C     apn=abs(dyq(1)/dyqv(iip1+1))
+C     appn=abs(dyq(1)/dyqv(iip1+1))
 C     PRINT*,dyq(ip1jm+1)
 C     PRINT*,dyqv(ip1jm-iip1+1)
-C     aps=abs(dyq(ip1jm+1)/dyqv(ip1jm-iip1+1))
+C     apps=abs(dyq(ip1jm+1)/dyqv(ip1jm-iip1+1))
 C     DO ij=2,iim
-C        apn=amax1(abs(dyq(ij)/dyqv(ij)),apn)
-C        aps=amax1(abs(dyq(ip1jm+ij)/dyqv(ip1jm-iip1+ij)),aps)
+C        appn=amax1(abs(dyq(ij)/dyqv(ij)),appn)
+C        apps=amax1(abs(dyq(ip1jm+ij)/dyqv(ip1jm-iip1+ij)),apps)
 C     ENDDO
-C     apn=min(pente_max/apn,1.)
-C     aps=min(pente_max/aps,1.)
+C     appn=min(pente_max/appn,1.)
+C     apps=min(pente_max/apps,1.)
 C
 C
@@ -558,13 +561,13 @@
 C
 C     IF(dyqv(ismin(iim,dyqv,1))*dyqv(ismax(iim,dyqv,1)).le.0.)
-C    &   apn=0.
+C    &   appn=0.
 C     IF(dyqv(ismax(iim,dyqv(ip1jm-iip1+1),1)+ip1jm-iip1+1)*
 C    &   dyqv(ismin(iim,dyqv(ip1jm-iip1+1),1)+ip1jm-iip1+1).le.0.)
-C    &   aps=0.
+C    &   apps=0.
 C
 C   limitation des pentes aux poles
 C     DO ij=1,iip1
-C        dyq(ij)=apn*dyq(ij)
-C        dyq(ip1jm+ij)=aps*dyq(ip1jm+ij)
+C        dyq(ij)=appn*dyq(ij)
+C        dyq(ip1jm+ij)=apps*dyq(ip1jm+ij)
 C     ENDDO
 C
Index: LMDZ5/branches/testing/libf/dyn3dmem/vlspltqs_loc.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/vlspltqs_loc.F	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dmem/vlspltqs_loc.F	(revision 1707)
@@ -549,14 +549,14 @@
 C     PRINT*,dyq(1)
 C     PRINT*,dyqv(iip1+1)
-C     apn=abs(dyq(1)/dyqv(iip1+1))
+C     appn=abs(dyq(1)/dyqv(iip1+1))
 C     PRINT*,dyq(ip1jm+1)
 C     PRINT*,dyqv(ip1jm-iip1+1)
-C     aps=abs(dyq(ip1jm+1)/dyqv(ip1jm-iip1+1))
+C     apps=abs(dyq(ip1jm+1)/dyqv(ip1jm-iip1+1))
 C     DO ij=2,iim
-C        apn=amax1(abs(dyq(ij)/dyqv(ij)),apn)
-C        aps=amax1(abs(dyq(ip1jm+ij)/dyqv(ip1jm-iip1+ij)),aps)
+C        appn=amax1(abs(dyq(ij)/dyqv(ij)),appn)
+C        apps=amax1(abs(dyq(ip1jm+ij)/dyqv(ip1jm-iip1+ij)),apps)
 C     ENDDO
-C     apn=min(pente_max/apn,1.)
-C     aps=min(pente_max/aps,1.)
+C     appn=min(pente_max/appn,1.)
+C     apps=min(pente_max/apps,1.)
 C
 C
@@ -564,13 +564,13 @@
 C
 C     IF(dyqv(ismin(iim,dyqv,1))*dyqv(ismax(iim,dyqv,1)).le.0.)
-C    &   apn=0.
+C    &   appn=0.
 C     IF(dyqv(ismax(iim,dyqv(ip1jm-iip1+1),1)+ip1jm-iip1+1)*
 C    &   dyqv(ismin(iim,dyqv(ip1jm-iip1+1),1)+ip1jm-iip1+1).le.0.)
-C    &   aps=0.
+C    &   apps=0.
 C
 C   limitation des pentes aux poles
 C     DO ij=1,iip1
-C        dyq(ij)=apn*dyq(ij)
-C        dyq(ip1jm+ij)=aps*dyq(ip1jm+ij)
+C        dyq(ij)=appn*dyq(ij)
+C        dyq(ip1jm+ij)=apps*dyq(ip1jm+ij)
 C     ENDDO
 C
Index: LMDZ5/branches/testing/libf/dyn3dmem/wrgrads.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/wrgrads.F	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dmem/wrgrads.F	(revision 1707)
@@ -22,5 +22,5 @@
 c   local
 
-      integer im,jm,lm,i,j,l,lnblnk,iv,iii,iji,iif,ijf
+      integer im,jm,lm,i,j,l,iv,iii,iji,iif,ijf
 
       logical writectl
@@ -55,5 +55,5 @@
             nvar(if)=ivar(if)
             var(ivar(if),if)=name
-            tvar(ivar(if),if)=titlevar(1:lnblnk(titlevar))
+            tvar(ivar(if),if)=trim(titlevar)
             nld(ivar(if),if)=nl
             print*,'initialisation ecriture de ',var(ivar(if),if)
@@ -96,8 +96,8 @@
       file=fichier(if)
 c   WARNING! on reecrase le fichier .ctl a chaque ecriture
-      open(unit(if),file=file(1:lnblnk(file))//'.ctl'
+      open(unit(if),file=trim(file)//'.ctl'
      &         ,form='formatted',status='unknown')
       write(unit(if),'(a5,1x,a40)')
-     &       'DSET ','^'//file(1:lnblnk(file))//'.dat'
+     &       'DSET ','^'//trim(file)//'.dat'
 
       write(unit(if),'(a12)') 'UNDEF 1.0E30'
Index: LMDZ5/branches/testing/libf/dyn3dpar/calfis_p.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dpar/calfis_p.F	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dpar/calfis_p.F	(revision 1707)
@@ -684,5 +684,5 @@
      .             debut_split,    !! firstcall 
      .             lafin_split,    !! lastcall
-     .             float(day_ini), !! pday <-- day_ini (dans temps.h)
+     .             jD_cur,         !! pday. see leapfrog_p 
      .             jH_cur_split,   !! ptime "fraction of day"
      .             zdt_split,      !! ptimestep
Index: LMDZ5/branches/testing/libf/dyn3dpar/comconst.h
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dpar/comconst.h	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dpar/comconst.h	(revision 1707)
@@ -21,6 +21,7 @@
       REAL dtdiss ! (s) time step for the dissipation
       REAL rad ! (m) radius of the planet
-      REAL r ! Gas constant R=8.31 J.K-1.mol-1
-      REAL cpp   ! Cp
+      REAL r ! Reduced Gas constant r=R/mu
+             ! with R=8.31.. J.K-1.mol-1, mu: mol mass of atmosphere (kg/mol)
+      REAL cpp   ! Specific heat Cp (J.kg-1.K-1)
       REAL kappa ! kappa=R/Cp 
       REAL cotot
Index: LMDZ5/branches/testing/libf/dyn3dpar/comdissnew.h
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dpar/comdissnew.h	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dpar/comdissnew.h	(revision 1707)
@@ -12,8 +12,14 @@
 
       COMMON/comdissnew/ lstardis,nitergdiv,nitergrot,niterh,tetagdiv,  &
-     &                   tetagrot,tetatemp,coefdis 
+     &                   tetagrot,tetatemp,coefdis, vert_prof_dissip
 
       LOGICAL lstardis
       INTEGER nitergdiv, nitergrot, niterh
+
+      integer vert_prof_dissip ! vertical profile of horizontal dissipation
+!     Allowed values:
+!     0: rational fraction, function of pressure
+!     1: tanh of altitude
+
       REAL     tetagdiv, tetagrot,  tetatemp, coefdis
 
Index: LMDZ5/branches/testing/libf/dyn3dpar/conf_gcm.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dpar/conf_gcm.F	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dpar/conf_gcm.F	(revision 1707)
@@ -6,4 +6,5 @@
       SUBROUTINE conf_gcm( tapedef, etatinit, clesphy0 )
 c
+      USE control_mod
 #ifdef CPP_IOIPSL
       use IOIPSL
@@ -16,6 +17,7 @@
       use mod_hallo, ONLY : use_mpi_alloc
       use parallel, ONLY : omp_chunk
-      USE control_mod
       USE infotrac, ONLY : type_trac
+      use assert_m, only: assert
+
       IMPLICIT NONE
 c-----------------------------------------------------------------------
@@ -43,10 +45,10 @@
 #include "serre.h"
 #include "comdissnew.h"
-!#include "clesphys.h"
-#include "iniprint.h"
 #include "temps.h"
 #include "comconst.h"
 
 ! FH 2008/05/09 On elimine toutes les clefs physiques dans la dynamique
+! #include "clesphys.h"
+#include "iniprint.h"
 c
 c
@@ -105,5 +107,4 @@
         OPEN(UNIT=lunout,FILE='lmdz.out_0000',ACTION='write', 
      &          STATUS='unknown',FORM='formatted')
-
       ENDIF
 
@@ -185,8 +186,4 @@
 
 !Config  Key  = nsplit_phys
-!Config  Desc = nombre d'iteration de la physique
-!Config  Def  = 240 
-!Config  Help = nombre d'itration de la physique
-!
        nsplit_phys = 1 
        CALL getin('nsplit_phys',nsplit_phys)
@@ -325,5 +322,4 @@
        CALL getin('tau_top_bound',tau_top_bound)
 
-!
 !Config  Key  = coefdis
 !Config  Desc = coefficient pour gamdissip
@@ -608,5 +604,4 @@
       type_trac = 'lmdz'
       CALL getin('type_trac',type_trac)
-
 
 !Config  Key  = config_inca
@@ -830,5 +825,5 @@
 
 !Config  Key  = ok_dynzon 
-!Config  Desc = calcul et sortie des transports 
+!Config  Desc = sortie des transports zonaux dans la dynamique
 !Config  Def  = n 
 !Config  Help = Permet de mettre en route le calcul des transports 
@@ -865,5 +860,5 @@
         write(lunout,*)"Le zoom en longitude est incompatible",
      &                 " avec l'utilisation du filtre FFT ",
-     &                 "---> filtre FFT dÃ©sactivÃ© "
+     &                 "---> FFT filter not active"
        use_filtre_fft=.FALSE.
       ENDIF
@@ -898,4 +893,9 @@
       ok_strato=.FALSE.
       CALL getin('ok_strato',ok_strato)
+
+      vert_prof_dissip = merge(1, 0, ok_strato .and. llm==39)
+      CALL getin('vert_prof_dissip', vert_prof_dissip)
+      call assert(vert_prof_dissip == 0 .or. vert_prof_dissip ==  1,
+     $     "bad value for vert_prof_dissip")
 
 !Config  Key  = ok_gradsfile
@@ -968,5 +968,5 @@
       write(lunout,*)' type_trac = ', type_trac
       write(lunout,*)' config_inca = ', config_inca
-      write(lunout,*)' ok_dynzon = ', ok_dynzon 
+      write(lunout,*)' ok_dynzon = ', ok_dynzon
       write(lunout,*)' ok_dyn_ins = ', ok_dyn_ins 
       write(lunout,*)' ok_dyn_ave = ', ok_dyn_ave 
Index: LMDZ5/branches/testing/libf/dyn3dpar/etat0_netcdf.F90
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dpar/etat0_netcdf.F90	(revision 1669)
+++ 	(revision )
@@ -1,530 +1,0 @@
-!
-! $Id$
-!
-!-------------------------------------------------------------------------------
-!
-SUBROUTINE etat0_netcdf(ib, masque, phis, letat0)
-!
-!-------------------------------------------------------------------------------
-! Purpose: Creates initial states
-!-------------------------------------------------------------------------------
-! Note: This routine is designed to work for Earth
-!-------------------------------------------------------------------------------
-  USE control_mod
-#ifdef CPP_EARTH
-  USE startvar
-  USE ioipsl
-  USE dimphy
-  USE infotrac
-  USE fonte_neige_mod
-  USE pbl_surface_mod
-  USE phys_state_var_mod
-  USE filtreg_mod
-  USE regr_lat_time_climoz_m, ONLY: regr_lat_time_climoz
-  USE conf_phys_m,            ONLY: conf_phys
-! For parameterization of ozone chemistry:
-  use regr_lat_time_coefoz_m, only: regr_lat_time_coefoz
-  use press_coefoz_m, only: press_coefoz
-  use regr_pr_o3_m, only: regr_pr_o3
-  USE netcdf, ONLY : NF90_OPEN, NF90_NOWRITE, NF90_CLOSE, NF90_NOERR
-#endif
-  IMPLICIT NONE
-!-------------------------------------------------------------------------------
-! Arguments:
-#include "dimensions.h"
-#include "paramet.h"
-#include "iniprint.h"
-  LOGICAL,                    INTENT(IN)    :: ib     ! barycentric interpolat.
-  REAL, DIMENSION(iip1,jjp1), INTENT(INOUT) :: masque ! land mask
-  REAL, DIMENSION(iip1,jjp1), INTENT(OUT)   :: phis   ! geopotentiel au sol
-  LOGICAL,                    INTENT(IN)    :: letat0 ! F: masque only required
-#ifndef CPP_EARTH
-  WRITE(lunout,*)'limit_netcdf: Earth-specific routine, needs Earth physics'
-#else
-!-------------------------------------------------------------------------------
-! Local variables:
-#include "comgeom2.h"
-#include "comvert.h"
-#include "comconst.h"
-#include "indicesol.h"
-#include "dimsoil.h"
-#include "temps.h"
-  REAL,    DIMENSION(klon)                 :: tsol, qsol
-  REAL,    DIMENSION(klon)                 :: sn, rugmer, run_off_lic_0
-  REAL,    DIMENSION(iip1,jjp1)            :: orog, rugo, psol
-  REAL,    DIMENSION(iip1,jjp1,llm+1)      :: p3d
-  REAL,    DIMENSION(iip1,jjp1,llm)        :: uvent, t3d, tpot, qsat, qd
-  REAL,    DIMENSION(iip1,jjm ,llm)        :: vvent
-  REAL,    DIMENSION(:,:,:,:), ALLOCATABLE :: q3d
-  REAL,    DIMENSION(klon,nbsrf)           :: qsolsrf, snsrf, evap
-  REAL,    DIMENSION(klon,nbsrf)           :: frugs, agesno
-  REAL,    DIMENSION(klon,nsoilmx,nbsrf)   :: tsoil
-
-!--- Local variables for sea-ice reading:
-  INTEGER                                  :: iml_lic, jml_lic, llm_tmp
-  INTEGER                                  :: ttm_tmp, iret, fid
-  INTEGER, DIMENSION(1)                    :: itaul
-  REAL,    DIMENSION(1)                    :: lev
-  REAL                                     :: date
-  REAL,    DIMENSION(:,:),   ALLOCATABLE   ::  lon_lic,  lat_lic, fraclic
-  REAL,    DIMENSION(:),     ALLOCATABLE   :: dlon_lic, dlat_lic
-  REAL,    DIMENSION(iip1,jjp1)            :: flic_tmp
-
-!--- Misc
-  CHARACTER(LEN=80)                        :: x, fmt
-  INTEGER                                  :: i, j, l, ji
-  REAL,    DIMENSION(iip1,jjp1,llm)        :: alpha, beta, pk, pls, y
-  REAL,    DIMENSION(ip1jmp1)              :: pks
-
-#include "comdissnew.h"
-#include "serre.h"
-#include "clesphys.h"
-
-  REAL,    DIMENSION(iip1,jjp1,llm)        :: masse
-  INTEGER :: itau, iday
-  REAL    :: xpn, xps, time, phystep
-  REAL,    DIMENSION(iim)                  :: xppn, xpps
-  REAL,    DIMENSION(ip1jmp1,llm)          :: pbaru, phi, w
-  REAL,    DIMENSION(ip1jm  ,llm)          :: pbarv
-  REAL,    DIMENSION(klon)                 :: fder
-
-!--- Local variables for ocean mask reading:
-  INTEGER :: nid_o2a, iml_omask, jml_omask
-  LOGICAL :: couple=.FALSE.
-  REAL,    DIMENSION(:,:), ALLOCATABLE ::  lon_omask, lat_omask, ocemask, ocetmp
-  REAL,    DIMENSION(:),   ALLOCATABLE :: dlon_omask,dlat_omask
-  REAL,    DIMENSION(klon)             :: ocemask_fi
-  INTEGER, DIMENSION(klon-2)           :: isst
-  REAL,    DIMENSION(iim,jjp1)         :: zx_tmp_2d
-  REAL    :: dummy
-  LOGICAL :: ok_newmicro, ok_journe, ok_mensuel, ok_instan, ok_hf
-  LOGICAL :: ok_LES, ok_ade, ok_aie, aerosol_couple, new_aod, callstats
-  INTEGER :: iflag_radia, flag_aerosol
-  REAL    :: bl95_b0, bl95_b1, fact_cldcon, facttemps, ratqsbas, ratqshaut
-  REAL    :: tau_ratqs
-  INTEGER :: iflag_cldcon, iflag_ratqs, iflag_coupl, iflag_clos, iflag_wake
-  INTEGER :: iflag_thermals, nsplit_thermals
-  INTEGER :: iflag_thermals_ed, iflag_thermals_optflux
-  REAL    :: tau_thermals, solarlong0,  seuil_inversion
-  INTEGER :: read_climoz ! read ozone climatology
-!  Allowed values are 0, 1 and 2
-!     0: do not read an ozone climatology
-!     1: read a single ozone climatology that will be used day and night
-!     2: read two ozone climatologies, the average day and night
-!     climatology and the daylight climatology
-!-------------------------------------------------------------------------------
-  REAL    :: alp_offset
-  logical found
-
-!--- Constants
-  pi     = 4. * ATAN(1.)
-  rad    = 6371229.
-  daysec = 86400.
-  omeg   = 2.*pi/daysec
-  g      = 9.8
-  kappa  = 0.2857143
-  cpp    = 1004.70885
-  preff  = 101325.
-  pa     = 50000.
-  jmp1   = jjm + 1
-
-!--- CONSTRUCT A GRID
-  CALL conf_phys(  ok_journe, ok_mensuel, ok_instan, ok_hf, ok_LES,     &
-                   callstats,                                           &
-                   solarlong0,seuil_inversion,                          &
-                   fact_cldcon, facttemps,ok_newmicro,iflag_radia,      &
-                   iflag_cldcon,                                        &
-                   iflag_ratqs,ratqsbas,ratqshaut,tau_ratqs,            &
-                   ok_ade, ok_aie, aerosol_couple,                      &
-                   flag_aerosol, new_aod,                               &
-                   bl95_b0, bl95_b1,                                    &
-                   read_climoz,                                         &
-                   alp_offset)
-
-! co2_ppm0 : initial value of atmospheric CO2 from .def file (co2_ppm value)
-  co2_ppm0 = co2_ppm
-
-  dtvr   = daysec/FLOAT(day_step)
-  WRITE(lunout,*)'dtvr',dtvr
-
-  CALL iniconst()
-  CALL inigeom()
-
-!--- Initializations for tracers
-  CALL infotrac_init
-  ALLOCATE(q3d(iip1,jjp1,llm,nqtot))
-
-  CALL inifilr()
-  CALL phys_state_var_init(read_climoz)
-
-  rlat(1) = ASIN(1.0)
-  DO j=2,jjm; rlat((j-2)*iim+2:(j-1)*iim+1)=rlatu(j);     END DO
-  rlat(klon) = - ASIN(1.0)
-  rlat(:)=rlat(:)*(180.0/pi)
-
-  rlon(1) = 0.0
-  DO j=2,jjm; rlon((j-2)*iim+2:(j-1)*iim+1)=rlonv(1:iim); END DO
-  rlon(klon) = 0.0
-  rlon(:)=rlon(:)*(180.0/pi)
-
-! For a coupled simulation, the ocean mask from ocean model is used to compute
-! the weights an to insure ocean fractions are the same for atmosphere and ocean
-! Otherwise, mask is created using Relief file.
-
-  WRITE(lunout,*)'Essai de lecture masque ocean'
-  iret = NF90_OPEN("o2a.nc", NF90_NOWRITE, nid_o2a)
-  IF(iret/=NF90_NOERR) THEN
-    WRITE(lunout,*)'ATTENTION!! pas de fichier o2a.nc trouve'
-    WRITE(lunout,*)'Run force'
-    x='masque'
-    masque(:,:)=0.0
-    CALL startget_phys2d(x, iip1, jjp1, rlonv, rlatu, masque, 0.0, jjm, &
-   &              rlonu, rlatv, ib)
-    WRITE(lunout,*)'MASQUE construit : Masque'
-    WRITE(lunout,'(97I1)') nINT(masque)
-    CALL gr_dyn_fi(1, iip1, jjp1, klon, masque, zmasq)
-    WHERE(   zmasq(:)<EPSFRA) zmasq(:)=0.
-    WHERE(1.-zmasq(:)<EPSFRA) zmasq(:)=1.
-  ELSE
-    WRITE(lunout,*)'ATTENTION!! fichier o2a.nc trouve'
-    WRITE(lunout,*)'Run couple'
-    couple=.true.
-    iret=NF90_CLOSE(nid_o2a)
-    CALL flininfo("o2a.nc", iml_omask, jml_omask, llm_tmp, ttm_tmp, nid_o2a)
-    IF(iml_omask/=iim .OR.jml_omask/=jjp1) THEN
-      WRITE(lunout,*)'Dimensions non compatibles pour masque ocean'
-      WRITE(lunout,*)'iim = ',iim,' iml_omask = ',iml_omask
-      WRITE(lunout,*)'jjp1 = ',jjp1,' jml_omask = ',jml_omask
-      CALL abort_gcm('etat0_netcdf','Dimensions non compatibles pour masque oc&
-     &ean',1)
-    END IF
-    ALLOCATE(   ocemask(iml_omask,jml_omask),   ocetmp(iml_omask,jml_omask))
-    ALLOCATE( lon_omask(iml_omask,jml_omask),lat_omask(iml_omask,jml_omask))
-    ALLOCATE(dlon_omask(iml_omask),         dlat_omask(jml_omask))
-    CALL flinopen("o2a.nc", .FALSE., iml_omask, jml_omask, llm_tmp, lon_omask,&
-   &              lat_omask, lev, ttm_tmp, itaul, date, dt, fid)
-    CALL flinget(fid, 'OceMask', iml_omask, jml_omask, llm_tmp, ttm_tmp, &
-   &              1, 1, ocetmp)
-    CALL flinclo(fid)
-    dlon_omask(1:iml_omask) = lon_omask(1:iml_omask,1)
-    dlat_omask(1:jml_omask) = lat_omask(1,1:jml_omask)
-    ocemask = ocetmp
-    IF(dlat_omask(1)<dlat_omask(jml_omask)) THEN
-      DO j=1,jml_omask
-        ocemask(:,j) = ocetmp(:,jml_omask-j+1)
-      END DO
-    END IF
-!
-! Ocean mask to physical grid
-!*******************************************************************************
-    WRITE(lunout,*)'ocemask '
-    WRITE(fmt,"(i4,'i1)')")iml_omask ; fmt='('//ADJUSTL(fmt)
-    WRITE(lunout,fmt)int(ocemask)
-    ocemask_fi(1)=ocemask(1,1)
-    DO j=2,jjm; ocemask_fi((j-2)*iim+2:(j-1)*iim+1)=ocemask(1:iim,j); END DO
-    ocemask_fi(klon)=ocemask(1,jjp1)
-    zmasq=1.-ocemask_fi
-  END IF
-
-  CALL gr_fi_dyn(1,klon,iip1,jjp1,zmasq,masque)
-
-  ! The startget calls need to be replaced by a call to restget to get the
-  ! values in the restart file
-  x = 'relief'; orog(:,:) = 0.0
-  CALL startget_phys2d(x,iip1,jjp1,rlonv,rlatu, orog, 0.0,jjm,rlonu,rlatv,ib,&
- &               masque)
-
-  x = 'rugosite'; rugo(:,:) = 0.0
-  CALL startget_phys2d(x,iip1,jjp1,rlonv,rlatu, rugo, 0.0,jjm, rlonu,rlatv,ib)
-!  WRITE(lunout,'(49I1)') INT(orog(:,:)*10)
-!  WRITE(lunout,'(49I1)') INT(rugo(:,:)*10)
-
-! Sub-surfaces initialization
-!*******************************************************************************
-  pctsrf=0.
-  x = 'psol'; psol(:,:) = 0.0
-  CALL startget_phys2d(x,iip1,jjp1,rlonv,rlatu,psol,0.0,jjm,rlonu,rlatv,ib)
-!  WRITE(lunout,*) 'PSOL :', psol(10,20)
-!  WRITE(lunout,*) ap(:), bp(:)
-
-! Mid-levels pressure computation
-!*******************************************************************************
-  CALL pression(ip1jmp1, ap, bp, psol, p3d)
-  if (pressure_exner) then
-    CALL exner_hyb(ip1jmp1, psol, p3d, alpha, beta, pks, pk, y)
-  else
-    CALL exner_milieu(ip1jmp1,psol,p3d,beta,pks,pk,y)
-  endif
-  pls(:,:,:)=preff*(pk(:,:,:)/cpp)**(1./kappa)
-!  WRITE(lunout,*) 'P3D :', p3d(10,20,:)
-!  WRITE(lunout,*) 'PK:',    pk(10,20,:)
-!  WRITE(lunout,*) 'PLS :', pls(10,20,:)
-
-  x = 'surfgeo'; phis(:,:) = 0.0
-  CALL startget_phys2d(x,iip1,jjp1,rlonv,rlatu,phis, 0.0,jjm, rlonu,rlatv,ib)
-
-  x = 'u';    uvent(:,:,:) = 0.0
-  CALL startget_dyn(x,rlonu,rlatu,pls,y,uvent,0.0,  &
- &                  rlonv,rlatv,ib)
-
-  x = 'v';    vvent(:,:,:) = 0.0
-  CALL startget_dyn(x, rlonv,rlatv,pls(:, :jjm, :),y(:, :jjm, :),vvent,0.0, &
- &                  rlonu,rlatu(:jjm),ib)
-
-  x = 't';    t3d(:,:,:) = 0.0
-  CALL startget_dyn(x,rlonv,rlatu,pls,y,t3d,0.0,    &
- &                  rlonu,rlatv,ib)
-
-  x = 'tpot'; tpot(:,:,:) = 0.0
-  CALL startget_dyn(x,rlonv,rlatu,pls,pk,tpot,0.0,  &
- &                  rlonu,rlatv,ib)
-
-  WRITE(lunout,*) 'T3D min,max:',minval(t3d(:,:,:)),maxval(t3d(:,:,:))
-  WRITE(lunout,*) 'PLS min,max:',minval(pls(:,:,:)),maxval(pls(:,:,:))
-
-! Humidity at saturation computation
-!*******************************************************************************
-  WRITE(lunout,*) 'avant q_sat'
-  CALL q_sat(llm*jjp1*iip1, t3d, pls, qsat)
-  WRITE(lunout,*) 'apres q_sat'
-  WRITE(lunout,*) 'QSAT min,max:',minval(qsat(:,:,:)),maxval(qsat(:,:,:))
-!  WRITE(lunout,*) 'QSAT :',qsat(10,20,:)
-
-  x = 'q';    qd (:,:,:) = 0.0
-  CALL startget_dyn(x,rlonv,rlatu,pls,qsat,qd,0.0, rlonu,rlatv,ib)
-  q3d(:,:,:,:) = 0.0 ; q3d(:,:,:,1) = qd(:,:,:)
-
-! Parameterization of ozone chemistry:
-! Look for ozone tracer:
-  i = 1
-  DO
-    found = tname(i)=="O3" .OR. tname(i)=="o3"
-    if (found .or. i == nqtot) exit
-    i = i + 1
-  end do
-  if (found) then
-    call regr_lat_time_coefoz
-    call press_coefoz
-    call regr_pr_o3(p3d, q3d(:, :, :, i))
-!   Convert from mole fraction to mass fraction:
-    q3d(:, :, :, i) = q3d(:, :, :, i)  * 48. / 29.
-  end if
-
-!--- OZONE CLIMATOLOGY
-  IF(read_climoz>=1) CALL regr_lat_time_climoz(read_climoz)
-
-  x = 'tsol'; tsol(:) = 0.0
-  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,tsol,0.0,jjm,rlonu,rlatv,ib)
-
-  x = 'qsol';  qsol(:) = 0.0
-  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,qsol,0.0,jjm,rlonu,rlatv,ib)
-
-  x = 'snow';  sn(:) = 0.0
-  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,sn,0.0,jjm,rlonu,rlatv,ib)
-
-  x = 'rads';  radsol(:) = 0.0
-  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,radsol,0.0,jjm,rlonu,rlatv,ib)
-
-  x = 'rugmer'; rugmer(:) = 0.0
-  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,rugmer,0.0,jjm,rlonu,rlatv,ib)
-
-  x = 'zmea';  zmea(:) = 0.0
-  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,zmea,0.0,jjm,rlonu,rlatv,ib)
-
-  x = 'zstd';  zstd(:) = 0.0
-  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,zstd,0.0,jjm,rlonu,rlatv,ib)
-
-  x = 'zsig';  zsig(:) = 0.0
-  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,zsig,0.0,jjm,rlonu,rlatv,ib)
-
-  x = 'zgam';  zgam(:) = 0.0
-  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,zgam,0.0,jjm,rlonu,rlatv,ib)
-
-  x = 'zthe';  zthe(:) = 0.0
-  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,zthe,0.0,jjm,rlonu,rlatv,ib)
-
-  x = 'zpic';  zpic(:) = 0.0
-  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,zpic,0.0,jjm,rlonu,rlatv,ib)
-
-  x = 'zval';  zval(:) = 0.0
-  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,zval,0.0,jjm,rlonu,rlatv,ib)
-
-!  WRITE(lunout,'(48I3)') 'TSOL :', INT(tsol(2:klon)-273)
-
-! Soil ice file reading for soil fraction and soil ice fraction
-!*******************************************************************************
-  CALL flininfo("landiceref.nc", iml_lic, jml_lic, llm_tmp, ttm_tmp, fid)
-  ALLOCATE( lat_lic(iml_lic,jml_lic),lon_lic(iml_lic, jml_lic))
-  ALLOCATE(dlat_lic(jml_lic),       dlon_lic(iml_lic))
-  ALLOCATE( fraclic(iml_lic,jml_lic))
-  CALL flinopen("landiceref.nc", .FALSE., iml_lic, jml_lic, llm_tmp,  &
- &               lon_lic, lat_lic, lev, ttm_tmp, itaul, date, dt, fid)
-  CALL flinget(fid, 'landice', iml_lic, jml_lic, llm_tmp, ttm_tmp, 1,1, fraclic)
-  CALL flinclo(fid)
-
-! Interpolation on model T-grid
-!*******************************************************************************
-  WRITE(lunout,*)'dimensions de landice iml_lic, jml_lic : ',iml_lic,jml_lic
-! conversion if coordinates are in degrees
-  IF(MAXVAL(lon_lic)>pi) lon_lic=lon_lic*pi/180.
-  IF(MAXVAL(lat_lic)>pi) lat_lic=lat_lic*pi/180.
-  dlon_lic(:)=lon_lic(:,1)
-  dlat_lic(:)=lat_lic(1,:)
-  CALL grille_m( iml_lic, jml_lic, dlon_lic, dlat_lic, fraclic, iim,jjp1,   &
- &               rlonv, rlatu, flic_tmp(1:iim,:) )
-  flic_tmp(iip1,:)=flic_tmp(1,:)
-
-!--- To the physical grid
-  CALL gr_dyn_fi(1, iip1, jjp1, klon, flic_tmp, pctsrf(:,is_lic))
-
-!--- Adequation with soil/sea mask
-  WHERE(pctsrf(:,is_lic)<EPSFRA) pctsrf(:,is_lic)=0. 
-  WHERE(zmasq(:)<EPSFRA)         pctsrf(:,is_lic)=0.
-  pctsrf(:,is_ter)=zmasq(:)
-  DO ji=1,klon
-    IF(zmasq(ji)>EPSFRA) THEN 
-      IF(pctsrf(ji,is_lic)>=zmasq(ji)) THEN
-        pctsrf(ji,is_lic)=zmasq(ji)
-        pctsrf(ji,is_ter)=0.
-      ELSE
-        pctsrf(ji,is_ter)=zmasq(ji)-pctsrf(ji,is_lic)
-        IF(pctsrf(ji,is_ter)<EPSFRA) THEN
-          pctsrf(ji,is_ter)=0.
-          pctsrf(ji,is_lic)=zmasq(ji)
-        END IF 
-      END IF 
-    END IF 
-  END DO 
-
-! sub-surface ocean and sea ice (sea ice set to zero for start)
-!*******************************************************************************
-  pctsrf(:,is_oce)=(1.-zmasq(:))
-  WHERE(pctsrf(:,is_oce)<EPSFRA) pctsrf(:,is_oce)=0.
-  IF(couple) pctsrf(:,is_oce)=ocemask_fi(:)
-  isst=0
-  WHERE(pctsrf(2:klon-1,is_oce)>0.) isst=1
-
-! It is checked that the sub-surfaces sum is equal to 1
-!*******************************************************************************
-  ji=COUNT((ABS(SUM(pctsrf(:,:),dim=2))-1.0)>EPSFRA)
-  IF(ji/=0) WRITE(lunout,*) 'pb repartition sous maille pour ',ji,' points'
-  CALL gr_fi_ecrit(1, klon, iim, jjp1, zmasq, zx_tmp_2d)
-!  WRITE(fmt,"(i3,')')")iim; fmt='(i'//ADJUSTL(fmt)
-!  WRITE(lunout,*)'zmasq = '
-!  WRITE(lunout,TRIM(fmt))NINT(zx_tmp_2d)
-  CALL gr_fi_dyn(1, klon, iip1, jjp1, zmasq, masque)
-  WRITE(fmt,"(i4,'i1)')")iip1 ; fmt='('//ADJUSTL(fmt)
-  WRITE(lunout,*) 'MASQUE construit : Masque'
-  WRITE(lunout,TRIM(fmt))NINT(masque(:,:))
-
-! Intermediate computation
-!*******************************************************************************
-  CALL massdair(p3d,masse)
-  WRITE(lunout,*)' ALPHAX ',alphax
-  DO l=1,llm
-    xppn(:)=aire(1:iim,1   )*masse(1:iim,1   ,l)
-    xpps(:)=aire(1:iim,jjp1)*masse(1:iim,jjp1,l)
-    xpn=SUM(xppn)/apoln
-    xps=SUM(xpps)/apols
-    masse(:,1   ,l)=xpn
-    masse(:,jjp1,l)=xps
-  END DO
-  q3d(iip1,:,:,:)=q3d(1,:,:,:)
-  phis(iip1,:) = phis(1,:)
-
-  IF(.NOT.letat0) RETURN
-
-! Writing
-!*******************************************************************************
-  CALL inidissip(lstardis,nitergdiv,nitergrot,niterh,tetagdiv,tetagrot,tetatemp)
-  WRITE(lunout,*)'sortie inidissip'
-  itau=0
-  itau_dyn=0
-  itau_phy=0
-  iday=dayref+itau/day_step
-  time=FLOAT(itau-(iday-dayref)*day_step)/day_step
-  IF(time>1.) THEN
-   time=time-1
-   iday=iday+1
-  END IF
-  day_ref=dayref
-  annee_ref=anneeref
-
-  CALL geopot( ip1jmp1, tpot, pk, pks, phis, phi )
-  WRITE(lunout,*)'sortie geopot'
-
-  CALL caldyn0( itau, uvent, vvent, tpot, psol, masse, pk, phis,               &
-                phi,  w, pbaru, pbarv, time+iday-dayref)
-  WRITE(lunout,*)'sortie caldyn0'     
-  CALL dynredem0( "start.nc", dayref, phis)
-  WRITE(lunout,*)'sortie dynredem0'
-  CALL dynredem1( "start.nc", 0.0, vvent, uvent, tpot, q3d, masse, psol)
-  WRITE(lunout,*)'sortie dynredem1' 
-
-! Physical initial state writting
-!*******************************************************************************
-  WRITE(lunout,*)'phystep ',dtvr,iphysiq,nbapp_rad
-  phystep   = dtvr * FLOAT(iphysiq)
-  radpas    = NINT (86400./phystep/ FLOAT(nbapp_rad) )
-  WRITE(lunout,*)'phystep =', phystep, radpas
-
-! Init: tsol, qsol, sn, evap, tsoil, rain_fall, snow_fall, solsw, sollw, frugs
-!*******************************************************************************
-  DO i=1,nbsrf; ftsol(:,i) = tsol; END DO
-  DO i=1,nbsrf; snsrf(:,i) = sn;   END DO
-  falb1(:,is_ter) = 0.08; falb1(:,is_lic) = 0.6
-  falb1(:,is_oce) = 0.5;  falb1(:,is_sic) = 0.6
-  falb2 = falb1
-  evap(:,:) = 0.
-  DO i=1,nbsrf; qsolsrf(:,i)=150.; END DO
-  DO i=1,nbsrf; DO j=1,nsoilmx; tsoil(:,j,i) = tsol; END DO; END DO
-  rain_fall = 0.; snow_fall = 0.
-  solsw = 165.;   sollw = -53.
-  t_ancien = 273.15
-  q_ancien = 0.
-  agesno = 0.
-  frugs(:,is_oce) = rugmer(:)
-  frugs(:,is_ter) = MAX(1.0e-05,zstd(:)*zsig(:)/2.0)
-  frugs(:,is_lic) = MAX(1.0e-05,zstd(:)*zsig(:)/2.0)
-  frugs(:,is_sic) = 0.001
-  fder = 0.0
-  clwcon = 0.0
-  rnebcon = 0.0
-  ratqs = 0.0
-  run_off_lic_0 = 0.0 
-  rugoro = 0.0
-
-! Before phyredem calling, surface modules and values to be saved in startphy.nc
-! are initialized
-!*******************************************************************************
-  dummy = 1.0
-  pbl_tke(:,:,:) = 1.e-8 
-  zmax0(:) = 40.
-  f0(:) = 1.e-5
-  ema_work1(:,:) = 0.
-  ema_work2(:,:) = 0.
-  wake_deltat(:,:) = 0.
-  wake_deltaq(:,:) = 0.
-  wake_s(:) = 0.
-  wake_cstar(:) = 0.
-  wake_fip(:) = 0.
-  wake_pe = 0.
-  fm_therm = 0.
-  entr_therm = 0.
-  detr_therm = 0.
-
-  CALL fonte_neige_init(run_off_lic_0)
-  CALL pbl_surface_init( qsol, fder, snsrf, qsolsrf, evap, frugs, agesno, tsoil )
-  CALL phyredem( "startphy.nc" )
-
-!  WRITE(lunout,*)'CCCCCCCCCCCCCCCCCC REACTIVER SORTIE VISU DANS ETAT0'
-!  WRITE(lunout,*)'entree histclo'
-  CALL histclo()
-
-#endif 
-!#endif of #ifdef CPP_EARTH
-  RETURN
-
-END SUBROUTINE etat0_netcdf
-!
-!-------------------------------------------------------------------------------
Index: LMDZ5/branches/testing/libf/dyn3dpar/filtreg_p.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dpar/filtreg_p.F	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dpar/filtreg_p.F	(revision 1707)
@@ -214,5 +214,5 @@
      &                    champ_fft(1,j-jdfil+1,1), iip1*nlat)
 #else
-                     champ_fft(:,j-jdfil+1,:)
+                     champ_fft(:iim,j-jdfil+1,:)
      &                    =matmul(matrinvn(:,:,j),champ_loc(:iim,j,:))
 #endif
@@ -227,5 +227,5 @@
      &                    champ_fft(1,j-jdfil+1,1), iip1*nlat)
 #else
-                     champ_fft(:,j-jdfil+1,:)
+                     champ_fft(:iim,j-jdfil+1,:)
      &                    =matmul(matriceun(:,:,j),champ_loc(:iim,j,:))
 #endif
@@ -240,5 +240,5 @@
      &                    champ_fft(1,j-jdfil+1,1), iip1*nlat)
 #else
-                     champ_fft(:,j-jdfil+1,:)
+                     champ_fft(:iim,j-jdfil+1,:)
      &                    =matmul(matricevn(:,:,j),champ_loc(:iim,j,:))
 #endif
@@ -257,5 +257,5 @@
      &                    champ_fft(1,j-jdfil+1,1), iip1*nlat)
 #else
-                     champ_fft(:,j-jdfil+1,:)
+                     champ_fft(:iim,j-jdfil+1,:)
      &                    =matmul(matrinvs(:,:,j-jfiltsu+1),
      &                            champ_loc(:iim,j,:))
@@ -272,5 +272,5 @@
      &                    champ_fft(1,j-jdfil+1,1), iip1*nlat)
 #else
-                     champ_fft(:,j-jdfil+1,:)
+                     champ_fft(:iim,j-jdfil+1,:)
      &                    =matmul(matriceus(:,:,j-jfiltsu+1),
      &                            champ_loc(:iim,j,:))
@@ -287,5 +287,5 @@
      &                    champ_fft(1,j-jdfil+1,1), iip1*nlat)
 #else
-                     champ_fft(:,j-jdfil+1,:)
+                     champ_fft(:iim,j-jdfil+1,:)
      &                    =matmul(matricevs(:,:,j-jfiltsv+1),
      &                            champ_loc(:iim,j,:))
Index: LMDZ5/branches/testing/libf/dyn3dpar/fxhyp.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dpar/fxhyp.F	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dpar/fxhyp.F	(revision 1707)
@@ -48,18 +48,18 @@
 c
        REAL   dzoom
-       REAL*8 xlon(iip1),xprimm(iip1),xuv
-       REAL*8 xtild(0:nmax2)
-       REAL*8 fhyp(0:nmax2),ffdx,beta,Xprimt(0:nmax2)
-       REAL*8 Xf(0:nmax2),xxpr(0:nmax2)
-       REAL*8 xvrai(iip1),xxprim(iip1) 
-       REAL*8 pi,depi,epsilon,xzoom,fa,fb
-       REAL*8 Xf1, Xfi , a0,a1,a2,a3,xi2
+       REAL(KIND=8) xlon(iip1),xprimm(iip1),xuv
+       REAL(KIND=8) xtild(0:nmax2)
+       REAL(KIND=8) fhyp(0:nmax2),ffdx,beta,Xprimt(0:nmax2)
+       REAL(KIND=8) Xf(0:nmax2),xxpr(0:nmax2)
+       REAL(KIND=8) xvrai(iip1),xxprim(iip1) 
+       REAL(KIND=8) pi,depi,epsilon,xzoom,fa,fb
+       REAL(KIND=8) Xf1, Xfi , a0,a1,a2,a3,xi2
        INTEGER i,it,ik,iter,ii,idif,ii1,ii2
-       REAL*8 xi,xo1,xmoy,xlon2,fxm,Xprimin
-       REAL*8 champmin,champmax,decalx
+       REAL(KIND=8) xi,xo1,xmoy,xlon2,fxm,Xprimin
+       REAL(KIND=8) champmin,champmax,decalx
        INTEGER is2
        SAVE is2
 
-       REAL*8 heavyside
+       REAL(KIND=8) heavyside
 
        pi       = 2. * ASIN(1.)
@@ -68,4 +68,27 @@
        xzoom    = xzoomdeg * pi/180. 
 c
+       if (iim==1) then
+
+          print*,'Longitudes calculees a la main pour iim=1'
+
+          rlonm025(1)=-pi/2.
+          rlonv(1)=0.
+          rlonu(1)=pi
+          rlonp025(1)=pi/2.
+          rlonm025(2)=rlonm025(1)+depi
+          rlonv(2)=rlonv(1)+depi
+          rlonu(2)=rlonu(1)+depi
+          rlonp025(2)=rlonp025(1)+depi
+
+          xprimm025(:)=1.
+          xprimv(:)=1.
+          xprimu(:)=1.
+          xprimp025(:)=1.
+          champmin=depi
+          champmax=depi
+          return
+
+       endif
+
            decalx   = .75
        IF( grossism.EQ.1..AND.scal180 )  THEN
@@ -286,8 +309,10 @@
 
 
+
        IF(ik.EQ.1.and.grossism.EQ.1.)  THEN
          xvrai(1)    = xvrai(iip1)-depi
          xxprim(1)   = xxprim(iip1)
        ENDIF
+
        DO i = 1 , iim
         xlon(i)     = xvrai(i)
Index: LMDZ5/branches/testing/libf/dyn3dpar/gcm.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dpar/gcm.F	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dpar/gcm.F	(revision 1707)
@@ -418,10 +418,10 @@
 
       CALL inidissip( lstardis, nitergdiv, nitergrot, niterh   ,
-     *                tetagdiv, tetagrot , tetatemp              )
+     *                tetagdiv, tetagrot , tetatemp, vert_prof_dissip)
 
 c-----------------------------------------------------------------------
 c   Initialisation de la physique :
 c   -------------------------------
-      IF (call_iniphys.and.iflag_phys.eq.1) THEN
+      IF (call_iniphys.and.(iflag_phys==1.or.iflag_phys>=100)) THEN
          latfi(1)=rlatu(1)
          lonfi(1)=0.
@@ -446,9 +446,10 @@
 ! Physics:
 #ifdef CPP_PHYS
-         CALL iniphysiq(ngridmx,llm,daysec,day_ini,dtphys/nsplit_phys ,
-     ,                latfi,lonfi,airefi,zcufi,zcvfi,rad,g,r,cpp     )
+         CALL iniphysiq(ngridmx,llm,daysec,day_ini,dtphys/nsplit_phys,
+     &                latfi,lonfi,airefi,zcufi,zcvfi,rad,g,r,cpp,
+     &                iflag_phys)
 #endif
          call_iniphys=.false.
-      ENDIF ! of IF (call_iniphys.and.(iflag_phys.eq.1))
+      ENDIF ! of IF (call_iniphys.and.(iflag_phys==1.or.iflag_phys>=100))
 
 
@@ -481,12 +482,4 @@
  301  FORMAT('1'/,15x,'run du ', i2,'/',i2,'/',i4)
  302  FORMAT('1'/,15x,'    au ', i2,'/',i2,'/',i4)
-#endif
-
-#ifdef CPP_PHYS
-! Create start file (startphy.nc) and boundary conditions (limit.nc) 
-! for the Earth verstion
-       if (iflag_phys>=100) then
-          call iniaqua(ngridmx,latfi,lonfi,iflag_phys)
-       endif
 #endif
 
Index: LMDZ5/branches/testing/libf/dyn3dpar/groupe_p.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dpar/groupe_p.F	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dpar/groupe_p.F	(revision 1707)
@@ -37,13 +37,21 @@
       integer i,j,l
 
-      logical firstcall
-      save firstcall
-c$OMP THREADPRIVATE(firstcall)
+      logical firstcall,groupe_ok
+      save firstcall,groupe_ok
+c$OMP THREADPRIVATE(firstcall,groupe_ok)
 
       data firstcall/.true./
+      data groupe_ok/.true./
+
       integer ijb,ije,jjb,jje
       
+      if (iim==1) then
+         groupe_ok=.false.
+      endif
+
       if (firstcall) then
-         if(mod(iim,2**ngroup).ne.0) stop'probleme du nombre ede point'
+         if (groupe_ok) then
+           if(mod(iim,2**ngroup).ne.0) stop'probleme du nombre de point'
+         endif
          firstcall=.false.
       endif
@@ -66,5 +74,7 @@
 c$OMP END DO NOWAIT
 
-      call groupeun_p(jjp1,llm,jjb,jje,zconvmm)
+      if (groupe_ok) then
+         call groupeun_p(jjp1,llm,jjb,jje,zconvmm)
+      endif
       
       jjb=jj_begin-1
@@ -78,5 +88,7 @@
 c$OMP END DO NOWAIT
 
-      call groupeun_p(jjm,llm,jjb,jje,pbarvm)
+      if (groupe_ok) then
+         call groupeun_p(jjm,llm,jjb,jje,pbarvm)
+      endif
 
 c   Champs 3D
@@ -101,4 +113,5 @@
       enddo
 c$OMP END DO NOWAIT
+
 c    integration de la convergence de masse de haut  en bas ......
    
Index: LMDZ5/branches/testing/libf/dyn3dpar/inidissip.F90
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dpar/inidissip.F90	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dpar/inidissip.F90	(revision 1707)
@@ -3,5 +3,5 @@
 !
 SUBROUTINE inidissip ( lstardis,nitergdiv,nitergrot,niterh  , &
-     tetagdiv,tetagrot,tetatemp             )
+     tetagdiv,tetagrot,tetatemp, vert_prof_dissip)
   !=======================================================================
   !   initialisation de la dissipation horizontale
@@ -25,4 +25,10 @@
   INTEGER,INTENT(in) :: nitergdiv,nitergrot,niterh
   REAL,INTENT(in) :: tetagdiv,tetagrot,tetatemp
+
+  integer, INTENT(in):: vert_prof_dissip
+  ! Vertical profile of horizontal dissipation
+  ! Allowed values:
+  ! 0: rational fraction, function of pressure
+  ! 1: tanh of altitude
 
 ! Local variables:
@@ -167,5 +173,5 @@
   !   --------------------------------------------------
 
-  if (ok_strato .and. llm==39) then
+  if (vert_prof_dissip == 1) then
      do l=1,llm
         pseudoz=8.*log(preff/presnivs(l))
Index: LMDZ5/branches/testing/libf/dyn3dpar/leapfrog_p.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dpar/leapfrog_p.F	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dpar/leapfrog_p.F	(revision 1707)
@@ -139,4 +139,5 @@
       REAL :: secondes
 
+      logical :: physic
       LOGICAL first,callinigrads
 
@@ -208,4 +209,6 @@
 
       itau = 0
+      physic=.true.
+      if (iflag_phys==0.or.iflag_phys==2) physic=.false.
 !      iday = day_ini+itau/day_step
 !      time = REAL(itau-(iday-day_ini)*day_step)/day_step+time_0
@@ -364,5 +367,5 @@
      s        apdiss = .TRUE.
          IF( MOD(itau,iphysiq ).EQ.0.AND..NOT.forward 
-     s          .and. iflag_phys.EQ.1                 ) apphys = .TRUE.
+     s          .and. physic                        ) apphys = .TRUE.
       ELSE
       ! Leapfrog/Matsuno time stepping 
@@ -370,5 +373,5 @@
          IF( MOD(itau+1,dissip_period).EQ.0 .AND. .NOT. forward )
      s        apdiss = .TRUE.
-         IF( MOD(itau+1,iphysiq).EQ.0.AND.iflag_phys.EQ.1) apphys=.TRUE.
+         IF( MOD(itau+1,iphysiq).EQ.0.AND.physic) apphys=.TRUE.
       END IF
 
@@ -707,4 +710,10 @@
            jD_cur = jD_ref + day_ini - day_ref
      $        + itau/day_step
+
+           IF (planet_type .eq."generic") THEN
+              ! AS: we make jD_cur to be pday
+              jD_cur = int(day_ini + itau/day_step)
+           ENDIF
+
            jH_cur = jH_ref + start_time +                                &
      &              mod(itau,day_step)/float(day_step) 
Index: LMDZ5/branches/testing/libf/dyn3dpar/limit_netcdf.F90
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dpar/limit_netcdf.F90	(revision 1669)
+++ 	(revision )
@@ -1,642 +1,0 @@
-!
-! $Id$
-!-------------------------------------------------------------------------------
-!
-SUBROUTINE limit_netcdf(interbar, extrap, oldice, masque)
-!
-!-------------------------------------------------------------------------------
-! Author : L. Fairhead, 27/01/94
-!-------------------------------------------------------------------------------
-! Purpose: Boundary conditions files building for new model using climatologies.
-!          Both grids have to be regular.
-!-------------------------------------------------------------------------------
-! Note: This routine is designed to work for Earth
-!-------------------------------------------------------------------------------
-! Modification history:
-!  * 23/03/1994: Z. X. Li
-!  *    09/1999: L. Fairhead (netcdf reading in LMDZ.3.3)
-!  *    07/2001: P. Le Van
-!  *    11/2009: L. Guez     (ozone day & night climatos, see etat0_netcdf.F90)
-!  *    12/2009: D. Cugnet   (f77->f90, calendars, files from coupled runs)
-!-------------------------------------------------------------------------------
-  USE control_mod
-#ifdef CPP_EARTH
-  USE dimphy
-  USE ioipsl,             ONLY : ioget_year_len
-  USE phys_state_var_mod, ONLY : pctsrf
-  USE netcdf,             ONLY : NF90_OPEN,    NF90_CREATE,  NF90_CLOSE,       &
-                   NF90_DEF_DIM, NF90_DEF_VAR, NF90_PUT_VAR, NF90_PUT_ATT,     &
-                   NF90_NOERR,   NF90_NOWRITE, NF90_DOUBLE,  NF90_GLOBAL,      &
-		   NF90_CLOBBER, NF90_ENDDEF,  NF90_UNLIMITED, NF90_FLOAT
-  USE inter_barxy_m, only: inter_barxy
-#endif
-  IMPLICIT NONE
-!-------------------------------------------------------------------------------
-! Arguments:
-#include "dimensions.h"
-#include "paramet.h"
-#include "iniprint.h"
-  LOGICAL,                    INTENT(IN) :: interbar ! barycentric interpolation
-  LOGICAL,                    INTENT(IN) :: extrap   ! SST extrapolation flag
-  LOGICAL,                    INTENT(IN) :: oldice   ! old way ice computation
-  REAL, DIMENSION(iip1,jjp1), INTENT(IN) :: masque   ! land mask
-#ifndef CPP_EARTH
-  CALL abort_gcm('limit_netcdf','Earth-specific routine, needs Earth physics',1)
-#else
-!-------------------------------------------------------------------------------
-! Local variables:
-#include "logic.h"
-#include "comvert.h"
-#include "comgeom2.h"
-#include "comconst.h"
-#include "indicesol.h"
-
-!--- INPUT NETCDF FILES NAMES --------------------------------------------------
-  CHARACTER(LEN=25) :: icefile, sstfile, dumstr
-  CHARACTER(LEN=25), PARAMETER :: famipsst='amipbc_sst_1x1.nc        ',        &
-                                  famipsic='amipbc_sic_1x1.nc        ',        &
-                                  fcpldsst='cpl_atm_sst.nc           ',        &
-                                  fcpldsic='cpl_atm_sic.nc           ',        &
-                                  fhistsst='histmth_sst.nc           ',        &
-                                  fhistsic='histmth_sic.nc           ',        &
-                                  frugo   ='Rugos.nc                 ',        &
-                                  falbe   ='Albedo.nc                '
-  CHARACTER(LEN=10) :: varname
-!--- OUTPUT VARIABLES FOR NETCDF FILE ------------------------------------------
-  REAL,   DIMENSION(klon)                :: fi_ice, verif
-  REAL,   DIMENSION(:,:),   POINTER      :: phy_rug=>NULL(), phy_ice=>NULL()
-  REAL,   DIMENSION(:,:),   POINTER      :: phy_sst=>NULL(), phy_alb=>NULL()
-  REAL,   DIMENSION(:,:),   ALLOCATABLE  :: phy_bil
-  REAL,   DIMENSION(:,:,:), ALLOCATABLE  :: pctsrf_t
-  INTEGER                                :: nbad
-
-!--- VARIABLES FOR OUTPUT FILE WRITING -----------------------------------------
-  INTEGER :: ierr, nid, ndim, ntim, k
-  INTEGER, DIMENSION(2) :: dims
-  INTEGER :: id_tim,  id_SST,  id_BILS, id_RUG, id_ALB
-  INTEGER :: id_FOCE, id_FSIC, id_FTER, id_FLIC
-  INTEGER :: NF90_FORMAT
-  INTEGER :: ndays                   !--- Depending on the output calendar
-
-!--- INITIALIZATIONS -----------------------------------------------------------
-#ifdef NC_DOUBLE
-  NF90_FORMAT=NF90_DOUBLE
-#else
-  NF90_FORMAT=NF90_FLOAT
-#endif
-
-  pi    = 4.*ATAN(1.)
-  rad   = 6371229.
-  daysec= 86400.
-  omeg  = 2.*pi/daysec
-  g     = 9.8
-  kappa = 0.2857143
-  cpp   = 1004.70885
-  dtvr  = daysec/REAL(day_step)
-  CALL inigeom
-
-!--- Beware: anneeref (from gcm.def) is used to determine output time sampling
-  ndays=ioget_year_len(anneeref)
-
-!--- RUGOSITY TREATMENT --------------------------------------------------------
-  IF (prt_level>1) WRITE(lunout,*) 'Traitement de la rugosite'
-  varname='RUGOS'
-  CALL get_2Dfield(frugo,varname,'RUG',interbar,ndays,phy_rug,mask=masque(1:iim,:))
-
-!--- OCEAN TREATMENT -----------------------------------------------------------
-  IF (prt_level>1) WRITE(lunout,*) 'Traitement de la glace oceanique'
-
-! Input SIC file selection
-! Open file only to test if available
-  IF ( NF90_OPEN(TRIM(famipsic),NF90_NOWRITE,nid)==NF90_NOERR ) THEN
-     icefile=TRIM(famipsic)
-     varname='sicbcs'
-  ELSE IF( NF90_OPEN(TRIM(fcpldsic),NF90_NOWRITE,nid)==NF90_NOERR ) THEN
-     icefile=TRIM(fcpldsic)
-     varname='SIICECOV'
-  ELSE IF ( NF90_OPEN(TRIM(fhistsic),NF90_NOWRITE,nid)==NF90_NOERR ) THEN
-     icefile=TRIM(fhistsic)
-     varname='pourc_sic'
-  ELSE
-     WRITE(lunout,*) 'ERROR! No sea-ice input file was found.'
-     WRITE(lunout,*) 'One of following files must be availible : ',trim(famipsic),', ',trim(fcpldsic),', ',trim(fhistsic)
-     CALL abort_gcm('limit_netcdf','No sea-ice file was found',1)
-  END IF
-  ierr=NF90_CLOSE(nid)
-  IF (prt_level>=0) WRITE(lunout,*)'Pour la glace de mer a ete choisi le fichier '//TRIM(icefile)
-
-  CALL get_2Dfield(icefile,varname, 'SIC',interbar,ndays,phy_ice,flag=oldice)
-
-  ALLOCATE(pctsrf_t(klon,nbsrf,ndays))
-  DO k=1,ndays
-     fi_ice=phy_ice(:,k)
-     WHERE(fi_ice>=1.0  ) fi_ice=1.0
-     WHERE(fi_ice<EPSFRA) fi_ice=0.0
-     pctsrf_t(:,is_ter,k)=pctsrf(:,is_ter)       ! land soil
-     pctsrf_t(:,is_lic,k)=pctsrf(:,is_lic)       ! land ice
-     IF (icefile==trim(fcpldsic)) THEN           ! SIC=pICE*(1-LIC-TER)
-        pctsrf_t(:,is_sic,k)=fi_ice(:)*(1.-pctsrf(:,is_lic)-pctsrf(:,is_ter))
-     ELSE IF (icefile==trim(fhistsic)) THEN      ! SIC=pICE
-        pctsrf_t(:,is_sic,k)=fi_ice(:)
-     ELSE ! icefile==famipsic                    ! SIC=pICE-LIC
-        pctsrf_t(:,is_sic,k)=fi_ice-pctsrf_t(:,is_lic,k)
-     END IF
-     WHERE(pctsrf_t(:,is_sic,k)<=0) pctsrf_t(:,is_sic,k)=0.
-     WHERE(1.0-zmasq<EPSFRA)
-        pctsrf_t(:,is_sic,k)=0.0
-        pctsrf_t(:,is_oce,k)=0.0
-     ELSEWHERE
-        WHERE(pctsrf_t(:,is_sic,k)>=1.0-zmasq)
-           pctsrf_t(:,is_sic,k)=1.0-zmasq
-           pctsrf_t(:,is_oce,k)=0.0
-        ELSEWHERE
-           pctsrf_t(:,is_oce,k)=1.0-zmasq-pctsrf_t(:,is_sic,k)
-           WHERE(pctsrf_t(:,is_oce,k)<EPSFRA)
-              pctsrf_t(:,is_oce,k)=0.0
-              pctsrf_t(:,is_sic,k)=1.0-zmasq
-           END WHERE
-        END WHERE
-     END WHERE
-     nbad=COUNT(pctsrf_t(:,is_oce,k)<0.0)
-     IF(nbad>0) WRITE(lunout,*) 'pb sous maille pour nb point = ',nbad
-     nbad=COUNT(abs(sum(pctsrf_t(:,:,k),dim=2)-1.0)>EPSFRA)
-     IF(nbad>0) WRITE(lunout,*) 'pb sous surface pour nb points = ',nbad
-  END DO
-  DEALLOCATE(phy_ice)
-
-!--- SST TREATMENT -------------------------------------------------------------
-  IF (prt_level>1) WRITE(lunout,*) 'Traitement de la sst'
-
-! Input SST file selection
-! Open file only to test if available
-  IF ( NF90_OPEN(TRIM(famipsst),NF90_NOWRITE,nid)==NF90_NOERR ) THEN
-     sstfile=TRIM(famipsst)
-     varname='tosbcs'
-  ELSE IF ( NF90_OPEN(TRIM(fcpldsst),NF90_NOWRITE,nid)==NF90_NOERR ) THEN
-     sstfile=TRIM(fcpldsst)
-     varname='SISUTESW'
-  ELSE IF ( NF90_OPEN(TRIM(fhistsst),NF90_NOWRITE,nid)==NF90_NOERR ) THEN
-     sstfile=TRIM(fhistsst)
-     varname='tsol_oce'
-  ELSE
-     WRITE(lunout,*) 'ERROR! No sst input file was found.'
-     WRITE(lunout,*) 'One of following files must be availible : ',trim(famipsst),trim(fcpldsst),trim(fhistsst)
-     CALL abort_gcm('limit_netcdf','No sst file was found',1)
-  END IF
-  ierr=NF90_CLOSE(nid)
-  IF (prt_level>=0) WRITE(lunout,*)'Pour la temperature de mer a ete choisi un fichier '//TRIM(sstfile)
-
-  CALL get_2Dfield(sstfile,varname,'SST',interbar,ndays,phy_sst,flag=extrap)
-
-!--- ALBEDO TREATMENT ----------------------------------------------------------
-  IF (prt_level>1) WRITE(lunout,*) 'Traitement de l albedo'
-  varname='ALBEDO'
-  CALL get_2Dfield(falbe,varname,'ALB',interbar,ndays,phy_alb)
-
-!--- REFERENCE GROUND HEAT FLUX TREATMENT --------------------------------------
-  ALLOCATE(phy_bil(klon,ndays)); phy_bil=0.0
-
-!--- OUTPUT FILE WRITING -------------------------------------------------------
-  IF (prt_level>5) WRITE(lunout,*) 'Ecriture du fichier limit : debut'
-
-  !--- File creation
-  ierr=NF90_CREATE("limit.nc",NF90_CLOBBER,nid)
-  ierr=NF90_PUT_ATT(nid,NF90_GLOBAL,"title","Fichier conditions aux limites")
-
-  !--- Dimensions creation
-  ierr=NF90_DEF_DIM(nid,"points_physiques",klon,ndim)
-  ierr=NF90_DEF_DIM(nid,"time",NF90_UNLIMITED,ntim)
-
-  dims=(/ndim,ntim/)
-
-  !--- Variables creation
-  ierr=NF90_DEF_VAR(nid,"TEMPS",NF90_FORMAT,(/ntim/),id_tim)
-  ierr=NF90_DEF_VAR(nid,"FOCE", NF90_FORMAT,dims,id_FOCE)
-  ierr=NF90_DEF_VAR(nid,"FSIC", NF90_FORMAT,dims,id_FSIC)
-  ierr=NF90_DEF_VAR(nid,"FTER", NF90_FORMAT,dims,id_FTER)
-  ierr=NF90_DEF_VAR(nid,"FLIC", NF90_FORMAT,dims,id_FLIC)
-  ierr=NF90_DEF_VAR(nid,"SST",  NF90_FORMAT,dims,id_SST)
-  ierr=NF90_DEF_VAR(nid,"BILS", NF90_FORMAT,dims,id_BILS)
-  ierr=NF90_DEF_VAR(nid,"ALB",  NF90_FORMAT,dims,id_ALB)
-  ierr=NF90_DEF_VAR(nid,"RUG",  NF90_FORMAT,dims,id_RUG)
-
-  !--- Attributes creation
-  ierr=NF90_PUT_ATT(nid,id_tim, "title","Jour dans l annee")
-  ierr=NF90_PUT_ATT(nid,id_FOCE,"title","Fraction ocean")
-  ierr=NF90_PUT_ATT(nid,id_FSIC,"title","Fraction glace de mer")
-  ierr=NF90_PUT_ATT(nid,id_FTER,"title","Fraction terre")
-  ierr=NF90_PUT_ATT(nid,id_FLIC,"title","Fraction land ice")
-  ierr=NF90_PUT_ATT(nid,id_SST ,"title","Temperature superficielle de la mer")
-  ierr=NF90_PUT_ATT(nid,id_BILS,"title","Reference flux de chaleur au sol")
-  ierr=NF90_PUT_ATT(nid,id_ALB, "title","Albedo a la surface")
-  ierr=NF90_PUT_ATT(nid,id_RUG, "title","Rugosite")
-
-  ierr=NF90_ENDDEF(nid)
-
-  !--- Variables saving
-  ierr=NF90_PUT_VAR(nid,id_tim,(/(REAL(k),k=1,ndays)/))
-  ierr=NF90_PUT_VAR(nid,id_FOCE,pctsrf_t(:,is_oce,:),(/1,1/),(/klon,ndays/))
-  ierr=NF90_PUT_VAR(nid,id_FSIC,pctsrf_t(:,is_sic,:),(/1,1/),(/klon,ndays/))
-  ierr=NF90_PUT_VAR(nid,id_FTER,pctsrf_t(:,is_ter,:),(/1,1/),(/klon,ndays/))
-  ierr=NF90_PUT_VAR(nid,id_FLIC,pctsrf_t(:,is_lic,:),(/1,1/),(/klon,ndays/))
-  ierr=NF90_PUT_VAR(nid,id_SST ,phy_sst(:,:),(/1,1/),(/klon,ndays/))
-  ierr=NF90_PUT_VAR(nid,id_BILS,phy_bil(:,:),(/1,1/),(/klon,ndays/))
-  ierr=NF90_PUT_VAR(nid,id_ALB ,phy_alb(:,:),(/1,1/),(/klon,ndays/))
-  ierr=NF90_PUT_VAR(nid,id_RUG ,phy_rug(:,:),(/1,1/),(/klon,ndays/))
-
-  ierr=NF90_CLOSE(nid)
-
-  IF (prt_level>5) WRITE(lunout,*) 'Ecriture du fichier limit : fin'
-
-  DEALLOCATE(pctsrf_t,phy_sst,phy_bil,phy_alb,phy_rug)
-
-
-!===============================================================================
-!
-  CONTAINS
-!
-!===============================================================================
-
-
-!-------------------------------------------------------------------------------
-!
-SUBROUTINE get_2Dfield(fnam, varname, mode, ibar, ndays, champo, flag, mask)
-!
-!-----------------------------------------------------------------------------
-! Comments:
-!   There are two assumptions concerning the NetCDF files, that are satisfied
-!   with files that are conforming NC convention:
-!     1) The last dimension of the variables used is the time record.
-!     2) Dimensional variables have the same names as corresponding dimensions.
-!-----------------------------------------------------------------------------
-  USE netcdf, ONLY: NF90_OPEN, NF90_INQ_VARID, NF90_INQUIRE_VARIABLE, &
-       NF90_CLOSE, NF90_INQ_DIMID, NF90_INQUIRE_DIMENSION, NF90_GET_VAR, &
-       NF90_GET_ATT
-  USE dimphy, ONLY : klon
-  USE phys_state_var_mod, ONLY : pctsrf
-  USE control_mod
-  use pchsp_95_m, only: pchsp_95
-  use pchfe_95_m, only: pchfe_95
-  use arth_m, only: arth
-
-  IMPLICIT NONE
-#include "dimensions.h"
-#include "paramet.h"
-#include "comgeom2.h"
-#include "indicesol.h"
-#include "iniprint.h"
-!-----------------------------------------------------------------------------
-! Arguments:
-  CHARACTER(LEN=*),  INTENT(IN)     :: fnam     ! NetCDF file name
-  CHARACTER(LEN=10), INTENT(IN)     :: varname  ! NetCDF variable name
-  CHARACTER(LEN=3),  INTENT(IN)     :: mode     ! RUG, SIC, SST or ALB
-  LOGICAL,           INTENT(IN)     :: ibar     ! interp on pressure levels
-  INTEGER,           INTENT(IN)     :: ndays    ! current year number of days
-  REAL,    POINTER,  DIMENSION(:, :) :: champo  ! output field = f(t)
-  LOGICAL, OPTIONAL, INTENT(IN)     :: flag     ! extrapol. (SST) old ice (SIC)
-  REAL,    OPTIONAL, DIMENSION(iim, jjp1), INTENT(IN) :: mask
-!------------------------------------------------------------------------------
-! Local variables:
-!--- NetCDF
-  INTEGER :: ncid, varid                  ! NetCDF identifiers
-  CHARACTER(LEN=30)               :: dnam       ! dimension name
-!--- dimensions
-  INTEGER,           DIMENSION(4) :: dids       ! NetCDF dimensions identifiers
-  REAL, ALLOCATABLE, DIMENSION(:) :: dlon_ini   ! initial longitudes vector
-  REAL, ALLOCATABLE, DIMENSION(:) :: dlat_ini   ! initial latitudes  vector
-  REAL, POINTER,     DIMENSION(:) :: dlon, dlat ! reordered lon/lat  vectors
-!--- fields
-  INTEGER :: imdep, jmdep, lmdep                ! dimensions of 'champ'
-  REAL, ALLOCATABLE, DIMENSION(:, :) :: champ   ! wanted field on initial grid
-  REAL, ALLOCATABLE, DIMENSION(:) :: yder, timeyear
-  REAL,              DIMENSION(iim, jjp1) :: champint   ! interpolated field
-  REAL, ALLOCATABLE, DIMENSION(:, :, :)    :: champtime
-  REAL, ALLOCATABLE, DIMENSION(:, :, :)    :: champan
-!--- input files
-  CHARACTER(LEN=20)                 :: cal_in   ! calendar
-  CHARACTER(LEN=20)                 :: unit_sic ! attribute unit in sea-ice file
-  INTEGER                           :: ndays_in ! number of days
-!--- misc
-  INTEGER :: i, j, k, l                         ! loop counters
-  REAL, ALLOCATABLE, DIMENSION(:, :) :: work     ! used for extrapolation
-  CHARACTER(LEN=25)                 :: title    ! for messages
-  LOGICAL                           :: extrp    ! flag for extrapolation
-  LOGICAL                           :: oldice   ! flag for old way ice computation 
-  REAL                              :: chmin, chmax
-  INTEGER ierr
-  integer n_extrap ! number of extrapolated points
-  logical skip
-
-!------------------------------------------------------------------------------
-!---Variables depending on keyword 'mode' -------------------------------------
-  NULLIFY(champo)
-
-  SELECT CASE(mode)
-  CASE('RUG'); title='Rugosite'
-  CASE('SIC'); title='Sea-ice'
-  CASE('SST'); title='SST'
-  CASE('ALB'); title='Albedo'
-  END SELECT
-  
-
-  extrp=.FALSE. 
-  oldice=.FALSE.
-  IF ( PRESENT(flag) ) THEN 
-    IF ( flag .AND. mode=='SST' ) extrp=.TRUE. 
-    IF ( flag .AND. mode=='SIC' ) oldice=.TRUE. 
-  END IF
-
-!--- GETTING SOME DIMENSIONAL VARIABLES FROM FILE -----------------------------
-  IF (prt_level>5) WRITE(lunout,*) ' Now reading file : ',fnam
-  ierr=NF90_OPEN(fnam, NF90_NOWRITE, ncid);             CALL ncerr(ierr, fnam)
-  ierr=NF90_INQ_VARID(ncid, trim(varname), varid);            CALL ncerr(ierr, fnam)
-  ierr=NF90_INQUIRE_VARIABLE(ncid, varid, dimids=dids); CALL ncerr(ierr, fnam)
-
-!--- Read unit for sea-ice variable only
-  IF (mode=='SIC') THEN
-     ierr=NF90_GET_ATT(ncid, varid, 'units', unit_sic)
-     IF(ierr/=NF90_NOERR) THEN
-        IF (prt_level>5) WRITE(lunout,*) 'No unit was given in sea-ice file. Take percentage as default value'
-        unit_sic='X'
-     ELSE
-        IF (prt_level>5) WRITE(lunout,*) ' Sea-ice cover has unit=',unit_sic
-     END IF
-  END IF
-
-!--- Longitude
-  ierr=NF90_INQUIRE_DIMENSION(ncid, dids(1), name=dnam, len=imdep)
-  CALL ncerr(ierr, fnam); ALLOCATE(dlon_ini(imdep), dlon(imdep))
-  ierr=NF90_INQ_VARID(ncid, dnam, varid);                CALL ncerr(ierr, fnam)
-  ierr=NF90_GET_VAR(ncid, varid, dlon_ini);              CALL ncerr(ierr, fnam)
-  IF (prt_level>5) WRITE(lunout, *) 'variable ', dnam, 'dimension ', imdep
-
-!--- Latitude
-  ierr=NF90_INQUIRE_DIMENSION(ncid, dids(2), name=dnam, len=jmdep)
-  CALL ncerr(ierr, fnam); ALLOCATE(dlat_ini(jmdep), dlat(jmdep))
-  ierr=NF90_INQ_VARID(ncid, dnam, varid);                CALL ncerr(ierr, fnam)
-  ierr=NF90_GET_VAR(ncid, varid, dlat_ini);              CALL ncerr(ierr, fnam)
-  IF (prt_level>5) WRITE(lunout, *) 'variable ', dnam, 'dimension ', jmdep
-
-!--- Time (variable is not needed - it is rebuilt - but calendar is)
-  ierr=NF90_INQUIRE_DIMENSION(ncid, dids(3), name=dnam, len=lmdep)
-  CALL ncerr(ierr, fnam); ALLOCATE(timeyear(lmdep))
-  ierr=NF90_INQ_VARID(ncid, dnam, varid);                CALL ncerr(ierr, fnam)
-  cal_in=' '
-  ierr=NF90_GET_ATT(ncid, varid, 'calendar', cal_in)
-  IF(ierr/=NF90_NOERR) THEN
-    SELECT CASE(mode)
-      CASE('RUG', 'ALB'); cal_in='360d'
-      CASE('SIC', 'SST'); cal_in='gregorian'
-    END SELECT
-    IF (prt_level>5) WRITE(lunout, *)'ATTENTION: variable "time" sans attribut "calendrier" ' &
-         // 'dans '//TRIM(fnam)//'. On choisit la valeur par defaut.'
-  END IF
-  IF (prt_level>5) WRITE(lunout, *) 'variable ', dnam, 'dimension ', lmdep, 'calendrier ', &
-       cal_in
-
-  
-!--- CONSTRUCTING THE INPUT TIME VECTOR FOR INTERPOLATION --------------------
-  !--- Determining input file number of days, depending on calendar
-  ndays_in=year_len(anneeref, cal_in)
-
-!--- Time vector reconstruction (time vector from file is not trusted)
-!--- If input records are not monthly, time sampling has to be constant !
-  timeyear=mid_months(anneeref, cal_in, lmdep)
-  IF (lmdep /= 12) WRITE(lunout,*) 'Note : les fichiers de ', TRIM(mode), &
-       ' ne comportent pas 12, mais ', lmdep, ' enregistrements.'
-
-!--- GETTING THE FIELD AND INTERPOLATING IT ----------------------------------
-  ALLOCATE(champ(imdep, jmdep), champtime(iim, jjp1, lmdep))
-  IF(extrp) ALLOCATE(work(imdep, jmdep))
-
-  IF (prt_level>5) WRITE(lunout, *)
-  IF (prt_level>5) WRITE(lunout,*)'LECTURE ET INTERPOLATION HORIZ. DE ', lmdep, ' CHAMPS.'
-  ierr=NF90_INQ_VARID(ncid, varname, varid);             CALL ncerr(ierr, fnam)
-  DO l=1, lmdep
-    ierr=NF90_GET_VAR(ncid, varid, champ, (/1, 1, l/), (/imdep, jmdep, 1/))
-    CALL ncerr(ierr, fnam)
-    CALL conf_dat2d(title, imdep, jmdep, dlon_ini, dlat_ini, dlon, dlat, &
-         champ, ibar)
-
-    IF (extrp) CALL extrapol(champ, imdep, jmdep, 999999., .TRUE., .TRUE., 2, &
-         work)
-
-    IF(ibar .AND. .NOT.oldice) THEN
-      IF(l==1 .AND. prt_level>5) THEN
-        WRITE(lunout, *) '-------------------------------------------------------------------------'
-        WRITE(lunout, *) 'Utilisation de l''interpolation barycentrique pour ',TRIM(title),' $$$'
-        WRITE(lunout, *) '-------------------------------------------------------------------------'
-      END IF
-      IF(mode=='RUG') champ=LOG(champ)
-      CALL inter_barxy(dlon, dlat(:jmdep-1), champ, rlonu(:iim),     &
-                         rlatv, champint)
-      IF(mode=='RUG') THEN
-        champint=EXP(champint)
-        WHERE(NINT(mask)/=1) champint=0.001
-      END IF
-    ELSE
-      SELECT CASE(mode)
-        CASE('RUG');       CALL rugosite(imdep, jmdep, dlon, dlat, champ,    &
-                                    iim, jjp1, rlonv, rlatu, champint, mask)
-        CASE('SIC');       CALL sea_ice (imdep, jmdep, dlon, dlat, champ,    &
-                                    iim, jjp1, rlonv, rlatu, champint)
-        CASE('SST', 'ALB'); CALL grille_m(imdep, jmdep, dlon, dlat, champ,    &
-                                    iim, jjp1, rlonv, rlatu, champint)
-      END SELECT
-    END IF
-    champtime(:, :, l)=champint
-  END DO
-  ierr=NF90_CLOSE(ncid);                                 CALL ncerr(ierr, fnam)
-
-  DEALLOCATE(dlon_ini, dlat_ini, dlon, dlat, champ)
-  IF(extrp) DEALLOCATE(work)
-
-!--- TIME INTERPOLATION ------------------------------------------------------
-  IF (prt_level>5) THEN
-     WRITE(lunout, *)
-     WRITE(lunout, *)'INTERPOLATION TEMPORELLE.'
-     WRITE(lunout, *)' Vecteur temps en entree: ', timeyear
-     WRITE(lunout, *)' Vecteur temps en sortie de 0 a ', ndays
-  END IF
-
-  ALLOCATE(yder(lmdep), champan(iip1, jjp1, ndays))
-  skip = .false.
-  n_extrap = 0
-  DO j=1, jjp1
-    DO i=1, iim
-      yder = pchsp_95(timeyear, champtime(i, j, :), ibeg=2, iend=2, &
-           vc_beg=0., vc_end=0.)
-      CALL pchfe_95(timeyear, champtime(i, j, :), yder, skip, &
-           arth(0., real(ndays_in) / ndays, ndays), champan(i, j, :), ierr)
-      if (ierr < 0) stop 1
-      n_extrap = n_extrap + ierr
-    END DO
-  END DO
-  if (n_extrap /= 0) then
-     WRITE(lunout,*) "get_2Dfield pchfe_95: n_extrap = ", n_extrap
-  end if
-  champan(iip1, :, :)=champan(1, :, :)
-  DEALLOCATE(yder, champtime, timeyear)
-
-!--- Checking the result
-  DO j=1, jjp1
-    CALL minmax(iip1, champan(1, j, 10), chmin, chmax)
-    IF (prt_level>5) WRITE(lunout, *)' ',TRIM(title),' au temps 10 ', chmin, chmax, j
-  END DO
-
-!--- SPECIAL FILTER FOR SST: SST>271.38 --------------------------------------
-  IF(mode=='SST') THEN
-    IF (prt_level>5) WRITE(lunout, *) 'Filtrage de la SST: SST >= 271.38'
-    WHERE(champan<271.38) champan=271.38
-  END IF
-
-!--- SPECIAL FILTER FOR SIC: 0.0<SIC<1.0 -------------------------------------
-  IF(mode=='SIC') THEN
-    IF (prt_level>5) WRITE(lunout, *) 'Filtrage de la SIC: 0.0 < Sea-ice < 1.0'
-
-    IF (unit_sic=='1') THEN
-       ! Nothing to be done for sea-ice field is already in fraction of 1
-       ! This is the case for sea-ice in file cpl_atm_sic.nc
-       IF (prt_level>5) WRITE(lunout,*) 'Sea-ice field already in fraction of 1'
-    ELSE
-       ! Convert sea ice from percentage to fraction of 1
-       IF (prt_level>5) WRITE(lunout,*) 'Transformt sea-ice field from percentage to fraction of 1.' 
-       champan(:, :, :)=champan(:, :, :)/100.
-    END IF
-
-    champan(iip1, :, :)=champan(1, :, :)
-    WHERE(champan>1.0) champan=1.0
-    WHERE(champan<0.0) champan=0.0
- END IF
-
-!--- DYNAMICAL TO PHYSICAL GRID ----------------------------------------------
-  ALLOCATE(champo(klon, ndays))
-  DO k=1, ndays
-    CALL gr_dyn_fi(1, iip1, jjp1, klon, champan(1, 1, k), champo(1, k))
-  END DO
-  DEALLOCATE(champan)
-
-END SUBROUTINE get_2Dfield
-!
-!-------------------------------------------------------------------------------
-
-
-
-!-------------------------------------------------------------------------------
-!
-FUNCTION year_len(y,cal_in)
-!
-!-------------------------------------------------------------------------------
-  USE ioipsl, ONLY : ioget_calendar,ioconf_calendar,lock_calendar,ioget_year_len
-  IMPLICIT NONE
-!-------------------------------------------------------------------------------
-! Arguments:
-  INTEGER                       :: year_len
-  INTEGER,           INTENT(IN) :: y
-  CHARACTER(LEN=*),  INTENT(IN) :: cal_in
-!-------------------------------------------------------------------------------
-! Local variables:
-  CHARACTER(LEN=20)             :: cal_out              ! calendar (for outputs)
-!-------------------------------------------------------------------------------
-!--- Getting the input calendar to reset at the end of the function
-  CALL ioget_calendar(cal_out)
-
-!--- Unlocking calendar and setting it to wanted one
-  CALL lock_calendar(.FALSE.); CALL ioconf_calendar(TRIM(cal_in))
-
-!--- Getting the number of days in this year
-  year_len=ioget_year_len(y)
-
-!--- Back to original calendar
-  CALL lock_calendar(.FALSE.); CALL ioconf_calendar(TRIM(cal_out))
-
-END FUNCTION year_len
-!
-!-------------------------------------------------------------------------------
-
-
-!-------------------------------------------------------------------------------
-!
-FUNCTION mid_months(y,cal_in,nm)
-!
-!-------------------------------------------------------------------------------
-  USE ioipsl, ONLY : ioget_calendar,ioconf_calendar,lock_calendar,ioget_mon_len
-  IMPLICIT NONE
-!-------------------------------------------------------------------------------
-! Arguments:
-  INTEGER,                INTENT(IN) :: y               ! year
-  CHARACTER(LEN=*),       INTENT(IN) :: cal_in          ! calendar
-  INTEGER,                INTENT(IN) :: nm              ! months/year number
-  REAL,    DIMENSION(nm)             :: mid_months      ! mid-month times
-!-------------------------------------------------------------------------------
-! Local variables:
-  CHARACTER(LEN=99)                  :: mess            ! error message
-  CHARACTER(LEN=20)                  :: cal_out         ! calendar (for outputs)
-  INTEGER, DIMENSION(nm)             :: mnth            ! months lengths (days)
-  INTEGER                            :: m               ! months counter
-  INTEGER                            :: nd              ! number of days
-!-------------------------------------------------------------------------------
-  nd=year_len(y,cal_in)
-
-  IF(nm==12) THEN
-
-  !--- Getting the input calendar to reset at the end of the function
-    CALL ioget_calendar(cal_out)
-
-  !--- Unlocking calendar and setting it to wanted one
-    CALL lock_calendar(.FALSE.); CALL ioconf_calendar(TRIM(cal_in))
-
-  !--- Getting the length of each month
-    DO m=1,nm; mnth(m)=ioget_mon_len(y,m); END DO
-
-  !--- Back to original calendar
-    CALL lock_calendar(.FALSE.); CALL ioconf_calendar(TRIM(cal_out))
-
-  ELSE IF(MODULO(nd,nm)/=0) THEN
-    WRITE(mess,'(a,i3,a,i3,a)')'Unconsistent calendar: ',nd,' days/year, but ',&
-      nm,' months/year. Months number should divide days number.'
-    CALL abort_gcm('mid_months',TRIM(mess),1)
-
-  ELSE
-    mnth=(/(m,m=1,nm,nd/nm)/)
-  END IF
-
-!--- Mid-months times
-  mid_months(1)=0.5*REAL(mnth(1))
-  DO k=2,nm
-    mid_months(k)=mid_months(k-1)+0.5*REAL(mnth(k-1)+mnth(k))
-  END DO
-
-END FUNCTION mid_months
-!
-!-------------------------------------------------------------------------------
-
-
-!-------------------------------------------------------------------------------
-!
-SUBROUTINE ncerr(ncres,fnam)
-!
-!-------------------------------------------------------------------------------
-! Purpose: NetCDF errors handling.
-!-------------------------------------------------------------------------------
-  USE netcdf, ONLY : NF90_NOERR, NF90_STRERROR
-  IMPLICIT NONE
-!-------------------------------------------------------------------------------
-! Arguments:
-  INTEGER,          INTENT(IN) :: ncres
-  CHARACTER(LEN=*), INTENT(IN) :: fnam
-!-------------------------------------------------------------------------------
-#include "iniprint.h"
-  IF(ncres/=NF90_NOERR) THEN
-    WRITE(lunout,*)'Problem with file '//TRIM(fnam)//' in routine limit_netcdf.'
-    CALL abort_gcm('limit_netcdf',NF90_STRERROR(ncres),1)
-  END IF
-
-END SUBROUTINE ncerr
-!
-!-------------------------------------------------------------------------------
-
-#endif
-! of #ifdef CPP_EARTH
-
-END SUBROUTINE limit_netcdf
Index: LMDZ5/branches/testing/libf/dyn3dpar/mod_const_mpi.F90
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dpar/mod_const_mpi.F90	(revision 1707)
+++ LMDZ5/branches/testing/libf/dyn3dpar/mod_const_mpi.F90	(revision 1707)
@@ -0,0 +1,77 @@
+! 
+! $Id$
+!
+MODULE mod_const_mpi
+
+  INTEGER,SAVE :: COMM_LMDZ
+  INTEGER,SAVE :: MPI_REAL_LMDZ
+ 
+
+CONTAINS 
+
+  SUBROUTINE Init_const_mpi
+#ifdef CPP_IOIPSL
+    USE IOIPSL
+#else
+! if not using IOIPSL, we still need to use (a local version of) getin
+    USE ioipsl_getincom
+#endif
+
+    IMPLICIT NONE
+#ifdef CPP_MPI
+    INCLUDE 'mpif.h'
+#endif
+    INTEGER             :: ierr
+    INTEGER             :: comp_id
+    INTEGER             :: thread_required
+    INTEGER             :: thread_provided
+    CHARACTER(len = 6)  :: type_ocean
+
+!$OMP MASTER
+    type_ocean = 'force '
+    CALL getin('type_ocean', type_ocean)
+!$OMP END MASTER
+!$OMP BARRIER
+
+    IF (type_ocean=='couple') THEN
+#ifdef CPP_COUPLE
+!$OMP MASTER
+       CALL prism_init_comp_proto (comp_id, 'lmdz.x', ierr)
+       CALL prism_get_localcomm_proto(COMM_LMDZ,ierr)
+!$OMP END MASTER
+#endif
+#ifdef CPP_MPI
+      MPI_REAL_LMDZ=MPI_REAL8
+#endif
+    ELSE
+      CALL init_mpi
+    ENDIF
+
+  END SUBROUTINE Init_const_mpi
+  
+  SUBROUTINE Init_mpi
+  IMPLICIT NONE
+#ifdef CPP_MPI
+     INCLUDE 'mpif.h'
+#endif
+    INTEGER             :: ierr
+    INTEGER             :: thread_required
+    INTEGER             :: thread_provided
+
+#ifdef CPP_MPI
+!$OMP MASTER
+      thread_required=MPI_THREAD_SERIALIZED
+
+      CALL MPI_INIT_THREAD(thread_required,thread_provided,ierr)
+      IF (thread_provided < thread_required) THEN
+        PRINT *,'Warning : The multithreaded level of MPI librairy do not provide the requiered level',  &
+                ' in mod_const_mpi::Init_const_mpi'
+      ENDIF
+      COMM_LMDZ=MPI_COMM_WORLD
+      MPI_REAL_LMDZ=MPI_REAL8
+!$OMP END MASTER
+#endif
+
+   END SUBROUTINE Init_mpi
+    
+END MODULE mod_const_mpi
Index: LMDZ5/branches/testing/libf/dyn3dpar/mod_const_para.F90
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dpar/mod_const_para.F90	(revision 1669)
+++ 	(revision )
@@ -1,77 +1,0 @@
-! 
-! $Id$
-!
-MODULE mod_const_mpi
-
-  INTEGER,SAVE :: COMM_LMDZ
-  INTEGER,SAVE :: MPI_REAL_LMDZ
- 
-
-CONTAINS 
-
-  SUBROUTINE Init_const_mpi
-#ifdef CPP_IOIPSL
-    USE IOIPSL
-#else
-! if not using IOIPSL, we still need to use (a local version of) getin
-    USE ioipsl_getincom
-#endif
-
-    IMPLICIT NONE
-#ifdef CPP_MPI
-    INCLUDE 'mpif.h'
-#endif
-    INTEGER             :: ierr
-    INTEGER             :: comp_id
-    INTEGER             :: thread_required
-    INTEGER             :: thread_provided
-    CHARACTER(len = 6)  :: type_ocean
-
-!$OMP MASTER
-    type_ocean = 'force '
-    CALL getin('type_ocean', type_ocean)
-!$OMP END MASTER
-!$OMP BARRIER
-
-    IF (type_ocean=='couple') THEN
-#ifdef CPP_COUPLE
-!$OMP MASTER
-       CALL prism_init_comp_proto (comp_id, 'lmdz.x', ierr)
-       CALL prism_get_localcomm_proto(COMM_LMDZ,ierr)
-!$OMP END MASTER
-#endif
-#ifdef CPP_MPI
-      MPI_REAL_LMDZ=MPI_REAL8
-#endif
-    ELSE
-      CALL init_mpi
-    ENDIF
-
-  END SUBROUTINE Init_const_mpi
-  
-  SUBROUTINE Init_mpi
-  IMPLICIT NONE
-#ifdef CPP_MPI
-     INCLUDE 'mpif.h'
-#endif
-    INTEGER             :: ierr
-    INTEGER             :: thread_required
-    INTEGER             :: thread_provided
-
-#ifdef CPP_MPI
-!$OMP MASTER
-      thread_required=MPI_THREAD_SERIALIZED
-
-      CALL MPI_INIT_THREAD(thread_required,thread_provided,ierr)
-      IF (thread_provided < thread_required) THEN
-        PRINT *,'Warning : The multithreaded level of MPI librairy do not provide the requiered level',  &
-                ' in mod_const_mpi::Init_const_mpi'
-      ENDIF
-      COMM_LMDZ=MPI_COMM_WORLD
-      MPI_REAL_LMDZ=MPI_REAL8
-!$OMP END MASTER
-#endif
-
-   END SUBROUTINE Init_mpi
-    
-END MODULE mod_const_mpi
Index: LMDZ5/branches/testing/libf/dyn3dpar/parallel.F90
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dpar/parallel.F90	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dpar/parallel.F90	(revision 1707)
@@ -489,5 +489,10 @@
           enddo
           
-        endif
+        else
+          ! Ehouarn: When in debug mode, ifort complains (for call MPI_GATHERV
+          !          below) about Buffer_Recv() being not allocated.
+          !          So make a dummy allocation.
+          allocate(Buffer_Recv(1))
+        endif ! of if (MPI_Rank==rank)
   
 !$OMP CRITICAL (MPI)
Index: LMDZ5/branches/testing/libf/dyn3dpar/paramet.h
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dpar/paramet.h	(revision 1669)
+++ LMDZ5/branches/testing/libf/dyn3dpar/paramet.h	(revision 1707)
@@ -17,5 +17,5 @@
       INTEGER jcfil,jcfllm
 
-      PARAMETER( iip1= iim+1-1/iim,iip2=iim+2,iip3=iim+3                &
+      PARAMETER( iip1= iim+1,iip2=iim+2,iip3=iim+3                      &
      &    ,jjp1=jjm+1-1/jjm)
       PARAMETER( llmp1 = llm+1,  llmp2 = llm+2, llmm1 = llm-1 )
Index: LMDZ5/branches/testing/libf/filtrez/filtreg.F
===================================================================
--- LMDZ5/branches/testing/libf/filtrez/filtreg.F	(revision 1669)
+++ LMDZ5/branches/testing/libf/filtrez/filtreg.F	(revision 1707)
@@ -185,5 +185,5 @@
                DO j = jdfil,jffil
 #ifdef BLAS
-                  CALL DGEMM("N", "N", iim, nbniv, iim, 1.0, 
+                  CALL SGEMM("N", "N", iim, nbniv, iim, 1.0, 
      &                 matrinvn(1,1,j),
      &                 iim, champ(1,j,1), iip1*nlat, 0.0,
@@ -199,5 +199,5 @@
                DO j = jdfil,jffil
 #ifdef BLAS
-                  CALL DGEMM("N", "N", iim, nbniv, iim, 1.0, 
+                  CALL SGEMM("N", "N", iim, nbniv, iim, 1.0, 
      &                 matriceun(1,1,j),
      &                 iim, champ(1,j,1), iip1*nlat, 0.0,
@@ -213,5 +213,5 @@
                DO j = jdfil,jffil
 #ifdef BLAS
-                  CALL DGEMM("N", "N", iim, nbniv, iim, 1.0, 
+                  CALL SGEMM("N", "N", iim, nbniv, iim, 1.0, 
      &                 matricevn(1,1,j),
      &                 iim, champ(1,j,1), iip1*nlat, 0.0,
@@ -231,5 +231,5 @@
                DO j = jdfil,jffil
 #ifdef BLAS
-                  CALL DGEMM("N", "N", iim, nbniv, iim, 1.0, 
+                  CALL SGEMM("N", "N", iim, nbniv, iim, 1.0, 
      &                 matrinvs(1,1,j-jfiltsu+1),
      &                 iim, champ(1,j,1), iip1*nlat, 0.0,
@@ -247,5 +247,5 @@
                DO j = jdfil,jffil
 #ifdef BLAS
-                  CALL DGEMM("N", "N", iim, nbniv, iim, 1.0, 
+                  CALL SGEMM("N", "N", iim, nbniv, iim, 1.0, 
      &                 matriceus(1,1,j-jfiltsu+1),
      &                 iim, champ(1,j,1), iip1*nlat, 0.0,
@@ -262,5 +262,5 @@
                DO j = jdfil,jffil
 #ifdef BLAS
-                  CALL DGEMM("N", "N", iim, nbniv, iim, 1.0, 
+                  CALL SGEMM("N", "N", iim, nbniv, iim, 1.0, 
      &                 matricevs(1,1,j-jfiltsv+1),
      &                 iim, champ(1,j,1), iip1*nlat, 0.0,
Index: LMDZ5/branches/testing/libf/filtrez/filtreg_mod.F90
===================================================================
--- LMDZ5/branches/testing/libf/filtrez/filtreg_mod.F90	(revision 1669)
+++ LMDZ5/branches/testing/libf/filtrez/filtreg_mod.F90	(revision 1707)
@@ -1,4 +1,4 @@
 !
-! $Id $
+! $Id$
 !
 MODULE filtreg_mod
@@ -10,6 +10,6 @@
 
   SUBROUTINE inifilr
-  USE mod_filtre_fft
-    !
+  USE mod_filtre_fft, ONLY : use_filtre_fft,Init_filtre_fft
+  USE mod_filtre_fft_loc, ONLY : Init_filtre_fft_loc=>Init_filtre_fft    !
     !    ... H. Upadhyaya, O.Sharma   ...
     !
@@ -541,4 +541,6 @@
        CALL Init_filtre_fft(coefilu,modfrstu,jfiltnu,jfiltsu,  &
                            coefilv,modfrstv,jfiltnv,jfiltsv)
+       CALL Init_filtre_fft_loc(coefilu,modfrstu,jfiltnu,jfiltsu,  &
+                           coefilv,modfrstv,jfiltnv,jfiltsv)
     ENDIF
 
Index: LMDZ5/branches/testing/libf/filtrez/mod_fft.F90
===================================================================
--- LMDZ5/branches/testing/libf/filtrez/mod_fft.F90	(revision 1669)
+++ LMDZ5/branches/testing/libf/filtrez/mod_fft.F90	(revision 1707)
@@ -3,11 +3,15 @@
 #ifdef FFT_MATHKEISAN
   USE mod_fft_mathkeisan
-#elif FFT_FFTW
+#else
+#ifdef FFT_FFTW
   USE mod_fft_fftw
-#elif FFT_MKL
+#else
+#ifdef FFT_MKL
   USE mod_fft_mkl
 #else
   USE mod_fft_wrapper
 #endif
+#endif
+#endif
 
 END MODULE mod_fft
Index: LMDZ5/branches/testing/libf/filtrez/mod_filtre_fft_loc.F90
===================================================================
--- LMDZ5/branches/testing/libf/filtrez/mod_filtre_fft_loc.F90	(revision 1707)
+++ LMDZ5/branches/testing/libf/filtrez/mod_filtre_fft_loc.F90	(revision 1707)
@@ -0,0 +1,343 @@
+MODULE mod_filtre_fft_loc
+
+  LOGICAL,SAVE :: use_filtre_fft
+  REAL,SAVE,ALLOCATABLE :: Filtre_u(:,:)
+  REAL,SAVE,ALLOCATABLE :: Filtre_v(:,:)
+  REAL,SAVE,ALLOCATABLE :: Filtre_inv(:,:)
+
+CONTAINS
+  
+  SUBROUTINE Init_filtre_fft(coeffu,modfrstu,jfiltnu,jfiltsu,coeffv,modfrstv,jfiltnv,jfiltsv)
+    USE mod_fft
+    IMPLICIT NONE
+    include 'dimensions.h'
+    REAL,   INTENT(IN) :: coeffu(iim,jjm)
+    INTEGER,INTENT(IN) :: modfrstu(jjm)
+    INTEGER,INTENT(IN) :: jfiltnu
+    INTEGER,INTENT(IN) :: jfiltsu
+    REAL,   INTENT(IN) :: coeffv(iim,jjm)
+    INTEGER,INTENT(IN) :: modfrstv(jjm)
+    INTEGER,INTENT(IN) :: jfiltnv
+    INTEGER,INTENT(IN) :: jfiltsv
+    
+    INTEGER            :: index_vp(iim)
+    INTEGER            :: i,j
+    
+    index_vp(1)=1
+    DO i=1,iim/2
+      index_vp(i+1)=i*2
+    ENDDO
+    
+    DO i=1,iim/2-1
+      index_vp(iim/2+i+1)=iim-2*i+1
+    ENDDO
+    
+    ALLOCATE(Filtre_u(iim,jjm))
+    ALLOCATE(Filtre_v(iim,jjm))
+    ALLOCATE(Filtre_inv(iim,jjm))
+  
+    
+    DO j=2,jfiltnu
+      DO i=1,iim
+        IF (index_vp(i) < modfrstu(j)) THEN
+          Filtre_u(i,j)=0
+        ELSE
+          Filtre_u(i,j)=coeffu(index_vp(i),j)
+        ENDIF
+      ENDDO
+    ENDDO
+    
+    DO j=jfiltsu,jjm
+      DO i=1,iim
+        IF (index_vp(i) < modfrstu(j)) THEN
+          Filtre_u(i,j)=0
+        ELSE
+          Filtre_u(i,j)=coeffu(index_vp(i),j)
+        ENDIF
+      ENDDO
+    ENDDO
+ 
+    DO j=1,jfiltnv
+      DO i=1,iim
+        IF (index_vp(i) < modfrstv(j)) THEN
+          Filtre_v(i,j)=0
+        ELSE
+          Filtre_v(i,j)=coeffv(index_vp(i),j)
+        ENDIF
+      ENDDO
+    ENDDO
+   
+    DO j=jfiltsv,jjm
+      DO i=1,iim
+        IF (index_vp(i) < modfrstv(j)) THEN
+          Filtre_v(i,j)=0
+        ELSE
+          Filtre_v(i,j)=coeffv(index_vp(i),j)
+        ENDIF
+      ENDDO
+    ENDDO
+         
+    DO j=2,jfiltnu
+      DO i=1,iim
+        IF (index_vp(i) < modfrstu(j)) THEN
+          Filtre_inv(i,j)=0
+        ELSE
+          Filtre_inv(i,j)=coeffu(index_vp(i),j)/(1.+coeffu(index_vp(i),j))
+        ENDIF
+      ENDDO
+    ENDDO
+
+    DO j=jfiltsu,jjm
+      DO i=1,iim
+        IF (index_vp(i) < modfrstu(j)) THEN
+          Filtre_inv(i,j)=0
+        ELSE
+          Filtre_inv(i,j)=coeffu(index_vp(i),j)/(1.+coeffu(index_vp(i),j))
+        ENDIF
+      ENDDO
+    ENDDO
+    
+    
+!    CALL Init_FFT(iim,(jjm+1)*(llm+1))
+        
+    
+  END SUBROUTINE Init_filtre_fft
+  
+  SUBROUTINE Filtre_u_fft(vect_inout,jjb,jje,jj_begin,jj_end,nbniv)
+    USE mod_fft
+#ifdef CPP_PARA
+    USE parallel,ONLY : OMP_CHUNK
+#endif
+    IMPLICIT NONE
+    include 'dimensions.h'
+    INTEGER,INTENT(IN) :: jjb
+    INTEGER,INTENT(IN) :: jje
+    INTEGER,INTENT(IN) :: jj_begin
+    INTEGER,INTENT(IN) :: jj_end
+    INTEGER,INTENT(IN) :: nbniv
+    REAL,INTENT(INOUT) :: vect_inout(iim+1,jjb:jje,nbniv)
+
+    REAL               :: vect(iim+inc,jj_end-jj_begin+1,nbniv)
+    COMPLEX            :: TF_vect(iim/2+1,jj_end-jj_begin+1,nbniv)
+    INTEGER            :: nb_vect
+    INTEGER :: i,j,l
+    INTEGER :: ll_nb
+!    REAL               :: vect_tmp(iim+inc,jj_end-jj_begin+1,nbniv)
+    
+    ll_nb=0
+!$OMP DO SCHEDULE(STATIC,OMP_CHUNK)
+    DO l=1,nbniv
+      ll_nb=ll_nb+1
+      DO j=1,jj_end-jj_begin+1
+        DO i=1,iim+1
+          vect(i,j,ll_nb)=vect_inout(i,j+jj_begin-1,l)
+        ENDDO
+      ENDDO
+    ENDDO
+!$OMP END DO NOWAIT
+
+    nb_vect=(jj_end-jj_begin+1)*ll_nb
+
+!    vect_tmp=vect
+
+    CALL FFT_forward(vect,TF_vect,nb_vect)
+
+!    CALL FFT_forward(vect,TF_vect_test,nb_vect)
+!      PRINT *,"XXXXXXXXXXXXX Filtre_u_FFT xxxxxxxxxxxx"
+!      DO j=1,jj_end-jj_begin+1
+!      DO i=1,iim/2+1
+!         PRINT *,"====",i,j,"----->",TF_vect_test(i,j,1)
+!       ENDDO
+!      ENDDO
+
+    DO l=1,ll_nb
+      DO j=1,jj_end-jj_begin+1
+        DO i=1,iim/2+1
+          TF_vect(i,j,l)=TF_vect(i,j,l)*Filtre_u(i,jj_begin+j-1)
+        ENDDO
+      ENDDO
+    ENDDO
+       
+    CALL FFT_backward(TF_vect,vect,nb_vect)
+!    CALL FFT_backward(TF_vect_test,vect_test,nb_vect)
+          
+!      PRINT *,"XXXXXXXXXXXXX Filtre_u_FFT xxxxxxxxxxxx"
+!      DO j=1,jj_end-jj_begin+1
+!         DO i=1,iim
+!           PRINT *,"====",i,j,"----->",vect_test(i,j,1)
+!         ENDDO
+!      ENDDO
+
+    ll_nb=0
+!$OMP DO SCHEDULE(STATIC,OMP_CHUNK)
+    DO l=1,nbniv
+      ll_nb=ll_nb+1
+      DO j=1,jj_end-jj_begin+1
+        DO i=1,iim+1
+          vect_inout(i,j+jj_begin-1,l)=vect(i,j,ll_nb)
+        ENDDO
+      ENDDO
+    ENDDO
+!$OMP END DO NOWAIT
+
+  END SUBROUTINE Filtre_u_fft
+  
+
+  SUBROUTINE Filtre_v_fft(vect_inout,jjb,jje,jj_begin,jj_end,nbniv)
+    USE mod_fft
+#ifdef CPP_PARA
+    USE parallel,ONLY : OMP_CHUNK
+#endif
+    IMPLICIT NONE
+    INCLUDE 'dimensions.h'
+    INTEGER,INTENT(IN) :: jjb
+    INTEGER,INTENT(IN) :: jje
+    INTEGER,INTENT(IN) :: jj_begin
+    INTEGER,INTENT(IN) :: jj_end
+    INTEGER,INTENT(IN) :: nbniv
+    REAL,INTENT(INOUT) :: vect_inout(iim+1,jjb:jje,nbniv)
+
+    REAL               :: vect(iim+inc,jj_end-jj_begin+1,nbniv)
+    COMPLEX            :: TF_vect(iim/2+1,jj_end-jj_begin+1,nbniv)
+    INTEGER            :: nb_vect
+    INTEGER :: i,j,l
+    INTEGER :: ll_nb
+    
+    ll_nb=0
+!$OMP DO SCHEDULE(STATIC,OMP_CHUNK)
+    DO l=1,nbniv
+      ll_nb=ll_nb+1
+      DO j=1,jj_end-jj_begin+1
+        DO i=1,iim+1
+          vect(i,j,ll_nb)=vect_inout(i,j+jj_begin-1,l)
+        ENDDO
+      ENDDO
+    ENDDO
+!$OMP END DO NOWAIT
+
+    
+    nb_vect=(jj_end-jj_begin+1)*ll_nb
+
+    CALL FFT_forward(vect,TF_vect,nb_vect)
+  
+    DO l=1,ll_nb
+      DO j=1,jj_end-jj_begin+1
+        DO i=1,iim/2+1
+          TF_vect(i,j,l)=TF_vect(i,j,l)*Filtre_v(i,jj_begin+j-1)
+        ENDDO
+      ENDDO
+    ENDDO
+  
+    CALL FFT_backward(TF_vect,vect,nb_vect)
+    
+    
+    ll_nb=0
+!$OMP DO SCHEDULE(STATIC,OMP_CHUNK)
+    DO l=1,nbniv
+      ll_nb=ll_nb+1
+      DO j=1,jj_end-jj_begin+1
+        DO i=1,iim+1
+          vect_inout(i,j+jj_begin-1,l)=vect(i,j,ll_nb)
+        ENDDO
+      ENDDO
+    ENDDO
+!$OMP END DO NOWAIT
+  
+  END SUBROUTINE Filtre_v_fft
+
+
+  SUBROUTINE Filtre_inv_fft(vect_inout,jjb,jje,jj_begin,jj_end,nbniv)
+    USE mod_fft
+#ifdef CPP_PARA
+    USE parallel,ONLY : OMP_CHUNK
+#endif
+    IMPLICIT NONE
+    INCLUDE 'dimensions.h'
+    INTEGER,INTENT(IN) :: jjb
+    INTEGER,INTENT(IN) :: jje
+    INTEGER,INTENT(IN) :: jj_begin
+    INTEGER,INTENT(IN) :: jj_end
+    INTEGER,INTENT(IN) :: nbniv
+    REAL,INTENT(INOUT) :: vect_inout(iim+1,jjb:jje,nbniv)
+
+    REAL               :: vect(iim+inc,jj_end-jj_begin+1,nbniv)
+    COMPLEX            :: TF_vect(iim/2+1,jj_end-jj_begin+1,nbniv)
+    INTEGER            :: nb_vect
+    INTEGER :: i,j,l
+    INTEGER :: ll_nb
+    
+    ll_nb=0
+!$OMP DO SCHEDULE(STATIC,OMP_CHUNK)
+    DO l=1,nbniv
+      ll_nb=ll_nb+1
+      DO j=1,jj_end-jj_begin+1
+        DO i=1,iim+1
+          vect(i,j,ll_nb)=vect_inout(i,j+jj_begin-1,l)
+        ENDDO
+      ENDDO
+    ENDDO
+!$OMP END DO NOWAIT
+
+    nb_vect=(jj_end-jj_begin+1)*ll_nb
+
+    CALL FFT_forward(vect,TF_vect,nb_vect)
+  
+    DO l=1,ll_nb
+      DO j=1,jj_end-jj_begin+1
+        DO i=1,iim/2+1
+          TF_vect(i,j,l)=TF_vect(i,j,l)*Filtre_inv(i,jj_begin+j-1)
+        ENDDO
+      ENDDO
+    ENDDO
+  
+    CALL FFT_backward(TF_vect,vect,nb_vect)
+
+    ll_nb=0
+!$OMP DO SCHEDULE(STATIC,OMP_CHUNK)
+    DO l=1,nbniv
+      ll_nb=ll_nb+1
+      DO j=1,jj_end-jj_begin+1
+        DO i=1,iim+1
+          vect_inout(i,j+jj_begin-1,l)=vect(i,j,ll_nb)
+        ENDDO
+      ENDDO
+    ENDDO
+!$OMP END DO NOWAIT
+
+  END SUBROUTINE Filtre_inv_fft  
+  
+  
+!  SUBROUTINE get_ll_index(nbniv,ll_index,ll_nb)
+!  IMPLICIT NONE
+!    INTEGER,INTENT(IN)  :: nbniv
+!    INTEGER,INTENT(OUT) :: ll_index(nbniv)
+!    INTEGER,INTENT(OUT) :: ll_nb
+!
+!    INTEGER :: l,ll_begin, ll_end
+!   INTEGER :: omp_rank,omp_size
+!   INTEGER :: OMP_GET_NUM_THREADS
+!   INTEGER :: omp_chunk
+!   EXTERNAL OMP_GET_NUM_THREADS
+!   INTEGER :: OMP_GET_THREAD_NUM
+!   EXTERNAL OMP_GET_THREAD_NUM
+!
+!   
+!   omp_size=OMP_GET_NUM_THREADS()
+!   omp_rank=OMP_GET_THREAD_NUM()    
+!   omp_chunk=nbniv/omp_size+min(1,MOD(nbniv,omp_size))
+!   
+!   ll_begin=omp_rank*OMP_CHUNK+1
+!   ll_nb=0
+!   DO WHILE (ll_begin<=nbniv)
+!     ll_end=min(ll_begin+OMP_CHUNK-1,nbniv)
+!     DO l=ll_begin,ll_end
+!       ll_nb=ll_nb+1
+!       ll_index(ll_nb)=l
+!     ENDDO
+!     ll_begin=ll_begin+omp_size*OMP_CHUNK
+!   ENDDO
+!  
+!  END SUBROUTINE get_ll_index
+   
+END MODULE mod_filtre_fft_loc
+ 
Index: LMDZ5/branches/testing/libf/phy1d/1DUTILS.h_no_writelim
===================================================================
--- LMDZ5/branches/testing/libf/phy1d/1DUTILS.h_no_writelim	(revision 1669)
+++ LMDZ5/branches/testing/libf/phy1d/1DUTILS.h_no_writelim	(revision 1707)
@@ -52,5 +52,5 @@
 !Config         (defaut sortie standard = 6)
       lunout=6
-      CALL getin('lunout', lunout)
+!      CALL getin('lunout', lunout)
       IF (lunout /= 5 .and. lunout /= 6) THEN
         OPEN(lunout,FILE='lmdz.out')
Index: LMDZ5/branches/testing/libf/phy1d/1DUTILS.h_with_writelim
===================================================================
--- LMDZ5/branches/testing/libf/phy1d/1DUTILS.h_with_writelim	(revision 1669)
+++ LMDZ5/branches/testing/libf/phy1d/1DUTILS.h_with_writelim	(revision 1707)
@@ -52,5 +52,5 @@
 !Config         (defaut sortie standard = 6)
       lunout=6
-      CALL getin('lunout', lunout)
+!      CALL getin('lunout', lunout)
       IF (lunout /= 5 .and. lunout /= 6) THEN
         OPEN(lunout,FILE='lmdz.out')
Index: LMDZ5/branches/testing/libf/phy1d/1DUTILS.h_with_writelim_old
===================================================================
--- LMDZ5/branches/testing/libf/phy1d/1DUTILS.h_with_writelim_old	(revision 1669)
+++ LMDZ5/branches/testing/libf/phy1d/1DUTILS.h_with_writelim_old	(revision 1707)
@@ -52,5 +52,5 @@
 !Config         (defaut sortie standard = 6)
       lunout=6
-      CALL getin('lunout', lunout)
+!      CALL getin('lunout', lunout)
       IF (lunout /= 5 .and. lunout /= 6) THEN
         OPEN(lunout,FILE='lmdz.out')
Index: LMDZ5/branches/testing/libf/phy1d/lmdz1d.F
===================================================================
--- LMDZ5/branches/testing/libf/phy1d/lmdz1d.F	(revision 1669)
+++ LMDZ5/branches/testing/libf/phy1d/lmdz1d.F	(revision 1707)
@@ -711,5 +711,5 @@
 !---------------------------------------------------------------------
 
-      fcoriolis=2.*sin(rpi*rlat(1)/180.)*romega
+      fcoriolis=2.*sin(rpi*xlat/180.)*romega
 
        if (forcing_radconv) then
Index: LMDZ5/branches/testing/libf/phydev/comcstphy.F90
===================================================================
--- LMDZ5/branches/testing/libf/phydev/comcstphy.F90	(revision 1707)
+++ LMDZ5/branches/testing/libf/phydev/comcstphy.F90	(revision 1707)
@@ -0,0 +1,8 @@
+module comcstphy
+  
+  real :: rradius ! planet radius (m)
+  real :: rr      ! recuced gas constant: R/molar mass of atm
+  real :: rg      ! gravity
+  real :: rcpp    ! specific heat of the atmosphere
+
+end module comcstphy
Index: LMDZ5/branches/testing/libf/phydev/comcstphy.h
===================================================================
--- LMDZ5/branches/testing/libf/phydev/comcstphy.h	(revision 1669)
+++ 	(revision )
@@ -1,2 +1,0 @@
-      real rradius,rr,rg,rcpp
-      common/comcstphy/rradius,rr,rg,rcpp
Index: LMDZ5/branches/testing/libf/phydev/gr_fi_ecrit.F
===================================================================
--- LMDZ5/branches/testing/libf/phydev/gr_fi_ecrit.F	(revision 1707)
+++ LMDZ5/branches/testing/libf/phydev/gr_fi_ecrit.F	(revision 1707)
@@ -0,0 +1,27 @@
+!
+! $Id $
+!
+      SUBROUTINE gr_fi_ecrit(nfield,nlon,iim,jjmp1,fi,ecrit)
+      IMPLICIT NONE
+c
+c Transfer a field from the full physics grid
+c to a full 2D (lonxlat) grid suitable for outputs
+c
+      INTEGER,INTENT(IN) :: nfield,nlon,iim,jjmp1
+      REAL,INTENT(IN) :: fi(nlon,nfield)
+      REAL,INTENT(out) :: ecrit(iim*jjmp1,nfield)
+c
+      INTEGER :: i, n, ig, jjm
+c
+      jjm = jjmp1 - 1
+      DO n = 1, nfield
+         DO i=1,iim
+            ecrit(i,n) = fi(1,n)
+            ecrit(i+jjm*iim,n) = fi(nlon,n)
+         ENDDO
+         DO ig = 1, nlon - 2
+           ecrit(iim+ig,n) = fi(1+ig,n)
+         ENDDO
+      ENDDO
+
+      END
Index: LMDZ5/branches/testing/libf/phydev/iniphysiq.F
===================================================================
--- LMDZ5/branches/testing/libf/phydev/iniphysiq.F	(revision 1669)
+++ LMDZ5/branches/testing/libf/phydev/iniphysiq.F	(revision 1707)
@@ -2,15 +2,15 @@
 ! $Id: iniphysiq.F 1403 2010-07-01 09:02:53Z fairhead $
 !
-c
-c
       SUBROUTINE iniphysiq(ngrid,nlayer,
      $           punjours,
      $           pdayref,ptimestep,
      $           plat,plon,parea,pcu,pcv,
-     $           prad,pg,pr,pcpp)
-      USE dimphy
-      USE mod_grid_phy_lmdz
-      USE mod_phys_lmdz_para
-      USE comgeomphy
+     $           prad,pg,pr,pcpp,iflag_phys)
+      USE dimphy, only : klev
+      USE mod_grid_phy_lmdz, only : klon_glo
+      USE mod_phys_lmdz_para, only : klon_omp,klon_omp_begin,
+     &                               klon_omp_end,klon_mpi_begin
+      USE comgeomphy, only : airephy,cuphy,cvphy,rlond,rlatd
+      USE comcstphy, only : rradius,rg,rr,rcpp
 
       IMPLICIT NONE
@@ -18,18 +18,7 @@
 c=======================================================================
 c
-c   subject:
-c   --------
+c   Initialisation of the physical constants and some positional and 
+c   geometrical arrays for the physics
 c
-c   Initialisation for the physical parametrisations of the LMD 
-c   martian atmospheric general circulation modele.
-c
-c   author: Frederic Hourdin 15 / 10 /93
-c   -------
-c
-c   arguments:
-c   ----------
-c
-c   input:
-c   ------
 c
 c    ngrid                 Size of the horizontal grid.
@@ -37,36 +26,38 @@
 c    nlayer                Number of vertical layers.
 c    pdayref               Day of reference for the simulation
-c    firstcall             True at the first call
-c    lastcall              True at the last call
-c    pday                  Number of days counted from the North. Spring
-c                          equinoxe.
 c
 c=======================================================================
-c
-c-----------------------------------------------------------------------
-c   declarations:
-c   -------------
+ 
  
 cym#include "dimensions.h"
 cym#include "dimphy.h"
 cym#include "comgeomphy.h"
-#include "comcstphy.h"
-      REAL prad,pg,pr,pcpp,punjours
- 
-      INTEGER ngrid,nlayer
-      REAL plat(ngrid),plon(ngrid),parea(klon_glo)
-      REAL pcu(klon_glo),pcv(klon_glo)
-      INTEGER pdayref
+#include "iniprint.h"
+
+      REAL,INTENT(IN) :: prad ! radius of the planet (m)
+      REAL,INTENT(IN) :: pg ! gravitational acceleration (m/s2)
+      REAL,INTENT(IN) :: pr ! ! reduced gas constant R/mu
+      REAL,INTENT(IN) :: pcpp ! specific heat Cp
+      REAL,INTENT(IN) :: punjours ! length (in s) of a standard day
+      INTEGER,INTENT(IN) :: ngrid ! number of horizontal grid points in the physics
+      INTEGER,INTENT(IN) :: nlayer ! number of atmospheric layers
+      REAL,INTENT(IN) :: plat(ngrid) ! latitudes of the physics grid
+      REAL,INTENT(IN) :: plon(ngrid) ! longitudes of the physics grid
+      REAL,INTENT(IN) :: parea(klon_glo) ! area (m2)
+      REAL,INTENT(IN) :: pcu(klon_glo) ! cu coeff. (u_covariant = cu * u)
+      REAL,INTENT(IN) :: pcv(klon_glo) ! cv coeff. (v_covariant = cv * v)
+      INTEGER,INTENT(IN) :: pdayref ! reference day of for the simulation
+      REAL,INTENT(IN) :: ptimestep !physics time step (s)
+      INTEGER,INTENT(IN) :: iflag_phys ! type of physics to be called
+
       INTEGER :: ibegin,iend,offset
- 
-      REAL ptimestep
       CHARACTER (LEN=20) :: modname='iniphysiq'
       CHARACTER (LEN=80) :: abort_message
  
       IF (nlayer.NE.klev) THEN
-         PRINT*,'STOP in inifis'
-         PRINT*,'Probleme de dimensions :'
-         PRINT*,'nlayer     = ',nlayer
-         PRINT*,'klev   = ',klev
+         write(lunout,*) 'STOP in ',trim(modname)
+         write(lunout,*) 'Problem with dimensions :'
+         write(lunout,*) 'nlayer     = ',nlayer
+         write(lunout,*) 'klev   = ',klev
          abort_message = ''
          CALL abort_gcm (modname,abort_message,1)
@@ -74,13 +65,14 @@
 
       IF (ngrid.NE.klon_glo) THEN
-         PRINT*,'STOP in inifis'
-         PRINT*,'Probleme de dimensions :'
-         PRINT*,'ngrid     = ',ngrid
-         PRINT*,'klon   = ',klon_glo
+         write(lunout,*) 'STOP in ',trim(modname)
+         write(lunout,*) 'Problem with dimensions :'
+         write(lunout,*) 'ngrid     = ',ngrid
+         write(lunout,*) 'klon   = ',klon_glo
          abort_message = ''
          CALL abort_gcm (modname,abort_message,1)
       ENDIF
-c$OMP PARALLEL PRIVATE(ibegin,iend) 
-c$OMP+         SHARED(parea,pcu,pcv,plon,plat)
+
+!$OMP PARALLEL PRIVATE(ibegin,iend) 
+!$OMP+         SHARED(parea,pcu,pcv,plon,plat)
       
       offset=klon_mpi_begin-1
@@ -92,6 +84,5 @@
       rlatd(1:klon_omp)=plat(offset+klon_omp_begin:offset+klon_omp_end)
 
-!     call suphel
-!     prad,pg,pr,pcpp
+! copy some fundamental parameters to physics
       rradius=prad
       rg=pg
@@ -99,16 +90,21 @@
       rcpp=pcpp
 
-      
+!$OMP END PARALLEL
 
-c$OMP END PARALLEL
+!      print*,'ATTENTION !!! TRAVAILLER SUR INIPHYSIQ'
+!      print*,'CONTROLE DES LATITUDES, LONGITUDES, PARAMETRES ...'
 
-      print*,'ATTENTION !!! TRAVAILLER SUR INIPHYSIQ'
-      print*,'CONTROLE DES LATITUDES, LONGITUDES, PARAMETRES ...'
+! Additional initializations for aquaplanets 
+!$OMP PARALLEL
+      if (iflag_phys>=100) then
+        call iniaqua(klon_omp,rlatd,rlond,iflag_phys)
+      endif
+!$OMP END PARALLEL
 
-      RETURN
-9999  CONTINUE
-      abort_message ='Cette version demande les fichier rnatur.dat
-     & et surf.def'
-      CALL abort_gcm (modname,abort_message,1)
+!      RETURN
+!9999  CONTINUE
+!      abort_message ='Cette version demande les fichier rnatur.dat
+!     & et surf.def'
+!      CALL abort_gcm (modname,abort_message,1)
 
       END
Index: LMDZ5/branches/testing/libf/phydev/iostart.F90
===================================================================
--- LMDZ5/branches/testing/libf/phydev/iostart.F90	(revision 1707)
+++ LMDZ5/branches/testing/libf/phydev/iostart.F90	(revision 1707)
@@ -0,0 +1,1 @@
+link ../phylmd/iostart.F90
Index: LMDZ5/branches/testing/libf/phydev/phyaqua.F
===================================================================
--- LMDZ5/branches/testing/libf/phydev/phyaqua.F	(revision 1669)
+++ LMDZ5/branches/testing/libf/phydev/phyaqua.F	(revision 1707)
@@ -1,26 +1,41 @@
-! Routines complementaires pour la physique planetaire.
-
+!
+! $Id: $
+!
 
       subroutine iniaqua(nlon,latfi,lonfi,iflag_phys)
 
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-!  Creation d'un etat initial et de conditions aux limites 
-!  (resp startphy.nc et limit.nc) pour des configurations idealisees 
-! du modele LMDZ dans sa version terrestre.
-!  iflag_phys est un parametre qui controle
-!  iflag_phys = N  
-!    de 100 a 199 : aqua planetes avec SST forcees
-!                 N-100 determine le type de SSTs
-!    de 200 a 299 : terra planetes avec Ts calcule
-!        
+!  Create an initial state (startphy.nc) for the physics
+!  Usefull for idealised cases (e.g. aquaplanets or testcases)
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
+      use phys_state_var_mod, only : rlat,rlon,
+     &                               phys_state_var_init
+      use mod_phys_lmdz_para, only : klon_omp
+      use comgeomphy, only : rlond,rlatd
+      implicit none
+      
+      integer,intent(in) :: nlon,iflag_phys
+      real,intent(in) :: lonfi(nlon),latfi(nlon)
 
-      integer nlon,iflag_phys
-cIM ajout latfi, lonfi
-      REAL, DIMENSION (nlon) :: lonfi, latfi
+! local variables
+      real :: pi
+
+! initializations:
+      pi=2.*asin(1.)
+
+      call phys_state_var_init()
+
+      rlat(1:klon_omp)=rlatd(1:klon_omp)*180./pi
+      rlon(1:klon_omp)=rlond(1:klon_omp)*180./pi
 
 
-      return
+! Here you could create an initial condition for the physics
+! ...
+! ... fill in the fields...
+! ...
+! ... and create a "startphy.nc" file
+      CALL phyredem ("startphy.nc")
+
       end
 
Index: LMDZ5/branches/testing/libf/phydev/phyetat0.F90
===================================================================
--- LMDZ5/branches/testing/libf/phydev/phyetat0.F90	(revision 1707)
+++ LMDZ5/branches/testing/libf/phydev/phyetat0.F90	(revision 1707)
@@ -0,0 +1,33 @@
+!
+! $Id $
+!
+subroutine phyetat0(fichnom)
+! Load initial state for the physics
+! and do some resulting initializations
+
+use iostart, only : open_startphy,get_field,close_startphy
+use iophy, only : init_iophy_new
+use phys_state_var_mod, only : rlat,rlon
+
+implicit none
+
+character(len=*),intent(in) :: fichnom ! input file name
+
+! open physics initial state file:
+call open_startphy(fichnom)
+
+! read latitudes
+call get_field("latitude",rlat)
+
+! read longitudes
+call get_field("longitude",rlon)
+
+! read in other variables here ...
+
+! close file
+call close_startphy
+
+! do some more initializations
+call init_iophy_new(rlat,rlon)
+
+end subroutine phyetat0
Index: LMDZ5/branches/testing/libf/phydev/phyredem.F
===================================================================
--- LMDZ5/branches/testing/libf/phydev/phyredem.F	(revision 1707)
+++ LMDZ5/branches/testing/libf/phydev/phyredem.F	(revision 1707)
@@ -0,0 +1,40 @@
+!
+! $Id: $
+!
+      SUBROUTINE phyredem (fichnom)
+
+      use iostart, only : open_restartphy,close_restartphy,
+     &                    put_var,put_field
+      use phys_state_var_mod, only : rlon,rlat
+
+      implicit none
+
+      character(len=*),intent(in) :: fichnom
+
+      integer,parameter :: tab_cntrl_len=100
+      real :: tab_cntrl(tab_cntrl_len)
+
+! open file
+
+      CALL open_restartphy(fichnom)
+
+! tab_cntrl() contains run parameters
+
+      tab_cntrl(:)=0.0
+ 
+
+      CALL put_var("controle","Parametres de controle",tab_cntrl)
+
+! coordinates
+
+      CALL put_field("longitude",
+     .               "Longitudes de la grille physique",rlon)
+     
+      CALL put_field("latitude","Latitudes de la grille physique",rlat)
+
+! close file
+
+      CALL close_restartphy
+!$OMP BARRIER
+
+      END
Index: LMDZ5/branches/testing/libf/phydev/phys_state_var_mod.F90
===================================================================
--- LMDZ5/branches/testing/libf/phydev/phys_state_var_mod.F90	(revision 1707)
+++ LMDZ5/branches/testing/libf/phydev/phys_state_var_mod.F90	(revision 1707)
@@ -0,0 +1,37 @@
+!
+! $Id:  $
+!
+MODULE phys_state_var_mod
+!======================================================================
+! Variables saved in startphy.nc
+!======================================================================
+
+USE dimphy, only : klon
+ 
+
+REAL, ALLOCATABLE, SAVE :: rlat(:), rlon(:)
+!$OMP THREADPRIVATE(rlat,rlon)
+
+CONTAINS
+
+!======================================================================
+  SUBROUTINE phys_state_var_init()
+  use dimphy, only : klon
+
+  if (.not.allocated(rlat)) then
+    ALLOCATE(rlat(klon),rlon(klon))
+  else
+    write(*,*) "phys_state_var_init: warning, rlat already allocated"
+  endif
+  
+  END SUBROUTINE phys_state_var_init
+
+!======================================================================
+  SUBROUTINE phys_state_var_end
+  use dimphy, only : klon
+
+  deallocate(rlat,rlon)
+
+  END SUBROUTINE phys_state_var_end
+
+END MODULE phys_state_var_mod
Index: LMDZ5/branches/testing/libf/phydev/physiq.F90
===================================================================
--- LMDZ5/branches/testing/libf/phydev/physiq.F90	(revision 1669)
+++ LMDZ5/branches/testing/libf/phydev/physiq.F90	(revision 1707)
@@ -11,114 +11,145 @@
      &            , PVteta)
 
-      USE dimphy
-      USE infotrac
-      USE comgeomphy
+      USE dimphy, only : klon,klev
+      USE infotrac, only : nqtot
+      USE comgeomphy, only : rlatd
+      USE comcstphy, only : rg
+      USE iophy, only : histbeg_phy,histwrite_phy
+      USE ioipsl, only : getin,histvert,histdef,histend,ymds2ju
+      USE mod_phys_lmdz_para, only : jj_nb
+      USE phys_state_var_mod, only : phys_state_var_init
 
       IMPLICIT none
-!======================================================================
-! Objet: Moniteur general de la physique du modele
-!======================================================================
+#include "dimensions.h"
+
+      integer,parameter :: jjmp1=jjm+1-1/jjm
+      integer,parameter :: iip1=iim+1
 !
-!  Arguments:
+! Routine argument:
 !
-! nlon----input-I-nombre de points horizontaux
-! nlev----input-I-nombre de couches verticales, doit etre egale a klev
-! debut---input-L-variable logique indiquant le premier passage
-! lafin---input-L-variable logique indiquant le dernier passage
-! jD_cur       -R-jour courant a l'appel de la physique (jour julien)
-! jH_cur       -R-heure courante a l'appel de la physique (jour julien)
-! pdtphys-input-R-pas d'integration pour la physique (seconde)
-! paprs---input-R-pression pour chaque inter-couche (en Pa)
-! pplay---input-R-pression pour le mileu de chaque couche (en Pa)
-! pphi----input-R-geopotentiel de chaque couche (g z) (reference sol)
-! pphis---input-R-geopotentiel du sol
-! presnivs-input_R_pressions approximat. des milieux couches ( en PA)
-! u-------input-R-vitesse dans la direction X (de O a E) en m/s
-! v-------input-R-vitesse Y (de S a N) en m/s
-! t-------input-R-temperature (K)
-! qx------input-R-humidite specifique (kg/kg) et d'autres traceurs
-! d_t_dyn-input-R-tendance dynamique pour "t" (K/s)
-! d_q_dyn-input-R-tendance dynamique pour "q" (kg/kg/s)
-! flxmass_w -input-R- flux de masse verticale
-! d_u-----output-R-tendance physique de "u" (m/s/s)
-! d_v-----output-R-tendance physique de "v" (m/s/s)
-! d_t-----output-R-tendance physique de "t" (K/s)
-! d_qx----output-R-tendance physique de "qx" (kg/kg/s)
-! d_ps----output-R-tendance physique de la pression au sol
-!IM
-! PVteta--output-R-vorticite potentielle a des thetas constantes
-!======================================================================
-#include "dimensions.h"
-#include "comcstphy.h"
+      integer,intent(in) :: nlon ! number of atmospheric colums
+      integer,intent(in) :: nlev ! number of vertical levels (should be =klev)
+      real,intent(in) :: jD_cur ! current day number (Julian day)
+      real,intent(in) :: jH_cur ! current time of day (as fraction of day)
+      logical,intent(in) :: debut ! signals first call to physics
+      logical,intent(in) :: lafin ! signals last call to physics
+      real,intent(in) :: pdtphys ! physics time step (s)
+      real,intent(in) :: paprs(klon,klev+1) ! interlayer pressure (Pa)
+      real,intent(in) :: pplay(klon,klev) ! mid-layer pressure (Pa)
+      real,intent(in) :: pphi(klon,klev) ! geopotential at mid-layer
+      real,intent(in) :: pphis(klon) ! surface geopotential
+      real,intent(in) :: presnivs(klev) ! pseudo-pressure (Pa) of mid-layers
+      integer,parameter :: longcles=20
+      real,intent(in) :: clesphy0(longcles) ! Not used
+      real,intent(in) :: u(klon,klev) ! eastward zonal wind (m/s)
+      real,intent(in) :: v(klon,klev) ! northward meridional wind (m/s)
+      real,intent(in) :: t(klon,klev) ! temperature (K)
+      real,intent(in) :: qx(klon,klev,nqtot) ! tracers (.../kg_air)
+      real,intent(in) :: flxmass_w(klon,klev) ! vertical mass flux
+      real,intent(out) :: d_u(klon,klev) ! physics tendency on u (m/s/s)
+      real,intent(out) :: d_v(klon,klev) ! physics tendency on v (m/s/s)
+      real,intent(out) :: d_t(klon,klev) ! physics tendency on t (K/s)
+      real,intent(out) :: d_qx(klon,klev,nqtot) ! physics tendency on tracers
+      real,intent(out) :: d_ps(klon) ! physics tendency on surface pressure
+      real,intent(in) :: dudyn(iim+1,jjmp1,klev) ! Not used
+!FH! REAL PVteta(klon,nbteta)
+!      REAL PVteta(klon,1)
+      real,intent(in) :: PVteta(klon,3) ! Not used ; should match definition
+                                        ! in calfis.F
 
-      integer jjmp1
-      parameter (jjmp1=jjm+1-1/jjm)
-      integer iip1
-      parameter (iip1=iim+1)
+integer,save :: itau=0 ! counter to count number of calls to physics
+!$OMP THREADPRIVATE(itau)
+real :: temp_newton(klon,klev)
+integer :: k
+logical, save :: first=.true.
+!$OMP THREADPRIVATE(first)
 
-      INTEGER ivap          ! indice de traceurs pour vapeur d'eau
-      PARAMETER (ivap=1)
-      INTEGER iliq          ! indice de traceurs pour eau liquide
-      PARAMETER (iliq=2)
+! For I/Os
+integer :: itau0
+real :: zjulian
+real :: dtime
+integer :: nhori ! horizontal coordinate ID
+integer,save :: nid_hist ! output file ID
+!$OMP THREADPRIVATE(nid_hist)
+integer :: zvertid ! vertical coordinate ID
+integer,save :: iwrite_phys ! output every iwrite_phys physics step
+!$OMP THREADPRIVATE(iwrite_phys)
+real :: t_ops ! frequency of the IOIPSL operations (eg average over...)
+real :: t_wrt ! frequency of the IOIPSL outputs
 
-!
-!
-! Variables argument:
-!
-      INTEGER nlon
-      INTEGER nlev
-      REAL, intent(in):: jD_cur, jH_cur
+! initializations
+if (debut) then ! Things to do only for the first call to physics 
+! load initial conditions for physics (including the grid)
+  call phys_state_var_init() ! some initializations, required before calling phyetat0
+  call phyetat0("startphy.nc")
 
-      REAL pdtphys
-      LOGICAL debut, lafin
-      REAL paprs(klon,klev+1)
-      REAL pplay(klon,klev)
-      REAL pphi(klon,klev)
-      REAL pphis(klon)
-      REAL presnivs(klev)
-      REAL znivsig(klev)
-      real pir
+! Initialize outputs:
+  itau0=0
+  iwrite_phys=1 !default: output every physics timestep
+  call getin("iwrite_phys",iwrite_phys)
+  t_ops=pdtphys*iwrite_phys ! frequency of the IOIPSL operation
+  t_wrt=pdtphys*iwrite_phys ! frequency of the outputs in the file
+  ! compute zjulian for annee0=1979 and month=1 dayref=1 and hour=0.0
+  !CALL ymds2ju(annee0, month, dayref, hour, zjulian)
+  call ymds2ju(1979, 1, 1, 0.0, zjulian)
+  dtime=pdtphys
+  call histbeg_phy("histins.nc",itau0,zjulian,dtime,nhori,nid_hist)
+!$OMP MASTER
+  ! define vertical coordinate
+  call histvert(nid_hist,"presnivs","Vertical levels","Pa",klev, &
+                presnivs,zvertid,'down')
+  ! define variables which will be written in "histins.nc" file
+  call histdef(nid_hist,'temperature','Atmospheric temperature','K', &
+               iim,jj_nb,nhori,klev,1,klev,zvertid,32, &
+               'inst(X)',t_ops,t_wrt)
+  call histdef(nid_hist,'u','Eastward Zonal Wind','m/s', &
+               iim,jj_nb,nhori,klev,1,klev,zvertid,32, &
+               'inst(X)',t_ops,t_wrt)
+  call histdef(nid_hist,'v','Northward Meridional Wind','m/s', &
+               iim,jj_nb,nhori,klev,1,klev,zvertid,32, &
+               'inst(X)',t_ops,t_wrt)
+  call histdef(nid_hist,'ps','Surface Pressure','Pa', &
+               iim,jj_nb,nhori,1,1,1,zvertid,32, &
+               'inst(X)',t_ops,t_wrt)
+  ! end definition sequence
+  call histend(nid_hist)
+!$OMP END MASTER
+endif ! of if (debut)
 
-      REAL u(klon,klev)
-      REAL v(klon,klev)
-      REAL t(klon,klev),theta(klon,klev)
-      REAL qx(klon,klev,nqtot)
-      REAL flxmass_w(klon,klev)
-      REAL omega(klon,klev) ! vitesse verticale en Pa/s
-      REAL d_u(klon,klev)
-      REAL d_v(klon,klev)
-      REAL d_t(klon,klev)
-      REAL d_qx(klon,klev,nqtot)
-      REAL d_ps(klon)
-      real da(klon,klev),phi(klon,klev,klev),mp(klon,klev)
-!IM definition dynamique o_trac dans phys_output_open
-!      type(ctrl_out) :: o_trac(nqtot)
-!FH! REAL PVteta(klon,nbteta)
-      REAL PVteta(klon,1)
-      REAL dudyn(iim+1,jjmp1,klev)
+! increment counter itau
+itau=itau+1
 
-    INTEGER        longcles
-    PARAMETER    ( longcles = 20 )
+! set all tendencies to zero
+d_u(1:klon,1:klev)=0.
+d_v(1:klon,1:klev)=0.
+d_t(1:klon,1:klev)=0.
+d_qx(1:klon,1:klev,1:nqtot)=0.
+d_ps(1:klon)=0.
 
-real temp_newton(klon,klev)
-integer k
-logical, save :: first=.true.
-
-      REAL clesphy0( longcles      )
-
-d_u=0.
-d_v=0.
-d_t=0.
-d_qx=0.
-d_ps=0.
-
-     d_u(:,1)=-u(:,1)/86400.
-     do k=1,klev
-        temp_newton(:,k)=280.+cos(rlatd(:))*40.-pphi(:,k)/rg*6.e-3
-        d_t(:,k)=(temp_newton(:,k)-t(:,k))/1.e5
-     enddo
+! compute tendencies to return to the dynamics:
+! "friction" on the first layer
+d_u(1:klon,1)=-u(1:klon,1)/86400.
+d_v(1:klon,1)=-v(1:klon,1)/86400.
+! newtonian relaxation towards temp_newton()
+do k=1,klev
+  temp_newton(1:klon,k)=280.+cos(rlatd(1:klon))*40.-pphi(1:klon,k)/rg*6.e-3
+  d_t(1:klon,k)=(temp_newton(1:klon,k)-t(1:klon,k))/1.e5
+enddo
 
 
-      print*,'COUCOU PHYDEV'
-      return
-      end
+!print*,'PHYDEV: itau=',itau
+
+! write some outputs:
+if (modulo(itau,iwrite_phys)==0) then
+  call histwrite_phy(nid_hist,.false.,"temperature",itau,t)
+  call histwrite_phy(nid_hist,.false.,"u",itau,u)
+  call histwrite_phy(nid_hist,.false.,"v",itau,v)
+  call histwrite_phy(nid_hist,.false.,"ps",itau,paprs(:,1))
+endif
+
+! if lastcall, then it is time to write "restartphy.nc" file
+if (lafin) then
+  call phyredem("restartphy.nc")
+endif
+
+end
Index: LMDZ5/branches/testing/libf/phylmd/CFMIP_point_locations_mod.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/CFMIP_point_locations_mod.F90	(revision 1669)
+++ 	(revision )
@@ -1,121 +1,0 @@
-MODULE CFMIP_point_locations
-  IMPLICIT NONE
-
-CONTAINS
-
- SUBROUTINE read_CFMIP_point_locations(npCFMIP, tab, lonCFMIP, latCFMIP)
-  IMPLICIT none
-  INTEGER :: npCFMIP
-  REAL, DIMENSION(npCFMIP) :: lonCFMIP, latCFMIP
-  INTEGER :: tab(npCFMIP), np
-
-  WRITE(*,*) 'npCFMIP=',npCFMIP
-! OPEN(20, file="pointlocations.txt",status='old')
-  OPEN(20, file="pointlocations.txt",status='old',err=999)
-  OPEN(21, file="pointlocations_lon180.txt")
-  np=1
-10 READ(20,*) tab(np), lonCFMIP(np), latCFMIP(np)
-!!! passage de 0-360 a -180/180
-   IF (lonCFMIP(np).GT.180.) THEN
-    lonCFMIP(np)=lonCFMIP(np)-360.
-   ENDIF 
-   WRITE(21,*) np, lonCFMIP(np), latCFMIP(np)
-   np=np+1
-   IF(np.LE.npCFMIP) THEN 
-    GOTO 10
-   ENDIF
-   CLOSE(20)
-   CLOSE(21)
-999 RETURN
- END SUBROUTINE read_CFMIP_point_locations
-
- SUBROUTINE LMDZ_CFMIP_point_locations(npCFMIP, lonCFMIP, latCFMIP, &
-  tabijGCM, lonGCM, latGCM, ipt, jpt)
-  USE dimphy
-  USE iophy
-  USE mod_grid_phy_lmdz
-
-  IMPLICIT none 
-#include "dimensions.h"
-  INTEGER :: npCFMIP
-  REAL, DIMENSION(npCFMIP) :: lonCFMIP, latCFMIP
-  INTEGER :: i, j, np, ip
-  INTEGER, DIMENSION(npCFMIP) :: ipt, jpt 
-  REAL :: dlon1, dlon2
-  REAL :: dlat1, dlat2
-  REAL, DIMENSION(iim+1) :: lon
-  INTEGER, DIMENSION(npCFMIP) :: tabijGCM
-  REAL, DIMENSION(npCFMIP) :: lonGCM, latGCM
-
-  lon(1:iim)=io_lon(:)
-  lon(iim+1)=-1*lon(1)
-  OPEN(22, file="LMDZ_pointsCFMIP.txt")
-  DO np=1, npCFMIP
-  DO i=1, iim
-!
-! PRINT*,'IM np i lonCF lonGCM lonGCM+1',np,i,lonCFMIP(np),lon(i), &
-!  lon(i+1)
-!
-   IF(lonCFMIP(np).GE.lon(i).AND.lonCFMIP(np).LT.lon(i+1)) THEN
-    dlon1 = abs (lonCFMIP(np) - lon(i))
-    dlon2 = abs (lonCFMIP(np) - lon(i+1))
-    IF (dlon1.LE.dlon2) THEN
-     ipt(np)=i
-    ELSE
-     ipt(np)=i+1
-    ENDIF
-   ENDIF
-  END DO
-  END DO
-!
-   np=1
-30 j=1
-40 IF(latCFMIP(np).LE.io_lat(j).AND.latCFMIP(np).GE.io_lat(j+1)) THEN
-    dlat1 = abs (latCFMIP(np) - io_lat(j))
-    dlat2 = abs (latCFMIP(np) - io_lat(j+1))
-    IF (dlat1.LE.dlat2) THEN
-     jpt(np)=j
-    ELSE
-     jpt(np)=j+1
-    ENDIF
-    np=np+1
-    IF(np.LE.npCFMIP) THEN
-     GOTO 30
-    ENDIF 
-   ELSE
-    j=j+1
-    IF(j.LE.jjm) THEN 
-     GOTO 40
-    ENDIF
-   ENDIF
-
-  DO np=1, npCFMIP
-   WRITE(22,*) lon(ipt(np)), io_lat(jpt(np))
-  ENDDO
-  CLOSE(22)
-
-  OPEN(23, file="pointsCFMIPvsLMDZ.txt")
-    DO ip=1, npCFMIP
-     lonGCM(ip)=lon(ipt(ip))
-     latGCM(ip)=io_lat(jpt(ip))
-     if(jpt(ip).GE.2.AND.jpt(ip).LE.jjm) THEN     
-      tabijGCM(ip)=1+(jpt(ip)-2)*iim+ipt(ip)
-     else if(jpt(ip).EQ.1) THEN
-      tabijGCM(ip)=1
-     else if(jpt(ip).EQ.jjm+1) THEN
-      tabijGCM(ip)=klon_glo
-     else 
-      print*,'ip jpt tabijGCM',ip,jpt(ip),tabijGCM(ip)
-     endif
-!    PRINT*,'CFMIP ip lon lat tabijGCM',ip,lonGCM(ip),latGCM(ip),tabijGCM(ip)
-    ENDDO
-    DO ip=1, npCFMIP
-     if(lonGCM(ip).EQ.io_lon(1)) lonGCM(ip)=360.+lonGCM(ip)
-    ENDDO
-   DO i=1, npCFMIP
-    WRITE(23,*) i, lonCFMIP(i), latCFMIP(i), lonGCM(i), latGCM(i), tabijGCM(i)
-   ENDDO
-   CLOSE(23)
- END SUBROUTINE LMDZ_CFMIP_point_locations 
-
-END MODULE CFMIP_point_locations
Index: LMDZ5/branches/testing/libf/phylmd/calcratqs.F
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/calcratqs.F	(revision 1669)
+++ 	(revision )
@@ -1,166 +1,0 @@
-!
-! $Header$
-!
-      SUBROUTINE calcratqs ( flag_ratqs,
-     I            paprs,pplay,q_seri,d_t_con,d_t_ajs
-     O           ,ratqs,zpt_conv)
-      USE dimphy
-      IMPLICIT none
-c======================================================================
-c
-c Auteur(s) Z.X. Li (LMD/CNRS) date: 19930818
-c
-c Objet: Moniteur general de la physique du modele
-cAA      Modifications quant aux traceurs :
-cAA                  -  uniformisation des parametrisations ds phytrac
-cAA                  -  stockage des moyennes des champs necessaires
-cAA                     en mode traceur off-line 
-c======================================================================
-c    modif   ( P. Le Van ,  12/10/98 )
-c
-c  Arguments:
-c
-c paprs---input-R-pression pour chaque inter-couche (en Pa)
-c pplay---input-R-pression pour le mileu de chaque couche (en Pa)
-c presnivs-input_R_pressions approximat. des milieux couches ( en PA)
-cym#include "dimensions.h"
-cym#include "dimphy.h"
-      REAL paprs(klon,klev+1)
-      REAL pplay(klon,klev)
-      REAL d_t_con(klon,klev)
-      REAL d_t_ajs(klon,klev)
-      REAL ratqs(klon,klev)
-      LOGICAL pt_conv(klon,klev)
-      REAL q_seri(klon,klev)
-
-      logical firstcall
-      save firstcall
-      data firstcall/.true./
-c$OMP THREADPRIVATE(firstcall)
-
-      REAL ratqsmin,ratqsmax,zx,epmax
-      REAL ratqs1,ratqs2,ratqs3,ratqs4
-      REAL ratqsc1,ratqsc2,ratqsc3,ratqsc4
-      INTEGER i,k
-      INTEGER flag_ratqs
-      save ratqsmin,ratqsmax,epmax
-      save ratqs1,ratqs2,ratqs3,ratqs4
-      save ratqsc1,ratqsc2,ratqsc3,ratqsc4
-c$OMP THREADPRIVATE(ratqsmin,ratqsmax,epmax)
-c$OMP THREADPRIVATE(ratqs1,ratqs2,ratqs3,ratqs4)
-c$OMP THREADPRIVATE(ratqsc1,ratqsc2,ratqsc3,ratqsc4)
-      real zpt_conv(klon,klev)
-
-      REAL zx_min
-      PARAMETER (zx_min=1.0)
-      REAL zx_max
-      PARAMETER (zx_max=0.1)
-
-	zpt_conv=0.
-c
-c Appeler le processus de condensation a grande echelle
-c et le processus de precipitation
-c
-      if (flag_ratqs.eq.0) then
-
-         ratqsmax=0.01
-         ratqsmin=0.3
-
-         if (firstcall) print*,'RATQS ANCIEN '
-         do k=1,klev
-         do i=1,klon
-            zx = pplay(i,k)/paprs(i,1)
-            zx = (zx_max-zx)/(zx_max-zx_min)
-            zx = MIN(MAX(zx,0.0),1.0)
-            zx = zx * zx * zx
-            ratqs(i,k)= zx * (ratqsmax-ratqsmin) + ratqsmin
-         enddo
-         enddo
-
-      else
-
-c  On aplique un ratqs "interactif" a toutes les mailles affectees
-c  par la convection ou se trouvant "sous" une maille affectee.
-         do i=1,klon
-            pt_conv(i,klev)=.false.
-         enddo
-         do k=klev-1,1,-1
-            do i=1,klon
-               pt_conv(i,k)=pt_conv(i,k+1).or.
-     s               (abs(d_t_con(i,k))+abs(d_t_ajs(i,k))).gt.1.e-8
-               if(pt_conv(i,k)) then
-                  zpt_conv(i,k)=1.
-               else
-                  zpt_conv(i,k)=0.
-               endif
-            enddo
-         enddo
-
-         if (flag_ratqs.eq.1) then
-
-            ratqsmin=0.4
-            ratqsmax=0.99
-            if (firstcall) print*,'RATQS INTERACTIF '
-            do k=1,klev
-                do i=1,klon
-                   if (pt_conv(i,k)) then
-                      ratqs(i,k)=0.01
-     s                +1.5*0.25*(q_seri(i,1)-q_seri(i,k))/q_seri(i,k)
-                      ratqs(i,k)=min(ratqs(i,k),ratqsmax)
-                      ratqs(i,k)=max(ratqs(i,k),0.1)
-                   else
-                      ratqs(i,k)=0.01+(ratqsmin-0.01)*
-     s             min((paprs(i,1)-pplay(i,k))/(paprs(i,1)-30000.),1.)
-                   endif
-                enddo
-            enddo
-         else if (flag_ratqs.eq.2) then
-            do k=1,klev
-                do i=1,klon
-                   ratqs(i,k)=0.001+
-     s             (q_seri(i,1)-q_seri(i,k))/q_seri(i,k)
-                   if (pt_conv(i,k)) then
-                      ratqs(i,k)=min(ratqs(i,k),ratqsmax)
-                   else
-                      ratqs(i,k)=min(ratqs(i,k),ratqsmin)
-                   endif
-                enddo
-            enddo
-         else
-            do k=1,klev
-               do i=1,klon
-                  if (pplay(i,k).ge.95000.) then
-                     if (pt_conv(i,k)) then
-                        ratqs(i,k)=ratqsc1
-                     else
-                        ratqs(i,k)=ratqs1
-                     endif
-                  else if (pplay(i,k).ge.75000.) then
-                     if (pt_conv(i,k)) then
-                        ratqs(i,k)=ratqsc2
-                     else
-                        ratqs(i,k)=ratqs2
-                     endif
-                  else if (pplay(i,k).ge.50000.) then
-                     if (pt_conv(i,k)) then
-                        ratqs(i,k)=ratqsc3
-                     else
-                        ratqs(i,k)=ratqs3
-                     endif
-                  else
-                     if (pt_conv(i,k)) then
-                        ratqs(i,k)=ratqsc4
-                     else
-                        ratqs(i,k)=ratqs4
-                     endif
-                  endif
-               enddo
-            enddo
-         endif
-
-      endif
-
-      firstcall=.false.
-
-      return
-      end
Index: LMDZ5/branches/testing/libf/phylmd/calcratqs.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/calcratqs.F90	(revision 1707)
+++ LMDZ5/branches/testing/libf/phylmd/calcratqs.F90	(revision 1707)
@@ -0,0 +1,185 @@
+SUBROUTINE calcratqs(klon,klev,prt_level,lunout,       &
+           iflag_ratqs,iflag_con,iflag_cldcon,pdtphys, &
+           ratqsbas,ratqshaut,tau_ratqs,fact_cldcon,   &
+           ptconv,ptconvth,clwcon0th, rnebcon0th,      &
+           paprs,pplay,q_seri,zqsat,fm_therm,          &
+           ratqs,ratqsc)
+
+implicit none
+
+!========================================================================
+! Computation of ratqs, the width of the subrid scale water distribution
+! (normalized by the mean value)
+! Various options controled by flags iflag_con and iflag_ratqs
+! F Hourdin 2012/12/06
+!========================================================================
+
+! Declarations
+
+! Input
+integer,intent(in) :: klon,klev,prt_level,lunout
+integer,intent(in) :: iflag_con,iflag_cldcon,iflag_ratqs
+real,intent(in) :: pdtphys,ratqsbas,ratqshaut,fact_cldcon,tau_ratqs
+real, dimension(klon,klev+1),intent(in) :: paprs
+real, dimension(klon,klev),intent(in) :: pplay,q_seri,zqsat,fm_therm
+logical, dimension(klon,klev),intent(in) :: ptconv
+real, dimension(klon,klev),intent(in) :: rnebcon0th,clwcon0th
+
+! Output
+real, dimension(klon,klev),intent(inout) :: ratqs,ratqsc
+logical, dimension(klon,klev),intent(inout) :: ptconvth
+
+! local
+integer i,k
+real, dimension(klon,klev) :: ratqss
+real facteur,zfratqs1,zfratqs2
+
+!-------------------------------------------------------------------------
+!  Caclul des ratqs
+!-------------------------------------------------------------------------
+
+!      print*,'calcul des ratqs'
+!   ratqs convectifs a l'ancienne en fonction de q(z=0)-q / q
+!   ----------------
+!   on ecrase le tableau ratqsc calcule par clouds_gno
+      if (iflag_cldcon.eq.1) then
+         do k=1,klev
+         do i=1,klon
+            if(ptconv(i,k)) then
+              ratqsc(i,k)=ratqsbas &
+              +fact_cldcon*(q_seri(i,1)-q_seri(i,k))/q_seri(i,k)
+            else
+               ratqsc(i,k)=0.
+            endif
+         enddo
+         enddo
+
+!-----------------------------------------------------------------------
+!  par nversion de la fonction log normale
+!-----------------------------------------------------------------------
+      else if (iflag_cldcon.eq.4) then
+         ptconvth(:,:)=.false.
+         ratqsc(:,:)=0.
+         if(prt_level.ge.9) print*,'avant clouds_gno thermique'
+         call clouds_gno &
+         (klon,klev,q_seri,zqsat,clwcon0th,ptconvth,ratqsc,rnebcon0th)
+         if(prt_level.ge.9) print*,' CLOUDS_GNO OK'
+       
+       endif
+
+!   ratqs stables
+!   -------------
+
+      if (iflag_ratqs.eq.0) then
+
+! Le cas iflag_ratqs=0 correspond a la version IPCC 2005 du modele.
+         do k=1,klev
+            do i=1, klon
+               ratqss(i,k)=ratqsbas+(ratqshaut-ratqsbas)* &
+               min((paprs(i,1)-pplay(i,k))/(paprs(i,1)-30000.),1.) 
+            enddo 
+         enddo
+
+! Pour iflag_ratqs=1 ou 2, le ratqs est constant au dessus de 
+! 300 hPa (ratqshaut), varie lineariement en fonction de la pression
+! entre 600 et 300 hPa et est soit constant (ratqsbas) pour iflag_ratqs=1
+! soit lineaire (entre 0 a la surface et ratqsbas) pour iflag_ratqs=2
+! Il s'agit de differents tests dans la phase de reglage du modele
+! avec thermiques.
+
+      else if (iflag_ratqs.eq.1) then
+
+         do k=1,klev
+            do i=1, klon
+               if (pplay(i,k).ge.60000.) then
+                  ratqss(i,k)=ratqsbas
+               else if ((pplay(i,k).ge.30000.).and.(pplay(i,k).lt.60000.)) then
+                  ratqss(i,k)=ratqsbas+(ratqshaut-ratqsbas)*(60000.-pplay(i,k))/(60000.-30000.)
+               else
+                  ratqss(i,k)=ratqshaut
+               endif
+            enddo
+         enddo
+
+      else if (iflag_ratqs.eq.2) then
+
+         do k=1,klev
+            do i=1, klon
+               if (pplay(i,k).ge.60000.) then
+                  ratqss(i,k)=ratqsbas*(paprs(i,1)-pplay(i,k))/(paprs(i,1)-60000.)
+               else if ((pplay(i,k).ge.30000.).and.(pplay(i,k).lt.60000.)) then
+                    ratqss(i,k)=ratqsbas+(ratqshaut-ratqsbas)*(60000.-pplay(i,k))/(60000.-30000.)
+               else
+                    ratqss(i,k)=ratqshaut
+               endif
+            enddo
+         enddo
+
+      else if (iflag_ratqs==3) then
+         do k=1,klev
+           ratqss(:,k)=ratqsbas+(ratqshaut-ratqsbas) &
+           *min( ((paprs(:,1)-pplay(:,k))/70000.)**2 , 1. )
+         enddo
+
+      else if (iflag_ratqs==4) then
+         do k=1,klev
+           ratqss(:,k)=ratqsbas+0.5*(ratqshaut-ratqsbas) &
+           *( tanh( (50000.-pplay(:,k))/20000.) + 1.)
+         enddo
+
+      endif
+
+
+
+
+!  ratqs final
+!  -----------
+
+      if (iflag_cldcon.eq.1 .or.iflag_cldcon.eq.2.or.iflag_cldcon.eq.4) then
+
+! On ajoute une constante au ratqsc*2 pour tenir compte de 
+! fluctuations turbulentes de petite echelle
+
+         do k=1,klev
+            do i=1,klon
+               if ((fm_therm(i,k).gt.1.e-10)) then
+                  ratqsc(i,k)=sqrt(ratqsc(i,k)**2+0.05**2)
+               endif
+            enddo
+         enddo
+
+!   les ratqs sont une combinaison de ratqss et ratqsc
+       if(prt_level.ge.9) write(lunout,*)'PHYLMD NOUVEAU TAU_RATQS ',tau_ratqs
+
+         if (tau_ratqs>1.e-10) then
+            facteur=exp(-pdtphys/tau_ratqs)
+         else
+            facteur=0.
+         endif
+         ratqs(:,:)=ratqsc(:,:)*(1.-facteur)+ratqs(:,:)*facteur
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+! FH 22/09/2009
+! La ligne ci-dessous faisait osciller le modele et donnait une solution
+! assymptotique bidon et dépendant fortement du pas de temps.
+!        ratqs(:,:)=sqrt(ratqs(:,:)**2+ratqss(:,:)**2)
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+         ratqs(:,:)=max(ratqs(:,:),ratqss(:,:))
+      else if (iflag_cldcon<=6) then
+!   on ne prend que le ratqs stable pour fisrtilp
+         ratqs(:,:)=ratqss(:,:)
+      else
+          zfratqs1=exp(-pdtphys/10800.)
+          zfratqs2=exp(-pdtphys/10800.)
+          do k=1,klev
+             do i=1,klon
+                if (ratqsc(i,k).gt.1.e-10) then
+                   ratqs(i,k)=ratqs(i,k)*zfratqs2+(iflag_cldcon/100.)*ratqsc(i,k)*(1.-zfratqs2)
+                endif
+                ratqs(i,k)=min(ratqs(i,k)*zfratqs1+ratqss(i,k)*(1.-zfratqs1),0.5)
+             enddo
+          enddo
+      endif
+
+
+return
+end
Index: LMDZ5/branches/testing/libf/phylmd/calcul_STDlev.h
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/calcul_STDlev.h	(revision 1669)
+++ LMDZ5/branches/testing/libf/phylmd/calcul_STDlev.h	(revision 1707)
@@ -2,6 +2,13 @@
 c $Header$
 c
-c
 cIM on initialise les variables 
+c
+        missing_val=nf90_fill_real
+c
+cIM freq_moyNMC = frequences auxquelles on moyenne les champs accumules 
+cIM               sur les niveaux de pression standard du NMC
+      DO n=1, nout
+       freq_moyNMC(n)=freq_outNMC(n)/freq_calNMC(n)
+      ENDDO
 c
         CALL ini_undefSTD(itap,freq_outNMC)
@@ -157,2 +164,80 @@
      $     lwup,LWup200)
 c
+      twriteSTD(:,:,1)=tsumSTD(:,:,1)
+      qwriteSTD(:,:,1)=qsumSTD(:,:,1)
+      rhwriteSTD(:,:,1)=rhsumSTD(:,:,1)
+      phiwriteSTD(:,:,1)=phisumSTD(:,:,1)
+      uwriteSTD(:,:,1)=usumSTD(:,:,1)
+      vwriteSTD(:,:,1)=vsumSTD(:,:,1)
+      wwriteSTD(:,:,1)=wsumSTD(:,:,1)
+
+      twriteSTD(:,:,2)=tsumSTD(:,:,2)
+      qwriteSTD(:,:,2)=qsumSTD(:,:,2)
+      rhwriteSTD(:,:,2)=rhsumSTD(:,:,2)
+      phiwriteSTD(:,:,2)=phisumSTD(:,:,2)
+      uwriteSTD(:,:,2)=usumSTD(:,:,2)
+      vwriteSTD(:,:,2)=vsumSTD(:,:,2)
+      wwriteSTD(:,:,2)=wsumSTD(:,:,2)
+
+      twriteSTD(:,:,3)=tlevSTD(:,:)
+      qwriteSTD(:,:,3)=qlevSTD(:,:)
+      rhwriteSTD(:,:,3)=rhlevSTD(:,:)
+      phiwriteSTD(:,:,3)=philevSTD(:,:)
+      uwriteSTD(:,:,3)=ulevSTD(:,:)
+      vwriteSTD(:,:,3)=vlevSTD(:,:)
+      wwriteSTD(:,:,3)=wlevSTD(:,:)
+
+      twriteSTD(:,:,4)=tlevSTD(:,:)
+      qwriteSTD(:,:,4)=qlevSTD(:,:)
+      rhwriteSTD(:,:,4)=rhlevSTD(:,:)
+      phiwriteSTD(:,:,4)=philevSTD(:,:)
+      uwriteSTD(:,:,4)=ulevSTD(:,:)
+      vwriteSTD(:,:,4)=vlevSTD(:,:)
+      wwriteSTD(:,:,4)=wlevSTD(:,:)
+c
+cIM initialisation 5eme fichier de sortie 
+      twriteSTD(:,:,5)=tlevSTD(:,:)
+      qwriteSTD(:,:,5)=qlevSTD(:,:)
+      rhwriteSTD(:,:,5)=rhlevSTD(:,:)
+      phiwriteSTD(:,:,5)=philevSTD(:,:)
+      uwriteSTD(:,:,5)=ulevSTD(:,:)
+      vwriteSTD(:,:,5)=vlevSTD(:,:)
+      wwriteSTD(:,:,5)=wlevSTD(:,:)
+c
+cIM initialisation 6eme fichier de sortie 
+      twriteSTD(:,:,6)=tlevSTD(:,:)
+      qwriteSTD(:,:,6)=qlevSTD(:,:)
+      rhwriteSTD(:,:,6)=rhlevSTD(:,:)
+      phiwriteSTD(:,:,6)=philevSTD(:,:)
+      uwriteSTD(:,:,6)=ulevSTD(:,:)
+      vwriteSTD(:,:,6)=vlevSTD(:,:)
+      wwriteSTD(:,:,6)=wlevSTD(:,:)
+cIM for NMC files
+      DO n=1, nlevSTD3
+       DO k=1, nlevSTD
+        if(rlevSTD3(n).EQ.rlevSTD(k)) THEN
+         twriteSTD3(:,n)=tlevSTD(:,k)
+         qwriteSTD3(:,n)=qlevSTD(:,k)
+         rhwriteSTD3(:,n)=rhlevSTD(:,k)
+         phiwriteSTD3(:,n)=philevSTD(:,k)
+         uwriteSTD3(:,n)=ulevSTD(:,k)
+         vwriteSTD3(:,n)=vlevSTD(:,k)
+         wwriteSTD3(:,n)=wlevSTD(:,k)
+        endif !rlevSTD3(n).EQ.rlevSTD(k)
+       ENDDO 
+      ENDDO 
+c
+      DO n=1, nlevSTD8
+       DO k=1, nlevSTD
+        if(rlevSTD8(n).EQ.rlevSTD(k)) THEN
+         tnondefSTD8(:,n)=tnondef(:,k,2)
+         twriteSTD8(:,n)=tsumSTD(:,k,2)
+         qwriteSTD8(:,n)=qsumSTD(:,k,2)
+         rhwriteSTD8(:,n)=rhsumSTD(:,k,2)
+         phiwriteSTD8(:,n)=phisumSTD(:,k,2)
+         uwriteSTD8(:,n)=usumSTD(:,k,2)
+         vwriteSTD8(:,n)=vsumSTD(:,k,2)
+         wwriteSTD8(:,n)=wsumSTD(:,k,2)
+        endif !rlevSTD8(n).EQ.rlevSTD(k)
+       ENDDO 
+      ENDDO 
Index: LMDZ5/branches/testing/libf/phylmd/cfmip_point_locations.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/cfmip_point_locations.F90	(revision 1707)
+++ LMDZ5/branches/testing/libf/phylmd/cfmip_point_locations.F90	(revision 1707)
@@ -0,0 +1,121 @@
+MODULE cfmip_point_locations
+  IMPLICIT NONE
+
+CONTAINS
+
+ SUBROUTINE read_CFMIP_point_locations(npCFMIP, tab, lonCFMIP, latCFMIP)
+  IMPLICIT none
+  INTEGER :: npCFMIP
+  REAL, DIMENSION(npCFMIP) :: lonCFMIP, latCFMIP
+  INTEGER :: tab(npCFMIP), np
+
+  WRITE(*,*) 'npCFMIP=',npCFMIP
+! OPEN(20, file="pointlocations.txt",status='old')
+  OPEN(20, file="pointlocations.txt",status='old',err=999)
+  OPEN(21, file="pointlocations_lon180.txt")
+  np=1
+10 READ(20,*) tab(np), lonCFMIP(np), latCFMIP(np)
+!!! passage de 0-360 a -180/180
+   IF (lonCFMIP(np).GT.180.) THEN
+    lonCFMIP(np)=lonCFMIP(np)-360.
+   ENDIF 
+   WRITE(21,*) np, lonCFMIP(np), latCFMIP(np)
+   np=np+1
+   IF(np.LE.npCFMIP) THEN 
+    GOTO 10
+   ENDIF
+   CLOSE(20)
+   CLOSE(21)
+999 RETURN
+ END SUBROUTINE read_CFMIP_point_locations
+
+ SUBROUTINE LMDZ_CFMIP_point_locations(npCFMIP, lonCFMIP, latCFMIP, &
+  tabijGCM, lonGCM, latGCM, ipt, jpt)
+  USE dimphy
+  USE iophy
+  USE mod_grid_phy_lmdz
+
+  IMPLICIT none 
+#include "dimensions.h"
+  INTEGER :: npCFMIP
+  REAL, DIMENSION(npCFMIP) :: lonCFMIP, latCFMIP
+  INTEGER :: i, j, np, ip
+  INTEGER, DIMENSION(npCFMIP) :: ipt, jpt 
+  REAL :: dlon1, dlon2
+  REAL :: dlat1, dlat2
+  REAL, DIMENSION(iim+1) :: lon
+  INTEGER, DIMENSION(npCFMIP) :: tabijGCM
+  REAL, DIMENSION(npCFMIP) :: lonGCM, latGCM
+
+  lon(1:iim)=io_lon(:)
+  lon(iim+1)=-1*lon(1)
+  OPEN(22, file="LMDZ_pointsCFMIP.txt")
+  DO np=1, npCFMIP
+  DO i=1, iim
+!
+! PRINT*,'IM np i lonCF lonGCM lonGCM+1',np,i,lonCFMIP(np),lon(i), &
+!  lon(i+1)
+!
+   IF(lonCFMIP(np).GE.lon(i).AND.lonCFMIP(np).LT.lon(i+1)) THEN
+    dlon1 = abs (lonCFMIP(np) - lon(i))
+    dlon2 = abs (lonCFMIP(np) - lon(i+1))
+    IF (dlon1.LE.dlon2) THEN
+     ipt(np)=i
+    ELSE
+     ipt(np)=i+1
+    ENDIF
+   ENDIF
+  END DO
+  END DO
+!
+   np=1
+30 j=1
+40 IF(latCFMIP(np).LE.io_lat(j).AND.latCFMIP(np).GE.io_lat(j+1)) THEN
+    dlat1 = abs (latCFMIP(np) - io_lat(j))
+    dlat2 = abs (latCFMIP(np) - io_lat(j+1))
+    IF (dlat1.LE.dlat2) THEN
+     jpt(np)=j
+    ELSE
+     jpt(np)=j+1
+    ENDIF
+    np=np+1
+    IF(np.LE.npCFMIP) THEN
+     GOTO 30
+    ENDIF 
+   ELSE
+    j=j+1
+    IF(j.LE.jjm) THEN 
+     GOTO 40
+    ENDIF
+   ENDIF
+
+  DO np=1, npCFMIP
+   WRITE(22,*) lon(ipt(np)), io_lat(jpt(np))
+  ENDDO
+  CLOSE(22)
+
+  OPEN(23, file="pointsCFMIPvsLMDZ.txt")
+    DO ip=1, npCFMIP
+     lonGCM(ip)=lon(ipt(ip))
+     latGCM(ip)=io_lat(jpt(ip))
+     if(jpt(ip).GE.2.AND.jpt(ip).LE.jjm) THEN     
+      tabijGCM(ip)=1+(jpt(ip)-2)*iim+ipt(ip)
+     else if(jpt(ip).EQ.1) THEN
+      tabijGCM(ip)=1
+     else if(jpt(ip).EQ.jjm+1) THEN
+      tabijGCM(ip)=klon_glo
+     else 
+      print*,'ip jpt tabijGCM',ip,jpt(ip),tabijGCM(ip)
+     endif
+!    PRINT*,'CFMIP ip lon lat tabijGCM',ip,lonGCM(ip),latGCM(ip),tabijGCM(ip)
+    ENDDO
+    DO ip=1, npCFMIP
+     if(lonGCM(ip).EQ.io_lon(1)) lonGCM(ip)=360.+lonGCM(ip)
+    ENDDO
+   DO i=1, npCFMIP
+    WRITE(23,*) i, lonCFMIP(i), latCFMIP(i), lonGCM(i), latGCM(i), tabijGCM(i)
+   ENDDO
+   CLOSE(23)
+ END SUBROUTINE LMDZ_CFMIP_point_locations 
+
+END MODULE CFMIP_point_locations
Index: LMDZ5/branches/testing/libf/phylmd/change_srf_frac_mod.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/change_srf_frac_mod.F90	(revision 1669)
+++ LMDZ5/branches/testing/libf/phylmd/change_srf_frac_mod.F90	(revision 1707)
@@ -12,5 +12,5 @@
 
   SUBROUTINE change_srf_frac(itime, dtime, jour, &
-       pctsrf, alb1, alb2, tsurf, u10m, v10m, pbl_tke)
+       pctsrf, alb1, alb2, tsurf, ustar, u10m, v10m, pbl_tke)
 !
 ! This subroutine is called from physiq.F at each timestep. 
@@ -46,4 +46,5 @@
     REAL, DIMENSION(klon,nbsrf), INTENT(INOUT) :: alb2   ! albedo second interval in SW spektrum
     REAL, DIMENSION(klon,nbsrf), INTENT(INOUT) :: tsurf
+    REAL, DIMENSION(klon,nbsrf), INTENT(INOUT) :: ustar
     REAL, DIMENSION(klon,nbsrf), INTENT(INOUT) :: u10m
     REAL, DIMENSION(klon,nbsrf), INTENT(INOUT) :: v10m
@@ -150,5 +151,5 @@
 ! 
 !****************************************************************************************
-       CALL pbl_surface_newfrac(itime, pctsrf, pctsrf_old, tsurf, alb1, alb2, u10m, v10m, pbl_tke)
+       CALL pbl_surface_newfrac(itime, pctsrf, pctsrf_old, tsurf, alb1, alb2, ustar, u10m, v10m, pbl_tke)
 
     ELSE
Index: LMDZ5/branches/testing/libf/phylmd/conf_phys.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/conf_phys.F90	(revision 1669)
+++ 	(revision )
@@ -1,1965 +1,0 @@
-
-!
-! $Id$
-!
-!
-!
-module conf_phys_m
-
-   implicit none
-
-contains
-
-  subroutine conf_phys(ok_journe, ok_mensuel, ok_instan, ok_hf, &
-                       ok_LES,&
-                       callstats,&
-                       solarlong0,seuil_inversion, &
-                       fact_cldcon, facttemps,ok_newmicro,iflag_radia,&
-                       iflag_cldcon, &
-                       iflag_ratqs,ratqsbas,ratqshaut,tau_ratqs, &
-  		       ok_ade, ok_aie, aerosol_couple, &
-                       flag_aerosol, new_aod, &
-                       bl95_b0, bl95_b1,&
-                       read_climoz, &
-                       alp_offset)
-
-   use IOIPSL
-   USE surface_data
-   USE phys_cal_mod
-   USE carbon_cycle_mod, ONLY : carbon_cycle_tr, carbon_cycle_cpl
-   use control_mod
-
- include "conema3.h"
- include "fisrtilp.h"
- include "nuage.h"
- include "YOMCST.h"
- include "YOMCST2.h"
-
- include "thermcell.h"
- include "iniprint.h"
-
-!IM : on inclut/initialise les taux de CH4, N2O, CFC11 et CFC12
-include "clesphys.h"
-include "compbl.h"
-include "comsoil.h"
-!
-! Configuration de la "physique" de LMDZ a l'aide de la fonction
-! GETIN de IOIPSL
-!
-! LF 05/2001
-!
-
-!
-! type_ocean:      type d'ocean (force, slab, couple)
-! version_ocean:   version d'ocean (opa8/nemo pour type_ocean=couple ou 
-!                                   sicOBS pour type_ocean=slab)
-! ok_veget:   type de modele de vegetation
-! ok_journe:  sorties journalieres
-! ok_hf:  sorties haute frequence
-! ok_mensuel: sorties mensuelles
-! ok_instan:  sorties instantanees
-! ok_ade, ok_aie: apply or not aerosol direct and indirect effects
-! bl95_b*: parameters in the formula to link CDNC to aerosol mass conc 
-!
-
-
-! Sortie:
-  logical              :: ok_newmicro
-  integer              :: iflag_radia
-  logical              :: ok_journe, ok_mensuel, ok_instan, ok_hf
-  logical              :: ok_LES
-  LOGICAL              :: callstats
-  LOGICAL              :: ok_ade, ok_aie, aerosol_couple
-  INTEGER              :: flag_aerosol
-  LOGICAL              :: new_aod
-  REAL                 :: bl95_b0, bl95_b1
-  real                 :: fact_cldcon, facttemps,ratqsbas,ratqshaut,tau_ratqs
-  integer              :: iflag_cldcon
-  integer              :: iflag_ratqs
-
-  character (len = 6),SAVE  :: type_ocean_omp, version_ocean_omp, ocean_omp
-  CHARACTER(len = 8),SAVE   :: aer_type_omp
-  logical,SAVE              :: ok_veget_omp, ok_newmicro_omp
-  logical,SAVE        :: ok_journe_omp, ok_mensuel_omp, ok_instan_omp, ok_hf_omp        
-  logical,SAVE        :: ok_LES_omp   
-  LOGICAL,SAVE        :: callstats_omp
-  LOGICAL,SAVE        :: ok_ade_omp, ok_aie_omp, aerosol_couple_omp
-  INTEGER, SAVE       :: flag_aerosol_omp
-  LOGICAL, SAVE       :: new_aod_omp
-  REAL,SAVE           :: bl95_b0_omp, bl95_b1_omp
-  REAL,SAVE           :: freq_ISCCP_omp, ecrit_ISCCP_omp
-  REAL,SAVE           :: freq_COSP_omp
-  real,SAVE           :: fact_cldcon_omp, facttemps_omp,ratqsbas_omp
-  real,SAVE           :: ratqshaut_omp
-  real,SAVE           :: tau_ratqs_omp
-  integer,SAVE        :: iflag_radia_omp
-  integer,SAVE        :: iflag_rrtm_omp
-  integer,SAVE        :: iflag_cldcon_omp, ip_ebil_phy_omp
-  integer,SAVE        :: iflag_ratqs_omp
-
-  Real,SAVE           :: f_cdrag_ter_omp,f_cdrag_oce_omp
-  Real,SAVE           :: f_rugoro_omp   
-
-! Local
-  real                 :: zzz
-
-  real :: seuil_inversion
-  real,save :: seuil_inversion_omp
-
-  integer,SAVE :: iflag_thermals_ed_omp,iflag_thermals_optflux_omp
-  integer,SAVE :: iflag_thermals_omp,nsplit_thermals_omp
-  real,save :: tau_thermals_omp,alp_bl_k_omp
-!!! nrlmd le 10/04/2012
-  integer,SAVE :: iflag_trig_bl_omp,iflag_clos_bl_omp
-  integer,SAVE :: tau_trig_shallow_omp,tau_trig_deep_omp
-  real,SAVE    :: s_trig_omp
-!!! fin nrlmd le 10/04/2012
-  real :: alp_offset
-  REAL, SAVE :: alp_offset_omp
-  integer,SAVE :: iflag_coupl_omp,iflag_clos_omp,iflag_wake_omp
-  integer,SAVE :: iflag_cvl_sigd_omp
-  REAL, SAVE :: supcrit1_omp, supcrit2_omp
-  INTEGER, SAVE :: iflag_mix_omp
-  real, save :: scut_omp, qqa1_omp, qqa2_omp, gammas_omp, Fmax_omp, alphas_omp
-
-  REAL,SAVE :: R_ecc_omp,R_peri_omp,R_incl_omp,solaire_omp
-  REAL,SAVE :: co2_ppm_omp, RCO2_omp, co2_ppm_per_omp, RCO2_per_omp
-  REAL,SAVE :: CH4_ppb_omp, RCH4_omp, CH4_ppb_per_omp, RCH4_per_omp
-  REAL,SAVE :: N2O_ppb_omp, RN2O_omp, N2O_ppb_per_omp, RN2O_per_omp
-  REAL,SAVE :: CFC11_ppt_omp,RCFC11_omp,CFC11_ppt_per_omp,RCFC11_per_omp
-  REAL,SAVE :: CFC12_ppt_omp,RCFC12_omp,CFC12_ppt_per_omp,RCFC12_per_omp
-  REAL,SAVE :: epmax_omp
-  LOGICAL,SAVE :: ok_adj_ema_omp
-  INTEGER,SAVE :: iflag_clw_omp
-  REAL,SAVE :: cld_lc_lsc_omp,cld_lc_con_omp,cld_tau_lsc_omp,cld_tau_con_omp
-  REAL,SAVE :: ffallv_lsc_omp, ffallv_con_omp,coef_eva_omp
-  LOGICAL,SAVE :: reevap_ice_omp
-  INTEGER,SAVE :: iflag_pdf_omp
-  REAL,SAVE :: rad_froid_omp, rad_chau1_omp, rad_chau2_omp
-  REAL,SAVE :: t_glace_min_omp, t_glace_max_omp
-  REAL,SAVE :: rei_min_omp, rei_max_omp
-  REAL,SAVE :: inertie_sol_omp,inertie_sno_omp,inertie_ice_omp
-  REAL,SAVE :: qsol0_omp
-  REAL      :: solarlong0
-  REAL,SAVE :: solarlong0_omp
-  INTEGER,SAVE :: top_height_omp,overlap_omp
-  REAL,SAVE :: cdmmax_omp,cdhmax_omp,ksta_omp,ksta_ter_omp
-  LOGICAL,SAVE :: ok_kzmin_omp
-  REAL, SAVE ::  fmagic_omp, pmagic_omp
-  INTEGER,SAVE :: iflag_pbl_omp,lev_histhf_omp,lev_histday_omp,lev_histmth_omp
-  Integer, save :: lev_histins_omp, lev_histLES_omp 
-  INTEGER, SAVE :: lev_histdayNMC_omp
-  LOGICAL, SAVE :: ok_histNMC_omp(3)
-  REAL, SAVE :: freq_outNMC_omp(3), freq_calNMC_omp(3)
-  CHARACTER*4, SAVE :: type_run_omp
-  LOGICAL,SAVE :: ok_isccp_omp
-  LOGICAL,SAVE :: ok_cosp_omp
-  LOGICAL,SAVE :: ok_mensuelCOSP_omp,ok_journeCOSP_omp,ok_hfCOSP_omp
-  REAL,SAVE :: lonmin_ins_omp, lonmax_ins_omp, latmin_ins_omp, latmax_ins_omp
-  REAL,SAVE :: ecrit_hf_omp, ecrit_day_omp, ecrit_mth_omp, ecrit_reg_omp
-  REAL,SAVE :: ecrit_ins_omp
-  REAL,SAVE :: ecrit_LES_omp
-  REAL,SAVE :: ecrit_tra_omp
-  REAL,SAVE :: cvl_corr_omp
-  LOGICAL,SAVE :: ok_lic_melt_omp
-!
-  LOGICAL,SAVE :: cycle_diurne_omp,soil_model_omp,new_oliq_omp
-  LOGICAL,SAVE :: ok_orodr_omp, ok_orolf_omp, ok_limitvrai_omp
-  INTEGER, SAVE :: nbapp_rad_omp, iflag_con_omp
-  LOGICAL,SAVE :: ok_strato_omp
-  LOGICAL,SAVE :: ok_hines_omp
-  LOGICAL,SAVE      :: carbon_cycle_tr_omp
-  LOGICAL,SAVE      :: carbon_cycle_cpl_omp
-
-  integer, intent(out):: read_climoz ! read ozone climatology, OpenMP shared
-  ! Allowed values are 0, 1 and 2
-  ! 0: do not read an ozone climatology
-  ! 1: read a single ozone climatology that will be used day and night
-  ! 2: read two ozone climatologies, the average day and night
-  ! climatology and the daylight climatology
-
-!$OMP MASTER 
-!Config Key  = type_ocean 
-!Config Desc = Type d'ocean
-!Config Def  = force
-!Config Help = Type d'ocean utilise: force, slab,couple
-!
-  type_ocean_omp = 'force '
-  call getin('type_ocean', type_ocean_omp)
-!
-!Config Key  = version_ocean 
-!Config Desc = Version d'ocean
-!Config Def  = xxxxxx
-!Config Help = Version d'ocean utilise: opa8/nemo/sicOBS/xxxxxx
-!
-  version_ocean_omp = 'xxxxxx'
-  call getin('version_ocean', version_ocean_omp)
-
-!Config Key  = OCEAN
-!Config Desc = Old parameter name for type_ocean
-!Config Def  = yyyyyy
-!Config Help = This is only for testing purpose
-!
-  ocean_omp = 'yyyyyy'
-  call getin('OCEAN', ocean_omp)
-  IF (ocean_omp /= 'yyyyyy') THEN
-     WRITE(lunout,*)'ERROR!! Old variable name OCEAN used in parmeter file.'
-     WRITE(lunout,*)'Variable OCEAN has been replaced by the variable type_ocean.'
-     WRITE(lunout,*)'You have to update your parameter file physiq.def to succed running'
-     CALL abort_gcm('conf_phys','Variable OCEAN no longer existing, use variable name type_ocean',1)
-  END IF
-
-!
-!Config Key  = VEGET 
-!Config Desc = Type de modele de vegetation
-!Config Def  = .false.
-!Config Help = Type de modele de vegetation utilise
-!
-  ok_veget_omp = .false.
-  call getin('VEGET', ok_veget_omp)
-!
-!Config Key  = OK_journe
-!Config Desc = Pour des sorties journalieres 
-!Config Def  = .false.
-!Config Help = Pour creer le fichier histday contenant les sorties
-!              journalieres 
-!
-  ok_journe_omp = .false.
-  call getin('OK_journe', ok_journe_omp)
-!
-!Config Key  = ok_hf
-!Config Desc = Pour des sorties haute frequence
-!Config Def  = .false.
-!Config Help = Pour creer le fichier histhf contenant les sorties
-!              haute frequence ( 3h ou 6h)
-!
-  ok_hf_omp = .false.
-  call getin('ok_hf', ok_hf_omp)
-!
-!Config Key  = OK_mensuel
-!Config Desc = Pour des sorties mensuelles 
-!Config Def  = .true.
-!Config Help = Pour creer le fichier histmth contenant les sorties
-!              mensuelles 
-!
-  ok_mensuel_omp = .true.
-  call getin('OK_mensuel', ok_mensuel_omp)
-!
-!Config Key  = OK_instan
-!Config Desc = Pour des sorties instantanees 
-!Config Def  = .false.
-!Config Help = Pour creer le fichier histins contenant les sorties
-!              instantanees 
-!
-  ok_instan_omp = .false.
-  call getin('OK_instan', ok_instan_omp)
-!
-!Config Key  = ok_ade
-!Config Desc = Aerosol direct effect or not?
-!Config Def  = .false.
-!Config Help = Used in radlwsw.F
-!
-  ok_ade_omp = .false.
-  call getin('ok_ade', ok_ade_omp)
-
-!
-!Config Key  = ok_aie
-!Config Desc = Aerosol indirect effect or not?
-!Config Def  = .false.
-!Config Help = Used in nuage.F and radlwsw.F
-!
-  ok_aie_omp = .false.
-  call getin('ok_aie', ok_aie_omp)
-
-!
-!Config Key  = aerosol_couple
-!Config Desc = read aerosol in file or calcul by inca
-!Config Def  = .false.
-!Config Help = Used in physiq.F
-!
-  aerosol_couple_omp = .false.
-  CALL getin('aerosol_couple',aerosol_couple_omp)
-
-!
-!Config Key  = flag_aerosol
-!Config Desc = which aerosol is use for coupled model
-!Config Def  = 1
-!Config Help = Used in physiq.F
-!
-! - flag_aerosol=0 => no aerosol
-! - flag_aerosol=1 => so4 only (defaut) 
-! - flag_aerosol=2 => bc  only 
-! - flag_aerosol=3 => pom only
-! - flag_aerosol=4 => seasalt only 
-! - flag_aerosol=5 => dust only
-! - flag_aerosol=6 => all aerosol
-
-  flag_aerosol_omp = 0
-  CALL getin('flag_aerosol',flag_aerosol_omp)
-
-! Temporary variable for testing purpose!!
-!Config Key  = new_aod
-!Config Desc = which calcul of aeropt
-!Config Def  = false
-!Config Help = Used in physiq.F
-!
-  new_aod_omp = .true.
-  CALL getin('new_aod',new_aod_omp)
-
-! 
-!Config Key  = aer_type 
-!Config Desc = Use a constant field for the aerosols 
-!Config Def  = scenario 
-!Config Help = Used in readaerosol.F90 
-! 
-  aer_type_omp = 'scenario' 
-  call getin('aer_type', aer_type_omp) 
-
-!
-!Config Key  = bl95_b0
-!Config Desc = Parameter in CDNC-maer link (Boucher&Lohmann 1995)
-!Config Def  = .false.
-!Config Help = Used in nuage.F
-!
-  bl95_b0_omp = 2.
-  call getin('bl95_b0', bl95_b0_omp)
-
-!Config Key  = bl95_b1
-!Config Desc = Parameter in CDNC-maer link (Boucher&Lohmann 1995)
-!Config Def  = .false.
-!Config Help = Used in nuage.F
-!
-  bl95_b1_omp = 0.2
-  call getin('bl95_b1', bl95_b1_omp)
-
-!Config Key  = freq_ISCCP
-!Config Desc = Frequence d'appel du simulateur ISCCP en secondes;
-!              par defaut 10800, i.e. 3 heures 
-!Config Def  = 10800.
-!Config Help = Used in ini_histISCCP.h
-!
-  freq_ISCCP_omp = 10800.
-  call getin('freq_ISCCP', freq_ISCCP_omp)
-!
-!Config Key  = ecrit_ISCCP
-!Config Desc = Frequence d'ecriture des resultats du simulateur ISCCP en nombre de jours;
-!              par defaut 1., i.e. 1 jour
-!Config Def  = 1.
-!Config Help = Used in ini_histISCCP.h
-!
-!
-  ecrit_ISCCP_omp = 1.
-  call getin('ecrit_ISCCP', ecrit_ISCCP_omp)
-
-!Config Key  = freq_COSP
-!Config Desc = Frequence d'appel du simulateur COSP en secondes;
-!              par defaut 10800, i.e. 3 heures
-!Config Def  = 10800.
-!Config Help = Used in ini_histdayCOSP.h
-!
-  freq_COSP_omp = 10800.
-  call getin('freq_COSP', freq_COSP_omp)
-
-!
-!Config Key  = ip_ebil_phy
-!Config Desc = Niveau de sortie pour les diags bilan d'energie 
-!Config Def  = 0
-!Config Help = 
-!               
-  ip_ebil_phy_omp = 0
-  call getin('ip_ebil_phy', ip_ebil_phy_omp)
-!
-!Config Key  = seuil_inversion
-!Config Desc = Seuil ur dTh pour le choix entre les schemas de CL
-!Config Def  = -0.1
-!Config Help = 
-!               
-  seuil_inversion_omp = -0.1
-  call getin('seuil_inversion', seuil_inversion_omp)
-
-!!
-!! Constante solaire & Parametres orbitaux & taux gaz effet de serre BEG
-!!
-!Config Key  = R_ecc
-!Config Desc = Excentricite
-!Config Def  = 0.016715
-!Config Help = 
-!               
-!valeur AMIP II
-  R_ecc_omp = 0.016715
-  call getin('R_ecc', R_ecc_omp)
-!!
-!Config Key  = R_peri
-!Config Desc = Equinoxe
-!Config Def  = 
-!Config Help = 
-!               
-!
-!valeur AMIP II
-  R_peri_omp = 102.7
-  call getin('R_peri', R_peri_omp)
-!!
-!Config Key  = R_incl
-!Config Desc = Inclinaison
-!Config Def  = 
-!Config Help = 
-!               
-!
-!valeur AMIP II
-  R_incl_omp = 23.441
-  call getin('R_incl', R_incl_omp)
-!!
-!Config Key  = solaire
-!Config Desc = Constante solaire en W/m2
-!Config Def  = 1365.
-!Config Help = 
-!               
-!
-!valeur AMIP II
-  solaire_omp = 1365.
-  call getin('solaire', solaire_omp)
-!!
-!Config Key  = co2_ppm
-!Config Desc = concentration du gaz carbonique en ppmv
-!Config Def  = 348.
-!Config Help = 
-!               
-!
-!valeur AMIP II
-  co2_ppm_omp = 348.
-  call getin('co2_ppm', co2_ppm_omp)
-!!
-!Config Key  = RCO2
-!Config Desc = Concentration du CO2
-!Config Def  = co2_ppm * 1.0e-06  * 44.011/28.97
-!Config Def  = 348. * 1.0e-06  * 44.011/28.97
-!Config Help = 
-!               
-! RCO2 = 5.286789092164308E-04
-!ancienne valeur
-  RCO2_omp = co2_ppm_omp * 1.0e-06  * 44.011/28.97 ! pour co2_ppm=348.
-
-!!  call getin('RCO2', RCO2)
-!!
-!Config Key  = RCH4
-!Config Desc = Concentration du CH4
-!Config Def  = 1.65E-06* 16.043/28.97
-!Config Help = 
-!               
-!
-!valeur AMIP II
-!OK  RCH4 = 1.65E-06* 16.043/28.97
-! RCH4 = 9.137366240938903E-07
-!
-!ancienne valeur
-! RCH4 = 1.72E-06* 16.043/28.97
-!OK call getin('RCH4', RCH4)
-  zzz = 1650.
-  call getin('CH4_ppb', zzz)
-  CH4_ppb_omp = zzz
-  RCH4_omp = CH4_ppb_omp * 1.0E-09 * 16.043/28.97
-!!
-!Config Key  = RN2O
-!Config Desc = Concentration du N2O
-!Config Def  = 306.E-09* 44.013/28.97
-!Config Help = 
-!               
-!
-!valeur AMIP II
-!OK  RN2O = 306.E-09* 44.013/28.97
-! RN2O = 4.648939592682085E-07
-!
-!ancienne valeur
-! RN2O = 310.E-09* 44.013/28.97
-!OK  call getin('RN2O', RN2O)
-  zzz=306.
-  call getin('N2O_ppb', zzz)
-  N2O_ppb_omp = zzz
-  RN2O_omp = N2O_ppb_omp * 1.0E-09 * 44.013/28.97
-!!
-!Config Key  = RCFC11
-!Config Desc = Concentration du CFC11
-!Config Def  = 280.E-12* 137.3686/28.97
-!Config Help = 
-!               
-!
-!OK RCFC11 = 280.E-12* 137.3686/28.97
-  zzz = 280.
-  call getin('CFC11_ppt',zzz)
-  CFC11_ppt_omp = zzz
-  RCFC11_omp=CFC11_ppt_omp* 1.0E-12 * 137.3686/28.97
-! RCFC11 = 1.327690990680013E-09
-!OK call getin('RCFC11', RCFC11)
-!!
-!Config Key  = RCFC12
-!Config Desc = Concentration du CFC12
-!Config Def  = 484.E-12* 120.9140/28.97
-!Config Help = 
-!               
-!
-!OK RCFC12 = 484.E-12* 120.9140/28.97
-  zzz = 484.
-  call getin('CFC12_ppt',zzz)
-  CFC12_ppt_omp = zzz
-  RCFC12_omp = CFC12_ppt_omp * 1.0E-12 * 120.9140/28.97
-! RCFC12 = 2.020102726958923E-09
-!OK call getin('RCFC12', RCFC12)
-
-!ajout CFMIP begin
-!!
-!Config Key  = co2_ppm_per
-!Config Desc = concentration du co2_ppm_per
-!Config Def  = 348.
-!Config Help = 
-!               
-  co2_ppm_per_omp = co2_ppm_omp
-  call getin('co2_ppm_per', co2_ppm_per_omp)
-!!
-!Config Key  = RCO2_per
-!Config Desc = Concentration du CO2_per
-!Config Def  = co2_ppm_per * 1.0e-06  * 44.011/28.97
-!Config Def  = 348. * 1.0e-06  * 44.011/28.97
-!Config Help = 
-!               
-  RCO2_per_omp = co2_ppm_per_omp * 1.0e-06  * 44.011/28.97
-
-!Config Key  = RCH4_per
-!Config Desc = Concentration du CH4_per
-!Config Def  = 1.65E-06* 16.043/28.97
-!Config Help = 
-!               
-  zzz = CH4_ppb_omp
-  call getin('CH4_ppb_per', zzz)
-  CH4_ppb_per_omp = zzz
-  RCH4_per_omp = CH4_ppb_per_omp * 1.0E-09 * 16.043/28.97
-!!
-!Config Key  = RN2O_per
-!Config Desc = Concentration du N2O_per
-!Config Def  = 306.E-09* 44.013/28.97
-!Config Help = 
-!               
-  zzz = N2O_ppb_omp
-  call getin('N2O_ppb_per', zzz)
-  N2O_ppb_per_omp = zzz
-  RN2O_per_omp = N2O_ppb_per_omp * 1.0E-09 * 44.013/28.97
-!!
-!Config Key  = RCFC11_per
-!Config Desc = Concentration du CFC11_per
-!Config Def  = 280.E-12* 137.3686/28.97
-!Config Help = 
-!               
-  zzz = CFC11_ppt_omp
-  call getin('CFC11_ppt_per',zzz)
-  CFC11_ppt_per_omp = zzz
-  RCFC11_per_omp=CFC11_ppt_per_omp* 1.0E-12 * 137.3686/28.97
-!!
-!Config Key  = RCFC12_per
-!Config Desc = Concentration du CFC12_per
-!Config Def  = 484.E-12* 120.9140/28.97
-!Config Help = 
-!               
-  zzz = CFC12_ppt_omp
-  call getin('CFC12_ppt_per',zzz)
-  CFC12_ppt_per_omp = zzz
-  RCFC12_per_omp = CFC12_ppt_per_omp * 1.0E-12 * 120.9140/28.97
-!ajout CFMIP end
-
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-! FH 2008/05/09 On elimine toutes les clefs physiques dans la dynamique
-! Constantes precedemment dans dyn3d/conf_gcm
-
-!Config  Key  = cycle_diurne
-!Config  Desc = Cycle ddiurne
-!Config  Def  = y
-!Config  Help = Cette option permet d'eteidre le cycle diurne.
-!Config         Peut etre util pour accelerer le code !
-       cycle_diurne_omp = .TRUE.
-       CALL getin('cycle_diurne',cycle_diurne_omp)
-
-!Config  Key  = soil_model
-!Config  Desc = Modele de sol
-!Config  Def  = y
-!Config  Help = Choix du modele de sol (Thermique ?)
-!Config         Option qui pourait un string afin de pouvoir
-!Config         plus de choix ! Ou meme une liste d'options !
-       soil_model_omp = .TRUE.
-       CALL getin('soil_model',soil_model_omp)
-
-!Config  Key  = new_oliq
-!Config  Desc = Nouvelle eau liquide
-!Config  Def  = y
-!Config  Help = Permet de mettre en route la
-!Config         nouvelle parametrisation de l'eau liquide !
-       new_oliq_omp = .TRUE.
-       CALL getin('new_oliq',new_oliq_omp)
-
-!Config  Key  = ok_orodr
-!Config  Desc = Orodr ???
-!Config  Def  = y
-!Config  Help = Y en a pas comprendre !
-!Config         
-       ok_orodr_omp = .TRUE.
-       CALL getin('ok_orodr',ok_orodr_omp)
-
-!Config  Key  =  ok_orolf
-!Config  Desc = Orolf ??
-!Config  Def  = y
-!Config  Help = Connais pas !
-       ok_orolf_omp = .TRUE.
-       CALL getin('ok_orolf', ok_orolf_omp)
-
-!Config  Key  = ok_limitvrai
-!Config  Desc = Force la lecture de la bonne annee
-!Config  Def  = n
-!Config  Help = On peut forcer le modele a lire le
-!Config         fichier SST de la bonne annee. C'est une tres bonne
-!Config         idee, pourquoi ne pas mettre toujours a y ???
-       ok_limitvrai_omp = .FALSE.
-       CALL getin('ok_limitvrai',ok_limitvrai_omp)
-
-!Config  Key  = nbapp_rad
-!Config  Desc = Frequence d'appel au rayonnement
-!Config  Def  = 12
-!Config  Help = Nombre  d'appels des routines de rayonnements
-!Config         par jour.
-       nbapp_rad_omp = 12
-       CALL getin('nbapp_rad',nbapp_rad_omp)
-
-!Config  Key  = iflag_con
-!Config  Desc = Flag de convection
-!Config  Def  = 2
-!Config  Help = Flag  pour la convection les options suivantes existent :
-!Config         1 pour LMD,
-!Config         2 pour Tiedtke,
-!Config         3 pour CCM(NCAR)  
-       iflag_con_omp = 2
-       CALL getin('iflag_con',iflag_con_omp)
-
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-!!
-!! Constante solaire & Parametres orbitaux & taux gaz effet de serre END
-!!
-!! KE
-!
-
-!Config key  = cvl_corr
-!Config Desc = Facteur multiplication des precip convectives dans KE
-!Config Def  = 1.00
-!Config Help = 1.02 pour un moderne ou un pre-ind. A ajuster pour un glaciaire
-  cvl_corr_omp = 1.00
-  CALL getin('cvl_corr', cvl_corr_omp)
-
-
-!Config Key  = epmax
-!Config Desc = Efficacite precip
-!Config Def  = 0.993
-!Config Help = 
-!
-  epmax_omp = .993
-  call getin('epmax', epmax_omp)
-!
-!Config Key  = ok_adj_ema
-!Config Desc =  
-!Config Def  = false
-!Config Help = 
-!
-  ok_adj_ema_omp = .false.
-  call getin('ok_adj_ema',ok_adj_ema_omp)
-!
-!Config Key  = iflag_clw
-!Config Desc =  
-!Config Def  = 0
-!Config Help = 
-!
-  iflag_clw_omp = 0
-  call getin('iflag_clw',iflag_clw_omp)
-!
-!Config Key  = cld_lc_lsc 
-!Config Desc =  
-!Config Def  = 2.6e-4
-!Config Help = 
-!
-  cld_lc_lsc_omp = 2.6e-4
-  call getin('cld_lc_lsc',cld_lc_lsc_omp)
-!
-!Config Key  = cld_lc_con
-!Config Desc =  
-!Config Def  = 2.6e-4
-!Config Help = 
-!
-  cld_lc_con_omp = 2.6e-4
-  call getin('cld_lc_con',cld_lc_con_omp)
-!
-!Config Key  = cld_tau_lsc
-!Config Desc =  
-!Config Def  = 3600.
-!Config Help = 
-!
-  cld_tau_lsc_omp = 3600.
-  call getin('cld_tau_lsc',cld_tau_lsc_omp)
-!
-!Config Key  = cld_tau_con
-!Config Desc =  
-!Config Def  = 3600.
-!Config Help = 
-!
-  cld_tau_con_omp = 3600.
-  call getin('cld_tau_con',cld_tau_con_omp)
-!
-!Config Key  = ffallv_lsc
-!Config Desc =  
-!Config Def  = 1.
-!Config Help = 
-!
-  ffallv_lsc_omp = 1.
-  call getin('ffallv_lsc',ffallv_lsc_omp)
-!
-!Config Key  = ffallv_con
-!Config Desc =  
-!Config Def  = 1.
-!Config Help = 
-!
-  ffallv_con_omp = 1.
-  call getin('ffallv_con',ffallv_con_omp)
-!
-!Config Key  = coef_eva
-!Config Desc =  
-!Config Def  = 2.e-5
-!Config Help = 
-!
-  coef_eva_omp = 2.e-5
-  call getin('coef_eva',coef_eva_omp)
-!
-!Config Key  = reevap_ice
-!Config Desc =  
-!Config Def  = .false.
-!Config Help = 
-!
-  reevap_ice_omp = .false.
-  call getin('reevap_ice',reevap_ice_omp)
-
-!Config Key  = iflag_ratqs
-!Config Desc =
-!Config Def  = 1
-!Config Help =
-!
-  iflag_ratqs_omp = 1
-  call getin('iflag_ratqs',iflag_ratqs_omp)
-
-!
-!Config Key  = iflag_radia 
-!Config Desc =  
-!Config Def  = 1
-!Config Help = 
-!
-  iflag_radia_omp = 1
-  call getin('iflag_radia',iflag_radia_omp)
-
-!
-!Config Key  = iflag_rrtm 
-!Config Desc =  
-!Config Def  = 0
-!Config Help = 
-!
-  iflag_rrtm_omp = 0
-  call getin('iflag_rrtm',iflag_rrtm_omp)
-
-!
-!Config Key  = iflag_cldcon 
-!Config Desc =  
-!Config Def  = 1
-!Config Help = 
-!
-  iflag_cldcon_omp = 1
-  call getin('iflag_cldcon',iflag_cldcon_omp)
-
-!
-!Config Key  = iflag_pdf 
-!Config Desc =  
-!Config Def  = 0
-!Config Help = 
-!
-  iflag_pdf_omp = 0
-  call getin('iflag_pdf',iflag_pdf_omp)
-!
-!Config Key  = fact_cldcon
-!Config Desc =  
-!Config Def  = 0.375
-!Config Help = 
-!
-  fact_cldcon_omp = 0.375
-  call getin('fact_cldcon',fact_cldcon_omp)
-
-!
-!Config Key  = facttemps
-!Config Desc =  
-!Config Def  = 1.e-4
-!Config Help = 
-!
-  facttemps_omp = 1.e-4
-  call getin('facttemps',facttemps_omp)
-
-!
-!Config Key  = ok_newmicro
-!Config Desc =  
-!Config Def  = .true.
-!Config Help = 
-!
-  ok_newmicro_omp = .true.
-  call getin('ok_newmicro',ok_newmicro_omp)
-!
-!Config Key  = ratqsbas
-!Config Desc =  
-!Config Def  = 0.01
-!Config Help = 
-!
-  ratqsbas_omp = 0.01
-  call getin('ratqsbas',ratqsbas_omp)
-!
-!Config Key  = ratqshaut
-!Config Desc =  
-!Config Def  = 0.3
-!Config Help = 
-!
-  ratqshaut_omp = 0.3
-  call getin('ratqshaut',ratqshaut_omp)
-
-!Config Key  = tau_ratqs
-!Config Desc =  
-!Config Def  = 1800.
-!Config Help = 
-!
-  tau_ratqs_omp = 1800.
-  call getin('tau_ratqs',tau_ratqs_omp)
-
-!
-!-----------------------------------------------------------------------
-! Longitude solaire pour le calcul de l'ensoleillement en degre
-! si on veut imposer la saison. Sinon, solarlong0=-999.999
-!Config Key  = solarlong0
-!Config Desc =  
-!Config Def  = -999.999 
-!Config Help = 
-!
-  solarlong0_omp = -999.999
-  call getin('solarlong0',solarlong0_omp)
-!
-!-----------------------------------------------------------------------
-!  Valeur imposee de l'humidite du sol pour le modele bucket.
-!Config Key  = qsol0
-!Config Desc =  
-!Config Def  = -1.
-!Config Help = 
-!
-  qsol0_omp = -1.
-  call getin('qsol0',qsol0_omp)
-!
-!-----------------------------------------------------------------------
-!
-!Config Key  = inertie_ice
-!Config Desc =  
-!Config Def  = 2000.
-!Config Help = 
-!
-  inertie_ice_omp = 2000.
-  call getin('inertie_ice',inertie_ice_omp)
-!
-!Config Key  = inertie_sno
-!Config Desc =  
-!Config Def  = 2000.
-!Config Help = 
-!
-  inertie_sno_omp = 2000.
-  call getin('inertie_sno',inertie_sno_omp)
-!
-!Config Key  = inertie_sol
-!Config Desc =  
-!Config Def  = 2000.
-!Config Help = 
-!
-  inertie_sol_omp = 2000.
-  call getin('inertie_sol',inertie_sol_omp)
-
-!
-!Config Key  = rad_froid
-!Config Desc =  
-!Config Def  = 35.0
-!Config Help = 
-!
-  rad_froid_omp = 35.0
-  call getin('rad_froid',rad_froid_omp)
-
-!
-!Config Key  = rad_chau1
-!Config Desc =  
-!Config Def  = 13.0
-!Config Help = 
-!
-  rad_chau1_omp = 13.0
-  call getin('rad_chau1',rad_chau1_omp)
-
-!
-!Config Key  = rad_chau2
-!Config Desc =  
-!Config Def  = 9.0
-!Config Help = 
-!
-  rad_chau2_omp = 9.0
-  call getin('rad_chau2',rad_chau2_omp)
-
-!
-!Config Key  = t_glace_min
-!Config Desc =  
-!Config Def  = 258.
-!Config Help = 
-!
-  t_glace_min_omp = 258.
-  call getin('t_glace_min',t_glace_min_omp)
-
-!
-!Config Key  = t_glace_max
-!Config Desc =  
-!Config Def  = 273.13
-!Config Help = 
-!
-  t_glace_max_omp = 273.13
-  call getin('t_glace_max',t_glace_max_omp)
-
-!Config Key  = rei_min
-!Config Desc =  
-!Config Def  = 3.5
-!Config Help = 
-!
-  rei_min_omp = 3.5
-  call getin('rei_min',rei_min_omp)
-
-!
-!Config Key  = rei_max
-!Config Desc =  
-!Config Def  = 61.29
-!Config Help = 
-!
-  rei_max_omp = 61.29
-  call getin('rei_max',rei_max_omp)
-
-!
-!Config Key  = top_height
-!Config Desc =
-!Config Def  = 3
-!Config Help =
-!
-  top_height_omp = 3
-  call getin('top_height',top_height_omp)
-
-!
-!Config Key  = overlap
-!Config Desc =
-!Config Def  = 3
-!Config Help =
-!
-  overlap_omp = 3
-  call getin('overlap',overlap_omp)
-
-
-!
-!
-!Config Key  = cdmmax
-!Config Desc =
-!Config Def  = 1.3E-3
-!Config Help =
-!
-  cdmmax_omp = 1.3E-3
-  call getin('cdmmax',cdmmax_omp)
-
-!
-!Config Key  = cdhmax
-!Config Desc =
-!Config Def  = 1.1E-3
-!Config Help =
-!
-  cdhmax_omp = 1.1E-3
-  call getin('cdhmax',cdhmax_omp)
-
-!261103
-!
-!Config Key  = ksta
-!Config Desc =
-!Config Def  = 1.0e-10
-!Config Help =
-!
-  ksta_omp = 1.0e-10
-  call getin('ksta',ksta_omp)
-
-!
-!Config Key  = ksta_ter
-!Config Desc =
-!Config Def  = 1.0e-10
-!Config Help =
-!
-  ksta_ter_omp = 1.0e-10
-  call getin('ksta_ter',ksta_ter_omp)
-
-!
-!Config Key  = ok_kzmin
-!Config Desc =
-!Config Def  = .true.
-!Config Help =
-!
-  ok_kzmin_omp = .true.
-  call getin('ok_kzmin',ok_kzmin_omp)
-
-!
-!Config Key  = fmagic
-!Config Desc = additionnal multiplicator factor used for albedo
-!Config Def  = 1.
-!Config Help = additionnal multiplicator factor used in albedo.F
-!
-  fmagic_omp = 1.
-  call getin('fmagic',fmagic_omp)
-
-!
-!Config Key  = pmagic
-!Config Desc = additional factor used for albedo
-!Config Def  = 0.
-!Config Help = additional factor used in albedo.F
-!
-  pmagic_omp = 0.
-  call getin('pmagic',pmagic_omp)
-
-
-!Config Key = ok_lic_melt
-!Config Desc = Prise en compte de la fonte de la calotte dans le bilan d'eau
-!Config Def  = .false.
-!Config Help = mettre a .false. pour assurer la conservation en eau
-  ok_lic_melt_omp = .false.
-  call getin('ok_lic_melt', ok_lic_melt_omp)
-
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-! PARAMETER FOR THE PLANETARY BOUNDARY LAYER
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-!Config Key  = iflag_pbl
-!Config Desc =
-!Config Def  = 1
-!Config Help =
-!
-  iflag_pbl_omp = 1
-  call getin('iflag_pbl',iflag_pbl_omp)
-!
-!Config Key  = iflag_thermals
-!Config Desc =
-!Config Def  = 0
-!Config Help =
-!
-  iflag_thermals_omp = 0
-  call getin('iflag_thermals',iflag_thermals_omp)
-!
-!
-!Config Key  = iflag_thermals_ed
-!Config Desc =
-!Config Def  = 0
-!Config Help =
-!
-  iflag_thermals_ed_omp = 0
-  call getin('iflag_thermals_ed',iflag_thermals_ed_omp)
-!
-!
-!Config Key  = iflag_thermals_optflux
-!Config Desc =
-!Config Def  = 0
-!Config Help =
-!
-  iflag_thermals_optflux_omp = 0
-  call getin('iflag_thermals_optflux',iflag_thermals_optflux_omp)
-!
-!
-!Config Key  = nsplit_thermals
-!Config Desc =
-!Config Def  = 1
-!Config Help =
-!
-  nsplit_thermals_omp = 1
-  call getin('nsplit_thermals',nsplit_thermals_omp)
-
-!Config Key  = alp_bl_k
-!Config Desc =
-!Config Def  = 0.
-!Config Help =
-!
-  alp_bl_k_omp = 1.
-  call getin('alp_bl_k',alp_bl_k_omp)
-
-!!! nrlmd le 10/04/2012
-
-!Config Key  = iflag_trig_bl
-!Config Desc =  
-!Config Def  = 0
-!Config Help = 
-!
-  iflag_trig_bl_omp = 0
-  call getin('iflag_trig_bl',iflag_trig_bl_omp)
-
-!Config Key  = s_trig_bl
-!Config Desc =  
-!Config Def  = 0
-!Config Help = 
-!
-  s_trig_omp = 2e7
-  call getin('s_trig',s_trig_omp)
-
-!Config Key  = tau_trig_shallow
-!Config Desc =  
-!Config Def  = 0
-!Config Help = 
-!
-  tau_trig_shallow_omp = 600
-  call getin('tau_trig_shallow',tau_trig_shallow_omp)
-
-!Config Key  = tau_trig_deep
-!Config Desc =  
-!Config Def  = 0
-!Config Help = 
-!
-  tau_trig_deep_omp = 1800
-  call getin('tau_trig_deep',tau_trig_deep_omp)
-
-!Config Key  = iflag_clos_bl
-!Config Desc =  
-!Config Def  = 0
-!Config Help = 
-!
-  iflag_clos_bl_omp = 0
-  call getin('iflag_clos_bl',iflag_clos_bl_omp)
-
-!!! fin nrlmd le 10/04/2012
-
-!
-!Config Key  = tau_thermals
-!Config Desc =
-!Config Def  = 0.
-!Config Help =
-!
-  tau_thermals_omp = 0.
-  call getin('tau_thermals',tau_thermals_omp)
-
-!
-!Config Key  = iflag_coupl
-!Config Desc =
-!Config Def  = 0
-!Config Help =
-!
-  iflag_coupl_omp = 0
-  call getin('iflag_coupl',iflag_coupl_omp)
-
-!
-!Config Key  = iflag_clos
-!Config Desc =  
-!Config Def  = 0
-!Config Help = 
-!
-  iflag_clos_omp = 1
-  call getin('iflag_clos',iflag_clos_omp)
-!
-!Config Key  = iflag_cvl_sigd
-!Config Desc =  
-!Config Def  = 0
-!Config Help = 
-!
-  iflag_cvl_sigd_omp = 0
-  call getin('iflag_cvl_sigd',iflag_cvl_sigd_omp)
-
-!Config Key  = iflag_wake
-!Config Desc =  
-!Config Def  = 0
-!Config Help = 
-!
-  iflag_wake_omp = 0
-  call getin('iflag_wake',iflag_wake_omp)
-
-!Config Key  = alp_offset
-!Config Desc =  
-!Config Def  = 0
-!Config Help = 
-!
-  alp_offset_omp = 0.
-  call getin('alp_offset',alp_offset_omp)
-
-!
-!Config Key  = lev_histhf
-!Config Desc =
-!Config Def  = 1
-!Config Help =
-!
-  lev_histhf_omp = 1
-  call getin('lev_histhf',lev_histhf_omp)
-
-!
-!Config Key  = lev_histday
-!Config Desc =
-!Config Def  = 1
-!Config Help =
-!
-  lev_histday_omp = 1
-  call getin('lev_histday',lev_histday_omp)
-
-!
-!Config Key  = lev_histmth
-!Config Desc =
-!Config Def  = 2
-!Config Help =
-!
-  lev_histmth_omp = 2
-  call getin('lev_histmth',lev_histmth_omp)
-!
-!Config Key  = lev_histins
-!Config Desc =
-!Config Def  = 1
-!Config Help =
-!
-  lev_histins_omp = 1
-  call getin('lev_histins',lev_histins_omp)
-  !
-!Config Key  = lev_histLES
-!Config Desc =
-!Config Def  = 1
-!Config Help =
-!
-  lev_histLES_omp = 1
-  call getin('lev_histLES',lev_histLES_omp)
-!
-!Config Key  = lev_histdayNMC
-!Config Desc =
-!Config Def  = 8
-!Config Help =
-!
-  lev_histdayNMC_omp = 8
-  call getin('lev_histdayNMC',lev_histdayNMC_omp)
-!
-!histNMC BEG
-!Config Key  = ok_histNMC
-!Config Desc = ok_histNMC(1) = frequence de sortie fichiers histmthNMC
-!Config Desc = ok_histNMC(2) = frequence de sortie fichiers histdayNMC
-!Config Desc = ok_histNMC(3) = frequence de sortie fichiers histhfNMC
-!Config Def  = n, n, n
-!Config Help =
-!
-  ok_histNMC_omp(1) = .false.
-  ok_histNMC_omp(2) = .false.
-  ok_histNMC_omp(3) = .false.
-  call getin('ok_histNMC',ok_histNMC_omp)
-!
-!Config Key  = freq_outNMC
-!Config Desc = freq_outNMC(1) = frequence de sortie fichiers histmthNMC
-!Config Desc = freq_outNMC(2) = frequence de sortie fichiers histdayNMC
-!Config Desc = freq_outNMC(3) = frequence de sortie fichiers histhfNMC
-!Config Def  = 2592000., 86400., 21600.
-!Config Help =
-!
-! freq_outNMC_omp(1) = 2592000.
-  freq_outNMC_omp(1) = mth_len*86400.
-  freq_outNMC_omp(2) = 86400.
-  freq_outNMC_omp(3) = 21600.
-  call getin('freq_outNMC',freq_outNMC_omp)
-!
-!Config Key  = freq_calNMC
-!Config Desc = freq_calNMC(1) = frequence de calcul fichiers histmthNMC
-!Config Desc = freq_calNMC(2) = frequence de calcul fichiers histdayNMC
-!Config Desc = freq_calNMC(3) = frequence de calcul fichiers histhfNMC
-!Config Def  = pasphys
-!Config Help =
-!
-  freq_calNMC_omp(1) = pasphys
-  freq_calNMC_omp(2) = pasphys
-  freq_calNMC_omp(3) = pasphys
-  call getin('freq_calNMC',freq_calNMC_omp)
-!
-!Config Key  = type_run
-!Config Desc =
-!Config Def  = 'AMIP'/'CFMIP'  ou 'CLIM'/'ENSP'
-!Config Help =
-!
-  type_run_omp = 'AMIP'
-  call getin('type_run',type_run_omp)
-
-!
-!Config Key  = ok_isccp
-!Config Desc =
-!Config Def  = .true.
-!Config Help =
-!
-! ok_isccp = .true.
-  ok_isccp_omp = .false.
-  call getin('ok_isccp',ok_isccp_omp)
-
-!
-!Config Key  = ok_cosp
-!Config Desc =
-!Config Def  = .false.
-!Config Help =
-!
-  ok_cosp_omp = .false.
-  call getin('ok_cosp',ok_cosp_omp)
-
-!
-!Config Key  = ok_mensuelCOSP
-!Config Desc =
-!Config Def  = .true.
-!Config Help =
-!
-  ok_mensuelCOSP_omp = .true.
-  call getin('ok_mensuelCOSP',ok_mensuelCOSP_omp)
-
-!
-!Config Key  = ok_journeCOSP
-!Config Desc =
-!Config Def  = .true.
-!Config Help = 
-!
-  ok_journeCOSP_omp = .true.
-  call getin('ok_journeCOSP',ok_journeCOSP_omp)
-
-!
-!Config Key  = ok_hfCOSP
-!Config Desc =
-!Config Def  = .false.
-!Config Help =
-!
-  ok_hfCOSP_omp = .false.
-  call getin('ok_hfCOSP',ok_hfCOSP_omp)
-
-!
-! coordonnees (lonmin_ins, lonmax_ins, latmin_ins, latmax_ins) pour la zone 
-! avec sorties instantannees tous les pas de temps de la physique => "histbilKP_ins.nc"
-!
-!Config Key  = lonmin_ins
-!Config Desc = 100.  
-!Config Def  = longitude minimale sorties "bilKP_ins"
-!Config Help = 
-!
-   lonmin_ins_omp = 100.
-   call getin('lonmin_ins',lonmin_ins_omp)
-!
-!Config Key  = lonmax_ins
-!Config Desc = 130. 
-!Config Def  = longitude maximale sorties "bilKP_ins"
-!Config Help =
-!
-   lonmax_ins_omp = 130.
-   call getin('lonmax_ins',lonmax_ins_omp)
-!
-!Config Key  = latmin_ins
-!Config Desc = -20.  
-!Config Def  = latitude minimale sorties "bilKP_ins"
-!Config Help = 
-!
-   latmin_ins_omp = -20.
-   call getin('latmin_ins',latmin_ins_omp)
-!
-!Config Key  = latmax_ins
-!Config Desc = 20. 
-!Config Def  = latitude maximale sorties "bilKP_ins"
-!Config Help =
-!
-   latmax_ins_omp = 20.
-   call getin('latmax_ins',latmax_ins_omp)
-!
-!Config Key  = ecrit_hf
-!Config Desc =
-!Config Def  = 1./8. !toutes les 3h
-!Config Help =
-!
-  ecrit_hf_omp = 1./8.
-  call getin('ecrit_hf',ecrit_hf_omp)
-!
-!Config Key  = ecrit_ins
-!Config Desc =
-!Config Def  = 1./48. ! toutes les 1/2 h
-!Config Help =
-!
-  ecrit_ins_omp = 1./48.
-  call getin('ecrit_ins',ecrit_ins_omp)
-!
-!Config Key  = ecrit_day
-!Config Desc =
-!Config Def  = 1.0 !tous les jours
-!Config Help = nombre de jours pour ecriture fichier histday.nc
-!
-  ecrit_day_omp = 1.0
-  call getin('ecrit_day',ecrit_day_omp)
-!
-!Config Key  = ecrit_mth
-!Config Desc =
-!Config Def  = 30. !tous les 30jours (1 fois par mois)
-!Config Help =
-!
-  ecrit_mth_omp = 30.
-  call getin('ecrit_mth',ecrit_mth_omp)
-!
-!Config Key  = ecrit_tra
-!Config Desc =
-!Config Def  = 30. !tous les 30jours (1 fois par mois)
-!Config Help =
-!
-  ecrit_tra_omp = 0.
-  call getin('ecrit_tra',ecrit_tra_omp)
-!
-!Config Key  = ecrit_reg
-!Config Desc =
-!Config Def  = 0.25  !4 fois par jour
-!Config Help =
-!
-  ecrit_reg_omp = 0.25   !4 fois par jour
-  call getin('ecrit_reg',ecrit_reg_omp)
-!
-!
-!
-! PARAMETRES CDRAG
-!
-!Config Key  = f_cdrag_ter
-!Config Desc =
-!Config Def  = 0.8
-!Config Help =
-!
-  f_cdrag_ter_omp = 0.8
-  call getin('f_cdrag_ter',f_cdrag_ter_omp)
-!
-!Config Key  = f_cdrag_oce
-!Config Desc =
-!Config Def  = 0.8
-!Config Help =
-!
-  f_cdrag_oce_omp = 0.8
-  call getin('f_cdrag_oce',f_cdrag_oce_omp)
-!
-! RUGORO
-!Config Key  = f_rugoro
-!Config Desc =
-!Config Def  = 0.
-!Config Help =
-!
-  f_rugoro_omp = 0.
-  call getin('f_rugoro',f_rugoro_omp)
-
-! PARAMETERS FOR CONVECTIVE INHIBITION BY TROPOS. DRYNESS
-!
-!Config Key  = supcrit1
-!Config Desc =
-!Config Def  = .540
-!Config Help =
-!
-  supcrit1_omp = .540
-  call getin('supcrit1',supcrit1_omp)
-
-!
-!Config Key  = supcrit2
-!Config Desc =
-!Config Def  = .600
-!Config Help =
-!
-  supcrit2_omp = .600
-  call getin('supcrit2',supcrit2_omp)
-
-!
-! PARAMETERS FOR THE MIXING DISTRIBUTION
-! iflag_mix: 0=OLD, 
-!            1=NEW (JYG),            
-!            2=NEW + conv. depth inhib. by tropos. dryness
-! '2' is NOT operationnal and should not be used.
-!
-!Config Key  = iflag_mix
-!Config Desc =
-!Config Def  = 1
-!Config Help =
-!
-  iflag_mix_omp = 1
-  call getin('iflag_mix',iflag_mix_omp)
-
-!
-!Config Key  = scut
-!Config Desc =
-!Config Def  = 0.95
-!Config Help =
-!
-  scut_omp = 0.95
-  call getin('scut',scut_omp)
-
-!
-!Config Key  = qqa1
-!Config Desc =
-!Config Def  = 1.0
-!Config Help =
-!
-  qqa1_omp = 1.0
-  call getin('qqa1',qqa1_omp)
-
-!
-!Config Key  = qqa2
-!Config Desc =
-!Config Def  = 0.0
-!Config Help =
-!
-  qqa2_omp = 0.0
-  call getin('qqa2',qqa2_omp)
-
-!
-!Config Key  = gammas
-!Config Desc =
-!Config Def  = 0.05
-!Config Help =
-!
-  gammas_omp = 0.05
-  call getin('gammas',gammas_omp)
-
-!
-!Config Key  = Fmax
-!Config Desc =
-!Config Def  = 0.65
-!Config Help =
-!
-  Fmax_omp = 0.65
-  call getin('Fmax',Fmax_omp)
-
-!
-!Config Key  = alphas  
-!Config Desc =
-!Config Def  = -5.
-!Config Help =
-!
-  alphas_omp = -5.
-  call getin('alphas',alphas_omp)
-
-!Config key = ok_strato
-!Config  Desc = activation de la version strato
-!Config  Def  = .FALSE.
-!Config  Help = active la version stratosphérique de LMDZ de F. Lott
-
-  ok_strato_omp=.FALSE.
-  CALL getin('ok_strato',ok_strato_omp)
-      
-!Config  key = ok_hines
-!Config  Desc = activation de la parametrisation de hines
-!Config  Def  = .FALSE.
-!Config  Help = Clefs controlant la parametrization de Hines
-!               Et la sponge layer (Runs Stratospheriques)
-
-  ok_hines_omp=.FALSE.
-  CALL getin('ok_hines',ok_hines_omp)
-
-!Config Key  = OK_LES                                               
-!Config Desc = Pour des sorties LES                                 
-!Config Def  = .false.                                              
-!Config Help = Pour creer le fichier histLES contenant les sorties  
-!              LES                                                  
-!                                                                   
-  ok_LES_omp = .false.                                              
-  call getin('OK_LES', ok_LES_omp)                                  
-
-!Config Key  = callstats                                               
-!Config Desc = Pour des sorties callstats                                 
-!Config Def  = .false.                                              
-!Config Help = Pour creer le fichier stats contenant les sorties  
-!              stats                                                  
-!                                                                   
-  callstats_omp = .false.                                              
-  call getin('callstats', callstats_omp)                                  
-!
-!Config Key  = ecrit_LES
-!Config Desc = Frequence d'ecriture des resultats du LES en nombre de jours;
-!              par defaut 1., i.e. 1 jour
-!Config Def  = 1./8.
-!Config Help = ... 
-!
-!
-  ecrit_LES_omp = 1./8.
-  call getin('ecrit_LES', ecrit_LES_omp)
-!
-  read_climoz = 0 ! default value
-  call getin('read_climoz', read_climoz)
-
-  carbon_cycle_tr_omp=.FALSE.
-  CALL getin('carbon_cycle_tr',carbon_cycle_tr_omp)
-
-  carbon_cycle_cpl_omp=.FALSE.
-  CALL getin('carbon_cycle_cpl',carbon_cycle_cpl_omp)
-
-!$OMP END MASTER
-!$OMP BARRIER
-
-    R_ecc = R_ecc_omp
-    R_peri = R_peri_omp
-    R_incl = R_incl_omp
-    solaire = solaire_omp
-    co2_ppm = co2_ppm_omp
-    RCO2 = RCO2_omp
-    CH4_ppb = CH4_ppb_omp
-    RCH4 = RCH4_omp
-    N2O_ppb = N2O_ppb_omp
-    RN2O = RN2O_omp
-    CFC11_ppt = CFC11_ppt_omp
-    RCFC11 = RCFC11_omp
-    CFC12_ppt = CFC12_ppt_omp
-    RCFC12 = RCFC12_omp
-    RCO2_act = RCO2
-    RCH4_act = RCH4
-    RN2O_act = RN2O
-    RCFC11_act = RCFC11
-    RCFC12_act = RCFC12
-    RCO2_per = RCO2_per_omp
-    RCH4_per = RCH4_per_omp
-    RN2O_per = RN2O_per_omp
-    RCFC11_per = RCFC11_per_omp
-    RCFC12_per = RCFC12_per_omp
-    
-    cycle_diurne = cycle_diurne_omp
-    soil_model = soil_model_omp
-    new_oliq = new_oliq_omp
-    ok_orodr = ok_orodr_omp
-    ok_orolf = ok_orolf_omp
-    ok_limitvrai = ok_limitvrai_omp
-    nbapp_rad = nbapp_rad_omp
-    iflag_con = iflag_con_omp
-
-    epmax = epmax_omp
-    ok_adj_ema = ok_adj_ema_omp
-    iflag_clw = iflag_clw_omp
-    cld_lc_lsc = cld_lc_lsc_omp
-    cld_lc_con = cld_lc_con_omp
-    cld_tau_lsc = cld_tau_lsc_omp
-    cld_tau_con = cld_tau_con_omp
-    ffallv_lsc = ffallv_lsc_omp
-    ffallv_con = ffallv_con_omp
-    coef_eva = coef_eva_omp
-    reevap_ice = reevap_ice_omp
-    iflag_pdf = iflag_pdf_omp
-    solarlong0 = solarlong0_omp
-    qsol0 = qsol0_omp
-    inertie_sol = inertie_sol_omp
-    inertie_ice = inertie_ice_omp
-    inertie_sno = inertie_sno_omp
-    rad_froid = rad_froid_omp
-    rad_chau1 = rad_chau1_omp
-    rad_chau2 = rad_chau2_omp
-    t_glace_min = t_glace_min_omp
-    t_glace_max = t_glace_max_omp
-    rei_min = rei_min_omp
-    rei_max = rei_max_omp
-    top_height = top_height_omp
-    overlap = overlap_omp
-    cdmmax = cdmmax_omp
-    cdhmax = cdhmax_omp
-    ksta = ksta_omp
-    ksta_ter = ksta_ter_omp
-    ok_kzmin = ok_kzmin_omp
-    fmagic = fmagic_omp
-    pmagic = pmagic_omp
-    iflag_pbl = iflag_pbl_omp
-    lev_histhf = lev_histhf_omp
-    lev_histday = lev_histday_omp
-    lev_histmth = lev_histmth_omp
-    lev_histins = lev_histins_omp
-    lev_histLES = lev_histLES_omp
-    lev_histdayNMC = lev_histdayNMC_omp
-    ok_histNMC(:) = ok_histNMC_omp(:)
-    freq_outNMC(:) = freq_outNMC_omp(:)
-    freq_calNMC(:) = freq_calNMC_omp(:)
-
-    type_ocean = type_ocean_omp
-    version_ocean = version_ocean_omp
-    ok_veget = ok_veget_omp
-    ok_newmicro = ok_newmicro_omp
-    ok_journe = ok_journe_omp
-    ok_hf = ok_hf_omp
-    ok_mensuel = ok_mensuel_omp
-    ok_instan = ok_instan_omp
-    freq_ISCCP = freq_ISCCP_omp
-    ecrit_ISCCP = ecrit_ISCCP_omp
-    freq_COSP = freq_COSP_omp
-    ok_ade = ok_ade_omp
-    ok_aie = ok_aie_omp
-    aerosol_couple = aerosol_couple_omp
-    flag_aerosol=flag_aerosol_omp
-    new_aod=new_aod_omp
-    aer_type = aer_type_omp
-    bl95_b0 = bl95_b0_omp
-    bl95_b1 = bl95_b1_omp
-    fact_cldcon = fact_cldcon_omp
-    facttemps = facttemps_omp
-    ratqsbas = ratqsbas_omp
-    ratqshaut = ratqshaut_omp
-    tau_ratqs = tau_ratqs_omp
-
-    iflag_radia = iflag_radia_omp
-    iflag_rrtm = iflag_rrtm_omp
-    iflag_cldcon = iflag_cldcon_omp
-    iflag_ratqs = iflag_ratqs_omp
-    ip_ebil_phy = ip_ebil_phy_omp
-    iflag_thermals = iflag_thermals_omp
-    iflag_thermals_ed = iflag_thermals_ed_omp
-    iflag_thermals_optflux = iflag_thermals_optflux_omp
-    nsplit_thermals = nsplit_thermals_omp
-    tau_thermals = tau_thermals_omp
-    alp_bl_k = alp_bl_k_omp
-!!! nrlmd le 10/04/2012
-    iflag_trig_bl = iflag_trig_bl_omp
-    s_trig = s_trig_omp
-    tau_trig_shallow = tau_trig_shallow_omp
-    tau_trig_deep = tau_trig_deep_omp
-    iflag_clos_bl = iflag_clos_bl_omp
-!!! fin nrlmd le 10/04/2012
-    iflag_coupl = iflag_coupl_omp
-    iflag_clos = iflag_clos_omp
-    iflag_wake = iflag_wake_omp
-    alp_offset = alp_offset_omp
-    iflag_cvl_sigd = iflag_cvl_sigd_omp
-    type_run = type_run_omp
-    ok_isccp = ok_isccp_omp
-    ok_cosp = ok_cosp_omp
-    ok_mensuelCOSP = ok_mensuelCOSP_omp
-    ok_journeCOSP = ok_journeCOSP_omp
-    ok_hfCOSP = ok_hfCOSP_omp
-    seuil_inversion=seuil_inversion_omp
-    lonmin_ins = lonmin_ins_omp
-    lonmax_ins = lonmax_ins_omp
-    latmin_ins = latmin_ins_omp
-    latmax_ins = latmax_ins_omp
-    ecrit_hf   = ecrit_hf_omp
-    ecrit_ins   = ecrit_ins_omp
-    ecrit_day = ecrit_day_omp
-    ecrit_mth = ecrit_mth_omp
-    ecrit_tra = ecrit_tra_omp
-    ecrit_reg = ecrit_reg_omp
-    cvl_corr = cvl_corr_omp
-    ok_lic_melt = ok_lic_melt_omp
-    f_cdrag_ter=f_cdrag_ter_omp
-    f_cdrag_oce=f_cdrag_oce_omp
-    f_rugoro=f_rugoro_omp
-    supcrit1 = supcrit1_omp
-    supcrit2 = supcrit2_omp
-    iflag_mix = iflag_mix_omp
-    scut = scut_omp
-    qqa1 = qqa1_omp
-    qqa2 = qqa2_omp
-    gammas = gammas_omp
-    Fmax = Fmax_omp
-    alphas = alphas_omp
-    ok_strato = ok_strato_omp
-    ok_hines = ok_hines_omp
-    ok_LES = ok_LES_omp
-    callstats = callstats_omp
-    ecrit_LES = ecrit_LES_omp
-    carbon_cycle_tr = carbon_cycle_tr_omp
-    carbon_cycle_cpl = carbon_cycle_cpl_omp
-
-! Test of coherence between type_ocean and version_ocean
-    IF (type_ocean=='couple' .AND. (version_ocean/='opa8' .AND. version_ocean/='nemo') ) THEN
-       WRITE(lunout,*)' ERROR version_ocean=',version_ocean,' not valid in coupled configuration'
-       CALL abort_gcm('conf_phys','version_ocean not valid',1)
-    END IF
-
-    IF (type_ocean=='slab' .AND. version_ocean=='xxxxxx') THEN
-       version_ocean='sicOBS'
-    ELSE IF (type_ocean=='slab' .AND. version_ocean/='sicOBS') THEN
-       WRITE(lunout,*)' ERROR version_ocean=',version_ocean,' not valid with slab ocean'
-       CALL abort_gcm('conf_phys','version_ocean not valid',1)
-    END IF
-
-! Test sur new_aod. Ce flag permet de retrouver les resultats de l'AR4
-! il n'est utilisable que lors du couplage avec le SO4 seul 
-    IF (ok_ade .OR. ok_aie) THEN 
-       IF ( flag_aerosol .EQ. 0 ) THEN
-          CALL abort_gcm('conf_phys','flag_aerosol=0 not compatible avec ok_ade ou ok_aie=.TRUE.',1)
-       END IF
-       IF ( .NOT. new_aod .AND.  flag_aerosol .NE. 1) THEN
-          CALL abort_gcm('conf_phys','new_aod=.FALSE. not compatible avec flag_aerosol=1',1)
-       END IF
-    END IF
-
-!$OMP MASTER
-
-  write(lunout,*)' ##############################################'
-  write(lunout,*)' Configuration des parametres de la physique: '
-  write(lunout,*)' Type ocean = ', type_ocean
-  write(lunout,*)' Version ocean = ', version_ocean
-  write(lunout,*)' Config veget = ', ok_veget
-  write(lunout,*)' Sortie journaliere = ', ok_journe
-  write(lunout,*)' Sortie haute frequence = ', ok_hf
-  write(lunout,*)' Sortie mensuelle = ', ok_mensuel
-  write(lunout,*)' Sortie instantanee = ', ok_instan
-  write(lunout,*)' Frequence appel simulateur ISCCP, freq_ISCCP =', freq_ISCCP
-  write(lunout,*)' Frequence appel simulateur ISCCP, ecrit_ISCCP =', ecrit_ISCCP
-  write(lunout,*)' Frequence appel simulateur COSP, freq_COSP =', freq_COSP
-  write(lunout,*)' Sortie bilan d''energie, ip_ebil_phy =', ip_ebil_phy
-  write(lunout,*)' Excentricite = ',R_ecc
-  write(lunout,*)' Equinoxe = ',R_peri
-  write(lunout,*)' Inclinaison =',R_incl
-  write(lunout,*)' Constante solaire =',solaire
-  write(lunout,*)' co2_ppm =',co2_ppm
-  write(lunout,*)' RCO2_act = ',RCO2_act
-  write(lunout,*)' CH4_ppb =',CH4_ppb,' RCH4_act = ',RCH4_act
-  write(lunout,*)' N2O_ppb =',N2O_ppb,' RN2O_act=  ',RN2O_act
-  write(lunout,*)' CFC11_ppt=',CFC11_ppt,' RCFC11_act=  ',RCFC11_act
-  write(lunout,*)' CFC12_ppt=',CFC12_ppt,' RCFC12_act=  ',RCFC12_act
-  write(lunout,*)' RCO2_per = ',RCO2_per,' RCH4_per = ', RCH4_per
-  write(lunout,*)' RN2O_per = ',RN2O_per,' RCFC11_per = ', RCFC11_per
-  write(lunout,*)' RCFC12_per = ',RCFC12_per
-  write(lunout,*)' cvl_corr=', cvl_corr
-  write(lunout,*)'ok_lic_melt=', ok_lic_melt
-  write(lunout,*)'cycle_diurne=',cycle_diurne
-  write(lunout,*)'soil_model=',soil_model
-  write(lunout,*)'new_oliq=',new_oliq
-  write(lunout,*)'ok_orodr=',ok_orodr
-  write(lunout,*)'ok_orolf=',ok_orolf
-  write(lunout,*)'ok_limitvrai=',ok_limitvrai
-  write(lunout,*)'nbapp_rad=',nbapp_rad
-  write(lunout,*)'iflag_con=',iflag_con
-  write(lunout,*)' epmax = ', epmax
-  write(lunout,*)' ok_adj_ema = ', ok_adj_ema
-  write(lunout,*)' iflag_clw = ', iflag_clw
-  write(lunout,*)' cld_lc_lsc = ', cld_lc_lsc
-  write(lunout,*)' cld_lc_con = ', cld_lc_con
-  write(lunout,*)' cld_tau_lsc = ', cld_tau_lsc
-  write(lunout,*)' cld_tau_con = ', cld_tau_con
-  write(lunout,*)' ffallv_lsc = ', ffallv_lsc
-  write(lunout,*)' ffallv_con = ', ffallv_con
-  write(lunout,*)' coef_eva = ', coef_eva
-  write(lunout,*)' reevap_ice = ', reevap_ice
-  write(lunout,*)' iflag_pdf = ', iflag_pdf
-  write(lunout,*)' iflag_cldcon = ', iflag_cldcon
-  write(lunout,*)' iflag_radia = ', iflag_radia
-  write(lunout,*)' iflag_rrtm = ', iflag_rrtm
-  write(lunout,*)' iflag_ratqs = ', iflag_ratqs
-  write(lunout,*)' seuil_inversion = ', seuil_inversion
-  write(lunout,*)' fact_cldcon = ', fact_cldcon
-  write(lunout,*)' facttemps = ', facttemps
-  write(lunout,*)' ok_newmicro = ',ok_newmicro 
-  write(lunout,*)' ratqsbas = ',ratqsbas 
-  write(lunout,*)' ratqshaut = ',ratqshaut 
-  write(lunout,*)' tau_ratqs = ',tau_ratqs 
-  write(lunout,*)' top_height = ',top_height 
-  write(lunout,*)' rad_froid = ',rad_froid
-  write(lunout,*)' rad_chau1 = ',rad_chau1
-  write(lunout,*)' rad_chau2 = ',rad_chau2
-  write(lunout,*)' t_glace_min = ',t_glace_min
-  write(lunout,*)' t_glace_max = ',t_glace_max
-  write(lunout,*)' rei_min = ',rei_min
-  write(lunout,*)' rei_max = ',rei_max
-  write(lunout,*)' overlap = ',overlap 
-  write(lunout,*)' cdmmax = ',cdmmax 
-  write(lunout,*)' cdhmax = ',cdhmax 
-  write(lunout,*)' ksta = ',ksta 
-  write(lunout,*)' ksta_ter = ',ksta_ter 
-  write(lunout,*)' ok_kzmin = ',ok_kzmin 
-  write(lunout,*)' fmagic = ',fmagic
-  write(lunout,*)' pmagic = ',pmagic
-  write(lunout,*)' ok_ade = ',ok_ade
-  write(lunout,*)' ok_aie = ',ok_aie
-  write(lunout,*)' aerosol_couple = ', aerosol_couple
-  write(lunout,*)' flag_aerosol = ', flag_aerosol
-  write(lunout,*)' new_aod = ', new_aod
-  write(lunout,*)' aer_type = ',aer_type
-  write(lunout,*)' bl95_b0 = ',bl95_b0
-  write(lunout,*)' bl95_b1 = ',bl95_b1
-  write(lunout,*)' lev_histhf = ',lev_histhf 
-  write(lunout,*)' lev_histday = ',lev_histday 
-  write(lunout,*)' lev_histmth = ',lev_histmth 
-  write(lunout,*)' lev_histins = ',lev_histins
-  write(lunout,*)' lev_histLES = ',lev_histLES
-  write(lunout,*)' lev_histdayNMC = ',lev_histdayNMC
-  write(lunout,*)' ok_histNMC = ',ok_histNMC
-  write(lunout,*)' freq_outNMC = ',freq_outNMC
-  write(lunout,*)' freq_calNMC = ',freq_calNMC
-  write(lunout,*)' iflag_pbl = ', iflag_pbl
-  write(lunout,*)' iflag_thermals = ', iflag_thermals
-  write(lunout,*)' iflag_thermals_ed = ', iflag_thermals_ed
-  write(lunout,*)' iflag_thermals_optflux = ', iflag_thermals_optflux
-  write(lunout,*)' iflag_clos = ', iflag_clos
-  write(lunout,*)' type_run = ',type_run 
-  write(lunout,*)' ok_isccp = ',ok_isccp 
-  write(lunout,*)' ok_cosp = ',ok_cosp
-  write(lunout,*)' ok_mensuelCOSP = ',ok_mensuelCOSP
-  write(lunout,*)' ok_journeCOSP = ',ok_journeCOSP
-  write(lunout,*)' ok_hfCOSP =',ok_hfCOSP
-  write(lunout,*)' solarlong0 = ', solarlong0
-  write(lunout,*)' qsol0 = ', qsol0
-  write(lunout,*)' inertie_sol = ', inertie_sol
-  write(lunout,*)' inertie_ice = ', inertie_ice
-  write(lunout,*)' inertie_sno = ', inertie_sno
-  write(lunout,*)' f_cdrag_ter = ',f_cdrag_ter
-  write(lunout,*)' f_cdrag_oce = ',f_cdrag_oce
-  write(lunout,*)' f_rugoro = ',f_rugoro
-  write(lunout,*)' supcrit1 = ', supcrit1
-  write(lunout,*)' supcrit2 = ', supcrit2
-  write(lunout,*)' iflag_mix = ', iflag_mix
-  write(lunout,*)' scut = ', scut
-  write(lunout,*)' qqa1 = ', qqa1
-  write(lunout,*)' qqa2 = ', qqa2
-  write(lunout,*)' gammas = ', gammas
-  write(lunout,*)' Fmax = ', Fmax
-  write(lunout,*)' alphas = ', alphas
-  write(lunout,*)' iflag_wake = ', iflag_wake
-  write(lunout,*)' alp_offset = ', alp_offset
-!!! nrlmd le 10/04/2012
-  write(lunout,*)' iflag_trig_bl = ', iflag_trig_bl
-  write(lunout,*)' s_trig = ', s_trig
-  write(lunout,*)' tau_trig_shallow = ', tau_trig_shallow
-  write(lunout,*)' tau_trig_deep = ', tau_trig_deep
-  write(lunout,*)' iflag_clos_bl = ', iflag_clos_bl
-!!! fin nrlmd le 10/04/2012
-
-  write(lunout,*)' lonmin lonmax latmin latmax bilKP_ins =',&
-   lonmin_ins, lonmax_ins, latmin_ins, latmax_ins
-  write(lunout,*)' ecrit_ hf, ins, day, mth, reg, tra, ISCCP, LES',&
-   ecrit_hf, ecrit_ins, ecrit_day, ecrit_mth, ecrit_reg, ecrit_tra, ecrit_ISCCP, ecrit_LES
-
-  write(lunout,*) 'ok_strato = ', ok_strato
-  write(lunout,*) 'ok_hines = ',  ok_hines
-  write(lunout,*) 'read_climoz = ', read_climoz
-  write(lunout,*) 'carbon_cycle_tr = ', carbon_cycle_tr
-  write(lunout,*) 'carbon_cycle_cpl = ', carbon_cycle_cpl
-  
-!$OMP END MASTER
-
-  return
-  
-  end subroutine conf_phys
-
-end module conf_phys_m
-!
-!#################################################################
-!
-
-   subroutine conf_interface(tau_calv)
-
-   use IOIPSL
-   implicit none
-   include "iniprint.h"
-! Configuration de l'interace atm/surf
-!
-! tau_calv:    temps de relaxation pour la fonte des glaciers
-
-  REAL          :: tau_calv
-  REAL,SAVE     :: tau_calv_omp
-
-!
-!Config Key  = tau_calv
-!Config Desc = temps de relaxation pour fonte des glaciers en jours
-!Config Def  = 1 an 
-!Config Help = 
-!
-  tau_calv_omp = 360.*10.
-!$OMP MASTER
-  call getin('tau_calv',tau_calv_omp)
-!$OMP END MASTER
-!$OMP BARRIER
-
-  tau_calv=tau_calv_omp
-  
-!$OMP MASTER
-  write(lunout,*)' ##############################################'
-  WRITE(lunout,*)' Configuration de l''interface atm/surfaces  : '
-  WRITE(lunout,*)' tau_calv = ',tau_calv
-!$OMP END MASTER
-
-  return
-
-  end subroutine conf_interface
Index: LMDZ5/branches/testing/libf/phylmd/conf_phys_m.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/conf_phys_m.F90	(revision 1707)
+++ LMDZ5/branches/testing/libf/phylmd/conf_phys_m.F90	(revision 1707)
@@ -0,0 +1,1965 @@
+
+!
+! $Id: conf_phys.F90 1668 2012-10-12 10:47:37Z idelkadi $
+!
+!
+!
+module conf_phys_m
+
+   implicit none
+
+contains
+
+  subroutine conf_phys(ok_journe, ok_mensuel, ok_instan, ok_hf, &
+                       ok_LES,&
+                       callstats,&
+                       solarlong0,seuil_inversion, &
+                       fact_cldcon, facttemps,ok_newmicro,iflag_radia,&
+                       iflag_cldcon, &
+                       iflag_ratqs,ratqsbas,ratqshaut,tau_ratqs, &
+  		       ok_ade, ok_aie, aerosol_couple, &
+                       flag_aerosol, new_aod, &
+                       bl95_b0, bl95_b1,&
+                       read_climoz, &
+                       alp_offset)
+
+   use IOIPSL
+   USE surface_data
+   USE phys_cal_mod
+   USE carbon_cycle_mod, ONLY : carbon_cycle_tr, carbon_cycle_cpl
+   use control_mod
+
+ include "conema3.h"
+ include "fisrtilp.h"
+ include "nuage.h"
+ include "YOMCST.h"
+ include "YOMCST2.h"
+
+ include "thermcell.h"
+ include "iniprint.h"
+
+!IM : on inclut/initialise les taux de CH4, N2O, CFC11 et CFC12
+include "clesphys.h"
+include "compbl.h"
+include "comsoil.h"
+!
+! Configuration de la "physique" de LMDZ a l'aide de la fonction
+! GETIN de IOIPSL
+!
+! LF 05/2001
+!
+
+!
+! type_ocean:      type d'ocean (force, slab, couple)
+! version_ocean:   version d'ocean (opa8/nemo pour type_ocean=couple ou 
+!                                   sicOBS pour type_ocean=slab)
+! ok_veget:   type de modele de vegetation
+! ok_journe:  sorties journalieres
+! ok_hf:  sorties haute frequence
+! ok_mensuel: sorties mensuelles
+! ok_instan:  sorties instantanees
+! ok_ade, ok_aie: apply or not aerosol direct and indirect effects
+! bl95_b*: parameters in the formula to link CDNC to aerosol mass conc 
+!
+
+
+! Sortie:
+  logical              :: ok_newmicro
+  integer              :: iflag_radia
+  logical              :: ok_journe, ok_mensuel, ok_instan, ok_hf
+  logical              :: ok_LES
+  LOGICAL              :: callstats
+  LOGICAL              :: ok_ade, ok_aie, aerosol_couple
+  INTEGER              :: flag_aerosol
+  LOGICAL              :: new_aod
+  REAL                 :: bl95_b0, bl95_b1
+  real                 :: fact_cldcon, facttemps,ratqsbas,ratqshaut,tau_ratqs
+  integer              :: iflag_cldcon
+  integer              :: iflag_ratqs
+
+  character (len = 6),SAVE  :: type_ocean_omp, version_ocean_omp, ocean_omp
+  CHARACTER(len = 8),SAVE   :: aer_type_omp
+  logical,SAVE              :: ok_veget_omp, ok_newmicro_omp
+  logical,SAVE        :: ok_journe_omp, ok_mensuel_omp, ok_instan_omp, ok_hf_omp        
+  logical,SAVE        :: ok_LES_omp   
+  LOGICAL,SAVE        :: callstats_omp
+  LOGICAL,SAVE        :: ok_ade_omp, ok_aie_omp, aerosol_couple_omp
+  INTEGER, SAVE       :: flag_aerosol_omp
+  LOGICAL, SAVE       :: new_aod_omp
+  REAL,SAVE           :: bl95_b0_omp, bl95_b1_omp
+  REAL,SAVE           :: freq_ISCCP_omp, ecrit_ISCCP_omp
+  REAL,SAVE           :: freq_COSP_omp
+  real,SAVE           :: fact_cldcon_omp, facttemps_omp,ratqsbas_omp
+  real,SAVE           :: ratqshaut_omp
+  real,SAVE           :: tau_ratqs_omp
+  integer,SAVE        :: iflag_radia_omp
+  integer,SAVE        :: iflag_rrtm_omp
+  integer,SAVE        :: iflag_cldcon_omp, ip_ebil_phy_omp
+  integer,SAVE        :: iflag_ratqs_omp
+
+  Real,SAVE           :: f_cdrag_ter_omp,f_cdrag_oce_omp
+  Real,SAVE           :: f_rugoro_omp   
+
+! Local
+  real                 :: zzz
+
+  real :: seuil_inversion
+  real,save :: seuil_inversion_omp
+
+  integer,SAVE :: iflag_thermals_ed_omp,iflag_thermals_optflux_omp
+  integer,SAVE :: iflag_thermals_omp,nsplit_thermals_omp
+  real,save :: tau_thermals_omp,alp_bl_k_omp
+!!! nrlmd le 10/04/2012
+  integer,SAVE :: iflag_trig_bl_omp,iflag_clos_bl_omp
+  integer,SAVE :: tau_trig_shallow_omp,tau_trig_deep_omp
+  real,SAVE    :: s_trig_omp
+!!! fin nrlmd le 10/04/2012
+  real :: alp_offset
+  REAL, SAVE :: alp_offset_omp
+  integer,SAVE :: iflag_coupl_omp,iflag_clos_omp,iflag_wake_omp
+  integer,SAVE :: iflag_cvl_sigd_omp
+  REAL, SAVE :: supcrit1_omp, supcrit2_omp
+  INTEGER, SAVE :: iflag_mix_omp
+  real, save :: scut_omp, qqa1_omp, qqa2_omp, gammas_omp, Fmax_omp, alphas_omp
+
+  REAL,SAVE :: R_ecc_omp,R_peri_omp,R_incl_omp,solaire_omp
+  REAL,SAVE :: co2_ppm_omp, RCO2_omp, co2_ppm_per_omp, RCO2_per_omp
+  REAL,SAVE :: CH4_ppb_omp, RCH4_omp, CH4_ppb_per_omp, RCH4_per_omp
+  REAL,SAVE :: N2O_ppb_omp, RN2O_omp, N2O_ppb_per_omp, RN2O_per_omp
+  REAL,SAVE :: CFC11_ppt_omp,RCFC11_omp,CFC11_ppt_per_omp,RCFC11_per_omp
+  REAL,SAVE :: CFC12_ppt_omp,RCFC12_omp,CFC12_ppt_per_omp,RCFC12_per_omp
+  REAL,SAVE :: epmax_omp
+  LOGICAL,SAVE :: ok_adj_ema_omp
+  INTEGER,SAVE :: iflag_clw_omp
+  REAL,SAVE :: cld_lc_lsc_omp,cld_lc_con_omp,cld_tau_lsc_omp,cld_tau_con_omp
+  REAL,SAVE :: ffallv_lsc_omp, ffallv_con_omp,coef_eva_omp
+  LOGICAL,SAVE :: reevap_ice_omp
+  INTEGER,SAVE :: iflag_pdf_omp
+  REAL,SAVE :: rad_froid_omp, rad_chau1_omp, rad_chau2_omp
+  REAL,SAVE :: t_glace_min_omp, t_glace_max_omp
+  REAL,SAVE :: rei_min_omp, rei_max_omp
+  REAL,SAVE :: inertie_sol_omp,inertie_sno_omp,inertie_ice_omp
+  REAL,SAVE :: qsol0_omp
+  REAL      :: solarlong0
+  REAL,SAVE :: solarlong0_omp
+  INTEGER,SAVE :: top_height_omp,overlap_omp
+  REAL,SAVE :: cdmmax_omp,cdhmax_omp,ksta_omp,ksta_ter_omp
+  LOGICAL,SAVE :: ok_kzmin_omp
+  REAL, SAVE ::  fmagic_omp, pmagic_omp
+  INTEGER,SAVE :: iflag_pbl_omp,lev_histhf_omp,lev_histday_omp,lev_histmth_omp
+  Integer, save :: lev_histins_omp, lev_histLES_omp 
+  INTEGER, SAVE :: lev_histdayNMC_omp
+  LOGICAL, SAVE :: ok_histNMC_omp(3)
+  REAL, SAVE :: freq_outNMC_omp(3), freq_calNMC_omp(3)
+  CHARACTER*4, SAVE :: type_run_omp
+  LOGICAL,SAVE :: ok_isccp_omp
+  LOGICAL,SAVE :: ok_cosp_omp
+  LOGICAL,SAVE :: ok_mensuelCOSP_omp,ok_journeCOSP_omp,ok_hfCOSP_omp
+  REAL,SAVE :: lonmin_ins_omp, lonmax_ins_omp, latmin_ins_omp, latmax_ins_omp
+  REAL,SAVE :: ecrit_hf_omp, ecrit_day_omp, ecrit_mth_omp, ecrit_reg_omp
+  REAL,SAVE :: ecrit_ins_omp
+  REAL,SAVE :: ecrit_LES_omp
+  REAL,SAVE :: ecrit_tra_omp
+  REAL,SAVE :: cvl_corr_omp
+  LOGICAL,SAVE :: ok_lic_melt_omp
+!
+  LOGICAL,SAVE :: cycle_diurne_omp,soil_model_omp,new_oliq_omp
+  LOGICAL,SAVE :: ok_orodr_omp, ok_orolf_omp, ok_limitvrai_omp
+  INTEGER, SAVE :: nbapp_rad_omp, iflag_con_omp
+  LOGICAL,SAVE :: ok_strato_omp
+  LOGICAL,SAVE :: ok_hines_omp
+  LOGICAL,SAVE      :: carbon_cycle_tr_omp
+  LOGICAL,SAVE      :: carbon_cycle_cpl_omp
+
+  integer, intent(out):: read_climoz ! read ozone climatology, OpenMP shared
+  ! Allowed values are 0, 1 and 2
+  ! 0: do not read an ozone climatology
+  ! 1: read a single ozone climatology that will be used day and night
+  ! 2: read two ozone climatologies, the average day and night
+  ! climatology and the daylight climatology
+
+!$OMP MASTER 
+!Config Key  = type_ocean 
+!Config Desc = Type d'ocean
+!Config Def  = force
+!Config Help = Type d'ocean utilise: force, slab,couple
+!
+  type_ocean_omp = 'force '
+  call getin('type_ocean', type_ocean_omp)
+!
+!Config Key  = version_ocean 
+!Config Desc = Version d'ocean
+!Config Def  = xxxxxx
+!Config Help = Version d'ocean utilise: opa8/nemo/sicOBS/xxxxxx
+!
+  version_ocean_omp = 'xxxxxx'
+  call getin('version_ocean', version_ocean_omp)
+
+!Config Key  = OCEAN
+!Config Desc = Old parameter name for type_ocean
+!Config Def  = yyyyyy
+!Config Help = This is only for testing purpose
+!
+  ocean_omp = 'yyyyyy'
+  call getin('OCEAN', ocean_omp)
+  IF (ocean_omp /= 'yyyyyy') THEN
+     WRITE(lunout,*)'ERROR!! Old variable name OCEAN used in parmeter file.'
+     WRITE(lunout,*)'Variable OCEAN has been replaced by the variable type_ocean.'
+     WRITE(lunout,*)'You have to update your parameter file physiq.def to succed running'
+     CALL abort_gcm('conf_phys','Variable OCEAN no longer existing, use variable name type_ocean',1)
+  END IF
+
+!
+!Config Key  = VEGET 
+!Config Desc = Type de modele de vegetation
+!Config Def  = .false.
+!Config Help = Type de modele de vegetation utilise
+!
+  ok_veget_omp = .false.
+  call getin('VEGET', ok_veget_omp)
+!
+!Config Key  = OK_journe
+!Config Desc = Pour des sorties journalieres 
+!Config Def  = .false.
+!Config Help = Pour creer le fichier histday contenant les sorties
+!              journalieres 
+!
+  ok_journe_omp = .false.
+  call getin('OK_journe', ok_journe_omp)
+!
+!Config Key  = ok_hf
+!Config Desc = Pour des sorties haute frequence
+!Config Def  = .false.
+!Config Help = Pour creer le fichier histhf contenant les sorties
+!              haute frequence ( 3h ou 6h)
+!
+  ok_hf_omp = .false.
+  call getin('ok_hf', ok_hf_omp)
+!
+!Config Key  = OK_mensuel
+!Config Desc = Pour des sorties mensuelles 
+!Config Def  = .true.
+!Config Help = Pour creer le fichier histmth contenant les sorties
+!              mensuelles 
+!
+  ok_mensuel_omp = .true.
+  call getin('OK_mensuel', ok_mensuel_omp)
+!
+!Config Key  = OK_instan
+!Config Desc = Pour des sorties instantanees 
+!Config Def  = .false.
+!Config Help = Pour creer le fichier histins contenant les sorties
+!              instantanees 
+!
+  ok_instan_omp = .false.
+  call getin('OK_instan', ok_instan_omp)
+!
+!Config Key  = ok_ade
+!Config Desc = Aerosol direct effect or not?
+!Config Def  = .false.
+!Config Help = Used in radlwsw.F
+!
+  ok_ade_omp = .false.
+  call getin('ok_ade', ok_ade_omp)
+
+!
+!Config Key  = ok_aie
+!Config Desc = Aerosol indirect effect or not?
+!Config Def  = .false.
+!Config Help = Used in nuage.F and radlwsw.F
+!
+  ok_aie_omp = .false.
+  call getin('ok_aie', ok_aie_omp)
+
+!
+!Config Key  = aerosol_couple
+!Config Desc = read aerosol in file or calcul by inca
+!Config Def  = .false.
+!Config Help = Used in physiq.F
+!
+  aerosol_couple_omp = .false.
+  CALL getin('aerosol_couple',aerosol_couple_omp)
+
+!
+!Config Key  = flag_aerosol
+!Config Desc = which aerosol is use for coupled model
+!Config Def  = 1
+!Config Help = Used in physiq.F
+!
+! - flag_aerosol=0 => no aerosol
+! - flag_aerosol=1 => so4 only (defaut) 
+! - flag_aerosol=2 => bc  only 
+! - flag_aerosol=3 => pom only
+! - flag_aerosol=4 => seasalt only 
+! - flag_aerosol=5 => dust only
+! - flag_aerosol=6 => all aerosol
+
+  flag_aerosol_omp = 0
+  CALL getin('flag_aerosol',flag_aerosol_omp)
+
+! Temporary variable for testing purpose!!
+!Config Key  = new_aod
+!Config Desc = which calcul of aeropt
+!Config Def  = false
+!Config Help = Used in physiq.F
+!
+  new_aod_omp = .true.
+  CALL getin('new_aod',new_aod_omp)
+
+! 
+!Config Key  = aer_type 
+!Config Desc = Use a constant field for the aerosols 
+!Config Def  = scenario 
+!Config Help = Used in readaerosol.F90 
+! 
+  aer_type_omp = 'scenario' 
+  call getin('aer_type', aer_type_omp) 
+
+!
+!Config Key  = bl95_b0
+!Config Desc = Parameter in CDNC-maer link (Boucher&Lohmann 1995)
+!Config Def  = .false.
+!Config Help = Used in nuage.F
+!
+  bl95_b0_omp = 2.
+  call getin('bl95_b0', bl95_b0_omp)
+
+!Config Key  = bl95_b1
+!Config Desc = Parameter in CDNC-maer link (Boucher&Lohmann 1995)
+!Config Def  = .false.
+!Config Help = Used in nuage.F
+!
+  bl95_b1_omp = 0.2
+  call getin('bl95_b1', bl95_b1_omp)
+
+!Config Key  = freq_ISCCP
+!Config Desc = Frequence d'appel du simulateur ISCCP en secondes;
+!              par defaut 10800, i.e. 3 heures 
+!Config Def  = 10800.
+!Config Help = Used in ini_histISCCP.h
+!
+  freq_ISCCP_omp = 10800.
+  call getin('freq_ISCCP', freq_ISCCP_omp)
+!
+!Config Key  = ecrit_ISCCP
+!Config Desc = Frequence d'ecriture des resultats du simulateur ISCCP en nombre de jours;
+!              par defaut 1., i.e. 1 jour
+!Config Def  = 1.
+!Config Help = Used in ini_histISCCP.h
+!
+!
+  ecrit_ISCCP_omp = 1.
+  call getin('ecrit_ISCCP', ecrit_ISCCP_omp)
+
+!Config Key  = freq_COSP
+!Config Desc = Frequence d'appel du simulateur COSP en secondes;
+!              par defaut 10800, i.e. 3 heures
+!Config Def  = 10800.
+!Config Help = Used in ini_histdayCOSP.h
+!
+  freq_COSP_omp = 10800.
+  call getin('freq_COSP', freq_COSP_omp)
+
+!
+!Config Key  = ip_ebil_phy
+!Config Desc = Niveau de sortie pour les diags bilan d'energie 
+!Config Def  = 0
+!Config Help = 
+!               
+  ip_ebil_phy_omp = 0
+  call getin('ip_ebil_phy', ip_ebil_phy_omp)
+!
+!Config Key  = seuil_inversion
+!Config Desc = Seuil ur dTh pour le choix entre les schemas de CL
+!Config Def  = -0.1
+!Config Help = 
+!               
+  seuil_inversion_omp = -0.1
+  call getin('seuil_inversion', seuil_inversion_omp)
+
+!!
+!! Constante solaire & Parametres orbitaux & taux gaz effet de serre BEG
+!!
+!Config Key  = R_ecc
+!Config Desc = Excentricite
+!Config Def  = 0.016715
+!Config Help = 
+!               
+!valeur AMIP II
+  R_ecc_omp = 0.016715
+  call getin('R_ecc', R_ecc_omp)
+!!
+!Config Key  = R_peri
+!Config Desc = Equinoxe
+!Config Def  = 
+!Config Help = 
+!               
+!
+!valeur AMIP II
+  R_peri_omp = 102.7
+  call getin('R_peri', R_peri_omp)
+!!
+!Config Key  = R_incl
+!Config Desc = Inclinaison
+!Config Def  = 
+!Config Help = 
+!               
+!
+!valeur AMIP II
+  R_incl_omp = 23.441
+  call getin('R_incl', R_incl_omp)
+!!
+!Config Key  = solaire
+!Config Desc = Constante solaire en W/m2
+!Config Def  = 1365.
+!Config Help = 
+!               
+!
+!valeur AMIP II
+  solaire_omp = 1365.
+  call getin('solaire', solaire_omp)
+!!
+!Config Key  = co2_ppm
+!Config Desc = concentration du gaz carbonique en ppmv
+!Config Def  = 348.
+!Config Help = 
+!               
+!
+!valeur AMIP II
+  co2_ppm_omp = 348.
+  call getin('co2_ppm', co2_ppm_omp)
+!!
+!Config Key  = RCO2
+!Config Desc = Concentration du CO2
+!Config Def  = co2_ppm * 1.0e-06  * 44.011/28.97
+!Config Def  = 348. * 1.0e-06  * 44.011/28.97
+!Config Help = 
+!               
+! RCO2 = 5.286789092164308E-04
+!ancienne valeur
+  RCO2_omp = co2_ppm_omp * 1.0e-06  * 44.011/28.97 ! pour co2_ppm=348.
+
+!!  call getin('RCO2', RCO2)
+!!
+!Config Key  = RCH4
+!Config Desc = Concentration du CH4
+!Config Def  = 1.65E-06* 16.043/28.97
+!Config Help = 
+!               
+!
+!valeur AMIP II
+!OK  RCH4 = 1.65E-06* 16.043/28.97
+! RCH4 = 9.137366240938903E-07
+!
+!ancienne valeur
+! RCH4 = 1.72E-06* 16.043/28.97
+!OK call getin('RCH4', RCH4)
+  zzz = 1650.
+  call getin('CH4_ppb', zzz)
+  CH4_ppb_omp = zzz
+  RCH4_omp = CH4_ppb_omp * 1.0E-09 * 16.043/28.97
+!!
+!Config Key  = RN2O
+!Config Desc = Concentration du N2O
+!Config Def  = 306.E-09* 44.013/28.97
+!Config Help = 
+!               
+!
+!valeur AMIP II
+!OK  RN2O = 306.E-09* 44.013/28.97
+! RN2O = 4.648939592682085E-07
+!
+!ancienne valeur
+! RN2O = 310.E-09* 44.013/28.97
+!OK  call getin('RN2O', RN2O)
+  zzz=306.
+  call getin('N2O_ppb', zzz)
+  N2O_ppb_omp = zzz
+  RN2O_omp = N2O_ppb_omp * 1.0E-09 * 44.013/28.97
+!!
+!Config Key  = RCFC11
+!Config Desc = Concentration du CFC11
+!Config Def  = 280.E-12* 137.3686/28.97
+!Config Help = 
+!               
+!
+!OK RCFC11 = 280.E-12* 137.3686/28.97
+  zzz = 280.
+  call getin('CFC11_ppt',zzz)
+  CFC11_ppt_omp = zzz
+  RCFC11_omp=CFC11_ppt_omp* 1.0E-12 * 137.3686/28.97
+! RCFC11 = 1.327690990680013E-09
+!OK call getin('RCFC11', RCFC11)
+!!
+!Config Key  = RCFC12
+!Config Desc = Concentration du CFC12
+!Config Def  = 484.E-12* 120.9140/28.97
+!Config Help = 
+!               
+!
+!OK RCFC12 = 484.E-12* 120.9140/28.97
+  zzz = 484.
+  call getin('CFC12_ppt',zzz)
+  CFC12_ppt_omp = zzz
+  RCFC12_omp = CFC12_ppt_omp * 1.0E-12 * 120.9140/28.97
+! RCFC12 = 2.020102726958923E-09
+!OK call getin('RCFC12', RCFC12)
+
+!ajout CFMIP begin
+!!
+!Config Key  = co2_ppm_per
+!Config Desc = concentration du co2_ppm_per
+!Config Def  = 348.
+!Config Help = 
+!               
+  co2_ppm_per_omp = co2_ppm_omp
+  call getin('co2_ppm_per', co2_ppm_per_omp)
+!!
+!Config Key  = RCO2_per
+!Config Desc = Concentration du CO2_per
+!Config Def  = co2_ppm_per * 1.0e-06  * 44.011/28.97
+!Config Def  = 348. * 1.0e-06  * 44.011/28.97
+!Config Help = 
+!               
+  RCO2_per_omp = co2_ppm_per_omp * 1.0e-06  * 44.011/28.97
+
+!Config Key  = RCH4_per
+!Config Desc = Concentration du CH4_per
+!Config Def  = 1.65E-06* 16.043/28.97
+!Config Help = 
+!               
+  zzz = CH4_ppb_omp
+  call getin('CH4_ppb_per', zzz)
+  CH4_ppb_per_omp = zzz
+  RCH4_per_omp = CH4_ppb_per_omp * 1.0E-09 * 16.043/28.97
+!!
+!Config Key  = RN2O_per
+!Config Desc = Concentration du N2O_per
+!Config Def  = 306.E-09* 44.013/28.97
+!Config Help = 
+!               
+  zzz = N2O_ppb_omp
+  call getin('N2O_ppb_per', zzz)
+  N2O_ppb_per_omp = zzz
+  RN2O_per_omp = N2O_ppb_per_omp * 1.0E-09 * 44.013/28.97
+!!
+!Config Key  = RCFC11_per
+!Config Desc = Concentration du CFC11_per
+!Config Def  = 280.E-12* 137.3686/28.97
+!Config Help = 
+!               
+  zzz = CFC11_ppt_omp
+  call getin('CFC11_ppt_per',zzz)
+  CFC11_ppt_per_omp = zzz
+  RCFC11_per_omp=CFC11_ppt_per_omp* 1.0E-12 * 137.3686/28.97
+!!
+!Config Key  = RCFC12_per
+!Config Desc = Concentration du CFC12_per
+!Config Def  = 484.E-12* 120.9140/28.97
+!Config Help = 
+!               
+  zzz = CFC12_ppt_omp
+  call getin('CFC12_ppt_per',zzz)
+  CFC12_ppt_per_omp = zzz
+  RCFC12_per_omp = CFC12_ppt_per_omp * 1.0E-12 * 120.9140/28.97
+!ajout CFMIP end
+
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+! FH 2008/05/09 On elimine toutes les clefs physiques dans la dynamique
+! Constantes precedemment dans dyn3d/conf_gcm
+
+!Config  Key  = cycle_diurne
+!Config  Desc = Cycle ddiurne
+!Config  Def  = y
+!Config  Help = Cette option permet d'eteidre le cycle diurne.
+!Config         Peut etre util pour accelerer le code !
+       cycle_diurne_omp = .TRUE.
+       CALL getin('cycle_diurne',cycle_diurne_omp)
+
+!Config  Key  = soil_model
+!Config  Desc = Modele de sol
+!Config  Def  = y
+!Config  Help = Choix du modele de sol (Thermique ?)
+!Config         Option qui pourait un string afin de pouvoir
+!Config         plus de choix ! Ou meme une liste d'options !
+       soil_model_omp = .TRUE.
+       CALL getin('soil_model',soil_model_omp)
+
+!Config  Key  = new_oliq
+!Config  Desc = Nouvelle eau liquide
+!Config  Def  = y
+!Config  Help = Permet de mettre en route la
+!Config         nouvelle parametrisation de l'eau liquide !
+       new_oliq_omp = .TRUE.
+       CALL getin('new_oliq',new_oliq_omp)
+
+!Config  Key  = ok_orodr
+!Config  Desc = Orodr ???
+!Config  Def  = y
+!Config  Help = Y en a pas comprendre !
+!Config         
+       ok_orodr_omp = .TRUE.
+       CALL getin('ok_orodr',ok_orodr_omp)
+
+!Config  Key  =  ok_orolf
+!Config  Desc = Orolf ??
+!Config  Def  = y
+!Config  Help = Connais pas !
+       ok_orolf_omp = .TRUE.
+       CALL getin('ok_orolf', ok_orolf_omp)
+
+!Config  Key  = ok_limitvrai
+!Config  Desc = Force la lecture de la bonne annee
+!Config  Def  = n
+!Config  Help = On peut forcer le modele a lire le
+!Config         fichier SST de la bonne annee. C'est une tres bonne
+!Config         idee, pourquoi ne pas mettre toujours a y ???
+       ok_limitvrai_omp = .FALSE.
+       CALL getin('ok_limitvrai',ok_limitvrai_omp)
+
+!Config  Key  = nbapp_rad
+!Config  Desc = Frequence d'appel au rayonnement
+!Config  Def  = 12
+!Config  Help = Nombre  d'appels des routines de rayonnements
+!Config         par jour.
+       nbapp_rad_omp = 12
+       CALL getin('nbapp_rad',nbapp_rad_omp)
+
+!Config  Key  = iflag_con
+!Config  Desc = Flag de convection
+!Config  Def  = 2
+!Config  Help = Flag  pour la convection les options suivantes existent :
+!Config         1 pour LMD,
+!Config         2 pour Tiedtke,
+!Config         3 pour CCM(NCAR)  
+       iflag_con_omp = 2
+       CALL getin('iflag_con',iflag_con_omp)
+
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!!
+!! Constante solaire & Parametres orbitaux & taux gaz effet de serre END
+!!
+!! KE
+!
+
+!Config key  = cvl_corr
+!Config Desc = Facteur multiplication des precip convectives dans KE
+!Config Def  = 1.00
+!Config Help = 1.02 pour un moderne ou un pre-ind. A ajuster pour un glaciaire
+  cvl_corr_omp = 1.00
+  CALL getin('cvl_corr', cvl_corr_omp)
+
+
+!Config Key  = epmax
+!Config Desc = Efficacite precip
+!Config Def  = 0.993
+!Config Help = 
+!
+  epmax_omp = .993
+  call getin('epmax', epmax_omp)
+!
+!Config Key  = ok_adj_ema
+!Config Desc =  
+!Config Def  = false
+!Config Help = 
+!
+  ok_adj_ema_omp = .false.
+  call getin('ok_adj_ema',ok_adj_ema_omp)
+!
+!Config Key  = iflag_clw
+!Config Desc =  
+!Config Def  = 0
+!Config Help = 
+!
+  iflag_clw_omp = 0
+  call getin('iflag_clw',iflag_clw_omp)
+!
+!Config Key  = cld_lc_lsc 
+!Config Desc =  
+!Config Def  = 2.6e-4
+!Config Help = 
+!
+  cld_lc_lsc_omp = 2.6e-4
+  call getin('cld_lc_lsc',cld_lc_lsc_omp)
+!
+!Config Key  = cld_lc_con
+!Config Desc =  
+!Config Def  = 2.6e-4
+!Config Help = 
+!
+  cld_lc_con_omp = 2.6e-4
+  call getin('cld_lc_con',cld_lc_con_omp)
+!
+!Config Key  = cld_tau_lsc
+!Config Desc =  
+!Config Def  = 3600.
+!Config Help = 
+!
+  cld_tau_lsc_omp = 3600.
+  call getin('cld_tau_lsc',cld_tau_lsc_omp)
+!
+!Config Key  = cld_tau_con
+!Config Desc =  
+!Config Def  = 3600.
+!Config Help = 
+!
+  cld_tau_con_omp = 3600.
+  call getin('cld_tau_con',cld_tau_con_omp)
+!
+!Config Key  = ffallv_lsc
+!Config Desc =  
+!Config Def  = 1.
+!Config Help = 
+!
+  ffallv_lsc_omp = 1.
+  call getin('ffallv_lsc',ffallv_lsc_omp)
+!
+!Config Key  = ffallv_con
+!Config Desc =  
+!Config Def  = 1.
+!Config Help = 
+!
+  ffallv_con_omp = 1.
+  call getin('ffallv_con',ffallv_con_omp)
+!
+!Config Key  = coef_eva
+!Config Desc =  
+!Config Def  = 2.e-5
+!Config Help = 
+!
+  coef_eva_omp = 2.e-5
+  call getin('coef_eva',coef_eva_omp)
+!
+!Config Key  = reevap_ice
+!Config Desc =  
+!Config Def  = .false.
+!Config Help = 
+!
+  reevap_ice_omp = .false.
+  call getin('reevap_ice',reevap_ice_omp)
+
+!Config Key  = iflag_ratqs
+!Config Desc =
+!Config Def  = 1
+!Config Help =
+!
+  iflag_ratqs_omp = 1
+  call getin('iflag_ratqs',iflag_ratqs_omp)
+
+!
+!Config Key  = iflag_radia 
+!Config Desc =  
+!Config Def  = 1
+!Config Help = 
+!
+  iflag_radia_omp = 1
+  call getin('iflag_radia',iflag_radia_omp)
+
+!
+!Config Key  = iflag_rrtm 
+!Config Desc =  
+!Config Def  = 0
+!Config Help = 
+!
+  iflag_rrtm_omp = 0
+  call getin('iflag_rrtm',iflag_rrtm_omp)
+
+!
+!Config Key  = iflag_cldcon 
+!Config Desc =  
+!Config Def  = 1
+!Config Help = 
+!
+  iflag_cldcon_omp = 1
+  call getin('iflag_cldcon',iflag_cldcon_omp)
+
+!
+!Config Key  = iflag_pdf 
+!Config Desc =  
+!Config Def  = 0
+!Config Help = 
+!
+  iflag_pdf_omp = 0
+  call getin('iflag_pdf',iflag_pdf_omp)
+!
+!Config Key  = fact_cldcon
+!Config Desc =  
+!Config Def  = 0.375
+!Config Help = 
+!
+  fact_cldcon_omp = 0.375
+  call getin('fact_cldcon',fact_cldcon_omp)
+
+!
+!Config Key  = facttemps
+!Config Desc =  
+!Config Def  = 1.e-4
+!Config Help = 
+!
+  facttemps_omp = 1.e-4
+  call getin('facttemps',facttemps_omp)
+
+!
+!Config Key  = ok_newmicro
+!Config Desc =  
+!Config Def  = .true.
+!Config Help = 
+!
+  ok_newmicro_omp = .true.
+  call getin('ok_newmicro',ok_newmicro_omp)
+!
+!Config Key  = ratqsbas
+!Config Desc =  
+!Config Def  = 0.01
+!Config Help = 
+!
+  ratqsbas_omp = 0.01
+  call getin('ratqsbas',ratqsbas_omp)
+!
+!Config Key  = ratqshaut
+!Config Desc =  
+!Config Def  = 0.3
+!Config Help = 
+!
+  ratqshaut_omp = 0.3
+  call getin('ratqshaut',ratqshaut_omp)
+
+!Config Key  = tau_ratqs
+!Config Desc =  
+!Config Def  = 1800.
+!Config Help = 
+!
+  tau_ratqs_omp = 1800.
+  call getin('tau_ratqs',tau_ratqs_omp)
+
+!
+!-----------------------------------------------------------------------
+! Longitude solaire pour le calcul de l'ensoleillement en degre
+! si on veut imposer la saison. Sinon, solarlong0=-999.999
+!Config Key  = solarlong0
+!Config Desc =  
+!Config Def  = -999.999 
+!Config Help = 
+!
+  solarlong0_omp = -999.999
+  call getin('solarlong0',solarlong0_omp)
+!
+!-----------------------------------------------------------------------
+!  Valeur imposee de l'humidite du sol pour le modele bucket.
+!Config Key  = qsol0
+!Config Desc =  
+!Config Def  = -1.
+!Config Help = 
+!
+  qsol0_omp = -1.
+  call getin('qsol0',qsol0_omp)
+!
+!-----------------------------------------------------------------------
+!
+!Config Key  = inertie_ice
+!Config Desc =  
+!Config Def  = 2000.
+!Config Help = 
+!
+  inertie_ice_omp = 2000.
+  call getin('inertie_ice',inertie_ice_omp)
+!
+!Config Key  = inertie_sno
+!Config Desc =  
+!Config Def  = 2000.
+!Config Help = 
+!
+  inertie_sno_omp = 2000.
+  call getin('inertie_sno',inertie_sno_omp)
+!
+!Config Key  = inertie_sol
+!Config Desc =  
+!Config Def  = 2000.
+!Config Help = 
+!
+  inertie_sol_omp = 2000.
+  call getin('inertie_sol',inertie_sol_omp)
+
+!
+!Config Key  = rad_froid
+!Config Desc =  
+!Config Def  = 35.0
+!Config Help = 
+!
+  rad_froid_omp = 35.0
+  call getin('rad_froid',rad_froid_omp)
+
+!
+!Config Key  = rad_chau1
+!Config Desc =  
+!Config Def  = 13.0
+!Config Help = 
+!
+  rad_chau1_omp = 13.0
+  call getin('rad_chau1',rad_chau1_omp)
+
+!
+!Config Key  = rad_chau2
+!Config Desc =  
+!Config Def  = 9.0
+!Config Help = 
+!
+  rad_chau2_omp = 9.0
+  call getin('rad_chau2',rad_chau2_omp)
+
+!
+!Config Key  = t_glace_min
+!Config Desc =  
+!Config Def  = 258.
+!Config Help = 
+!
+  t_glace_min_omp = 258.
+  call getin('t_glace_min',t_glace_min_omp)
+
+!
+!Config Key  = t_glace_max
+!Config Desc =  
+!Config Def  = 273.13
+!Config Help = 
+!
+  t_glace_max_omp = 273.13
+  call getin('t_glace_max',t_glace_max_omp)
+
+!Config Key  = rei_min
+!Config Desc =  
+!Config Def  = 3.5
+!Config Help = 
+!
+  rei_min_omp = 3.5
+  call getin('rei_min',rei_min_omp)
+
+!
+!Config Key  = rei_max
+!Config Desc =  
+!Config Def  = 61.29
+!Config Help = 
+!
+  rei_max_omp = 61.29
+  call getin('rei_max',rei_max_omp)
+
+!
+!Config Key  = top_height
+!Config Desc =
+!Config Def  = 3
+!Config Help =
+!
+  top_height_omp = 3
+  call getin('top_height',top_height_omp)
+
+!
+!Config Key  = overlap
+!Config Desc =
+!Config Def  = 3
+!Config Help =
+!
+  overlap_omp = 3
+  call getin('overlap',overlap_omp)
+
+
+!
+!
+!Config Key  = cdmmax
+!Config Desc =
+!Config Def  = 1.3E-3
+!Config Help =
+!
+  cdmmax_omp = 1.3E-3
+  call getin('cdmmax',cdmmax_omp)
+
+!
+!Config Key  = cdhmax
+!Config Desc =
+!Config Def  = 1.1E-3
+!Config Help =
+!
+  cdhmax_omp = 1.1E-3
+  call getin('cdhmax',cdhmax_omp)
+
+!261103
+!
+!Config Key  = ksta
+!Config Desc =
+!Config Def  = 1.0e-10
+!Config Help =
+!
+  ksta_omp = 1.0e-10
+  call getin('ksta',ksta_omp)
+
+!
+!Config Key  = ksta_ter
+!Config Desc =
+!Config Def  = 1.0e-10
+!Config Help =
+!
+  ksta_ter_omp = 1.0e-10
+  call getin('ksta_ter',ksta_ter_omp)
+
+!
+!Config Key  = ok_kzmin
+!Config Desc =
+!Config Def  = .true.
+!Config Help =
+!
+  ok_kzmin_omp = .true.
+  call getin('ok_kzmin',ok_kzmin_omp)
+
+!
+!Config Key  = fmagic
+!Config Desc = additionnal multiplicator factor used for albedo
+!Config Def  = 1.
+!Config Help = additionnal multiplicator factor used in albedo.F
+!
+  fmagic_omp = 1.
+  call getin('fmagic',fmagic_omp)
+
+!
+!Config Key  = pmagic
+!Config Desc = additional factor used for albedo
+!Config Def  = 0.
+!Config Help = additional factor used in albedo.F
+!
+  pmagic_omp = 0.
+  call getin('pmagic',pmagic_omp)
+
+
+!Config Key = ok_lic_melt
+!Config Desc = Prise en compte de la fonte de la calotte dans le bilan d'eau
+!Config Def  = .false.
+!Config Help = mettre a .false. pour assurer la conservation en eau
+  ok_lic_melt_omp = .false.
+  call getin('ok_lic_melt', ok_lic_melt_omp)
+
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+! PARAMETER FOR THE PLANETARY BOUNDARY LAYER
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+!Config Key  = iflag_pbl
+!Config Desc =
+!Config Def  = 1
+!Config Help =
+!
+  iflag_pbl_omp = 1
+  call getin('iflag_pbl',iflag_pbl_omp)
+!
+!Config Key  = iflag_thermals
+!Config Desc =
+!Config Def  = 0
+!Config Help =
+!
+  iflag_thermals_omp = 0
+  call getin('iflag_thermals',iflag_thermals_omp)
+!
+!
+!Config Key  = iflag_thermals_ed
+!Config Desc =
+!Config Def  = 0
+!Config Help =
+!
+  iflag_thermals_ed_omp = 0
+  call getin('iflag_thermals_ed',iflag_thermals_ed_omp)
+!
+!
+!Config Key  = iflag_thermals_optflux
+!Config Desc =
+!Config Def  = 0
+!Config Help =
+!
+  iflag_thermals_optflux_omp = 0
+  call getin('iflag_thermals_optflux',iflag_thermals_optflux_omp)
+!
+!
+!Config Key  = nsplit_thermals
+!Config Desc =
+!Config Def  = 1
+!Config Help =
+!
+  nsplit_thermals_omp = 1
+  call getin('nsplit_thermals',nsplit_thermals_omp)
+
+!Config Key  = alp_bl_k
+!Config Desc =
+!Config Def  = 0.
+!Config Help =
+!
+  alp_bl_k_omp = 1.
+  call getin('alp_bl_k',alp_bl_k_omp)
+
+!!! nrlmd le 10/04/2012
+
+!Config Key  = iflag_trig_bl
+!Config Desc =  
+!Config Def  = 0
+!Config Help = 
+!
+  iflag_trig_bl_omp = 0
+  call getin('iflag_trig_bl',iflag_trig_bl_omp)
+
+!Config Key  = s_trig_bl
+!Config Desc =  
+!Config Def  = 0
+!Config Help = 
+!
+  s_trig_omp = 2e7
+  call getin('s_trig',s_trig_omp)
+
+!Config Key  = tau_trig_shallow
+!Config Desc =  
+!Config Def  = 0
+!Config Help = 
+!
+  tau_trig_shallow_omp = 600
+  call getin('tau_trig_shallow',tau_trig_shallow_omp)
+
+!Config Key  = tau_trig_deep
+!Config Desc =  
+!Config Def  = 0
+!Config Help = 
+!
+  tau_trig_deep_omp = 1800
+  call getin('tau_trig_deep',tau_trig_deep_omp)
+
+!Config Key  = iflag_clos_bl
+!Config Desc =  
+!Config Def  = 0
+!Config Help = 
+!
+  iflag_clos_bl_omp = 0
+  call getin('iflag_clos_bl',iflag_clos_bl_omp)
+
+!!! fin nrlmd le 10/04/2012
+
+!
+!Config Key  = tau_thermals
+!Config Desc =
+!Config Def  = 0.
+!Config Help =
+!
+  tau_thermals_omp = 0.
+  call getin('tau_thermals',tau_thermals_omp)
+
+!
+!Config Key  = iflag_coupl
+!Config Desc =
+!Config Def  = 0
+!Config Help =
+!
+  iflag_coupl_omp = 0
+  call getin('iflag_coupl',iflag_coupl_omp)
+
+!
+!Config Key  = iflag_clos
+!Config Desc =  
+!Config Def  = 0
+!Config Help = 
+!
+  iflag_clos_omp = 1
+  call getin('iflag_clos',iflag_clos_omp)
+!
+!Config Key  = iflag_cvl_sigd
+!Config Desc =  
+!Config Def  = 0
+!Config Help = 
+!
+  iflag_cvl_sigd_omp = 0
+  call getin('iflag_cvl_sigd',iflag_cvl_sigd_omp)
+
+!Config Key  = iflag_wake
+!Config Desc =  
+!Config Def  = 0
+!Config Help = 
+!
+  iflag_wake_omp = 0
+  call getin('iflag_wake',iflag_wake_omp)
+
+!Config Key  = alp_offset
+!Config Desc =  
+!Config Def  = 0
+!Config Help = 
+!
+  alp_offset_omp = 0.
+  call getin('alp_offset',alp_offset_omp)
+
+!
+!Config Key  = lev_histhf
+!Config Desc =
+!Config Def  = 1
+!Config Help =
+!
+  lev_histhf_omp = 1
+  call getin('lev_histhf',lev_histhf_omp)
+
+!
+!Config Key  = lev_histday
+!Config Desc =
+!Config Def  = 1
+!Config Help =
+!
+  lev_histday_omp = 1
+  call getin('lev_histday',lev_histday_omp)
+
+!
+!Config Key  = lev_histmth
+!Config Desc =
+!Config Def  = 2
+!Config Help =
+!
+  lev_histmth_omp = 2
+  call getin('lev_histmth',lev_histmth_omp)
+!
+!Config Key  = lev_histins
+!Config Desc =
+!Config Def  = 1
+!Config Help =
+!
+  lev_histins_omp = 1
+  call getin('lev_histins',lev_histins_omp)
+  !
+!Config Key  = lev_histLES
+!Config Desc =
+!Config Def  = 1
+!Config Help =
+!
+  lev_histLES_omp = 1
+  call getin('lev_histLES',lev_histLES_omp)
+!
+!Config Key  = lev_histdayNMC
+!Config Desc =
+!Config Def  = 8
+!Config Help =
+!
+  lev_histdayNMC_omp = 8
+  call getin('lev_histdayNMC',lev_histdayNMC_omp)
+!
+!histNMC BEG
+!Config Key  = ok_histNMC
+!Config Desc = ok_histNMC(1) = frequence de sortie fichiers histmthNMC
+!Config Desc = ok_histNMC(2) = frequence de sortie fichiers histdayNMC
+!Config Desc = ok_histNMC(3) = frequence de sortie fichiers histhfNMC
+!Config Def  = n, n, n
+!Config Help =
+!
+  ok_histNMC_omp(1) = .false.
+  ok_histNMC_omp(2) = .false.
+  ok_histNMC_omp(3) = .false.
+  call getin('ok_histNMC',ok_histNMC_omp)
+!
+!Config Key  = freq_outNMC
+!Config Desc = freq_outNMC(1) = frequence de sortie fichiers histmthNMC
+!Config Desc = freq_outNMC(2) = frequence de sortie fichiers histdayNMC
+!Config Desc = freq_outNMC(3) = frequence de sortie fichiers histhfNMC
+!Config Def  = 2592000., 86400., 21600.
+!Config Help =
+!
+! freq_outNMC_omp(1) = 2592000.
+  freq_outNMC_omp(1) = mth_len*86400.
+  freq_outNMC_omp(2) = 86400.
+  freq_outNMC_omp(3) = 21600.
+  call getin('freq_outNMC',freq_outNMC_omp)
+!
+!Config Key  = freq_calNMC
+!Config Desc = freq_calNMC(1) = frequence de calcul fichiers histmthNMC
+!Config Desc = freq_calNMC(2) = frequence de calcul fichiers histdayNMC
+!Config Desc = freq_calNMC(3) = frequence de calcul fichiers histhfNMC
+!Config Def  = pasphys
+!Config Help =
+!
+  freq_calNMC_omp(1) = pasphys
+  freq_calNMC_omp(2) = pasphys
+  freq_calNMC_omp(3) = pasphys
+  call getin('freq_calNMC',freq_calNMC_omp)
+!
+!Config Key  = type_run
+!Config Desc =
+!Config Def  = 'AMIP'/'CFMIP'  ou 'CLIM'/'ENSP'
+!Config Help =
+!
+  type_run_omp = 'AMIP'
+  call getin('type_run',type_run_omp)
+
+!
+!Config Key  = ok_isccp
+!Config Desc =
+!Config Def  = .true.
+!Config Help =
+!
+! ok_isccp = .true.
+  ok_isccp_omp = .false.
+  call getin('ok_isccp',ok_isccp_omp)
+
+!
+!Config Key  = ok_cosp
+!Config Desc =
+!Config Def  = .false.
+!Config Help =
+!
+  ok_cosp_omp = .false.
+  call getin('ok_cosp',ok_cosp_omp)
+
+!
+!Config Key  = ok_mensuelCOSP
+!Config Desc =
+!Config Def  = .true.
+!Config Help =
+!
+  ok_mensuelCOSP_omp = .true.
+  call getin('ok_mensuelCOSP',ok_mensuelCOSP_omp)
+
+!
+!Config Key  = ok_journeCOSP
+!Config Desc =
+!Config Def  = .true.
+!Config Help = 
+!
+  ok_journeCOSP_omp = .true.
+  call getin('ok_journeCOSP',ok_journeCOSP_omp)
+
+!
+!Config Key  = ok_hfCOSP
+!Config Desc =
+!Config Def  = .false.
+!Config Help =
+!
+  ok_hfCOSP_omp = .false.
+  call getin('ok_hfCOSP',ok_hfCOSP_omp)
+
+!
+! coordonnees (lonmin_ins, lonmax_ins, latmin_ins, latmax_ins) pour la zone 
+! avec sorties instantannees tous les pas de temps de la physique => "histbilKP_ins.nc"
+!
+!Config Key  = lonmin_ins
+!Config Desc = 100.  
+!Config Def  = longitude minimale sorties "bilKP_ins"
+!Config Help = 
+!
+   lonmin_ins_omp = 100.
+   call getin('lonmin_ins',lonmin_ins_omp)
+!
+!Config Key  = lonmax_ins
+!Config Desc = 130. 
+!Config Def  = longitude maximale sorties "bilKP_ins"
+!Config Help =
+!
+   lonmax_ins_omp = 130.
+   call getin('lonmax_ins',lonmax_ins_omp)
+!
+!Config Key  = latmin_ins
+!Config Desc = -20.  
+!Config Def  = latitude minimale sorties "bilKP_ins"
+!Config Help = 
+!
+   latmin_ins_omp = -20.
+   call getin('latmin_ins',latmin_ins_omp)
+!
+!Config Key  = latmax_ins
+!Config Desc = 20. 
+!Config Def  = latitude maximale sorties "bilKP_ins"
+!Config Help =
+!
+   latmax_ins_omp = 20.
+   call getin('latmax_ins',latmax_ins_omp)
+!
+!Config Key  = ecrit_hf
+!Config Desc =
+!Config Def  = 1./8. !toutes les 3h
+!Config Help =
+!
+  ecrit_hf_omp = 1./8.
+  call getin('ecrit_hf',ecrit_hf_omp)
+!
+!Config Key  = ecrit_ins
+!Config Desc =
+!Config Def  = 1./48. ! toutes les 1/2 h
+!Config Help =
+!
+  ecrit_ins_omp = 1./48.
+  call getin('ecrit_ins',ecrit_ins_omp)
+!
+!Config Key  = ecrit_day
+!Config Desc =
+!Config Def  = 1.0 !tous les jours
+!Config Help = nombre de jours pour ecriture fichier histday.nc
+!
+  ecrit_day_omp = 1.0
+  call getin('ecrit_day',ecrit_day_omp)
+!
+!Config Key  = ecrit_mth
+!Config Desc =
+!Config Def  = 30. !tous les 30jours (1 fois par mois)
+!Config Help =
+!
+  ecrit_mth_omp = 30.
+  call getin('ecrit_mth',ecrit_mth_omp)
+!
+!Config Key  = ecrit_tra
+!Config Desc =
+!Config Def  = 30. !tous les 30jours (1 fois par mois)
+!Config Help =
+!
+  ecrit_tra_omp = 0.
+  call getin('ecrit_tra',ecrit_tra_omp)
+!
+!Config Key  = ecrit_reg
+!Config Desc =
+!Config Def  = 0.25  !4 fois par jour
+!Config Help =
+!
+  ecrit_reg_omp = 0.25   !4 fois par jour
+  call getin('ecrit_reg',ecrit_reg_omp)
+!
+!
+!
+! PARAMETRES CDRAG
+!
+!Config Key  = f_cdrag_ter
+!Config Desc =
+!Config Def  = 0.8
+!Config Help =
+!
+  f_cdrag_ter_omp = 0.8
+  call getin('f_cdrag_ter',f_cdrag_ter_omp)
+!
+!Config Key  = f_cdrag_oce
+!Config Desc =
+!Config Def  = 0.8
+!Config Help =
+!
+  f_cdrag_oce_omp = 0.8
+  call getin('f_cdrag_oce',f_cdrag_oce_omp)
+!
+! RUGORO
+!Config Key  = f_rugoro
+!Config Desc =
+!Config Def  = 0.
+!Config Help =
+!
+  f_rugoro_omp = 0.
+  call getin('f_rugoro',f_rugoro_omp)
+
+! PARAMETERS FOR CONVECTIVE INHIBITION BY TROPOS. DRYNESS
+!
+!Config Key  = supcrit1
+!Config Desc =
+!Config Def  = .540
+!Config Help =
+!
+  supcrit1_omp = .540
+  call getin('supcrit1',supcrit1_omp)
+
+!
+!Config Key  = supcrit2
+!Config Desc =
+!Config Def  = .600
+!Config Help =
+!
+  supcrit2_omp = .600
+  call getin('supcrit2',supcrit2_omp)
+
+!
+! PARAMETERS FOR THE MIXING DISTRIBUTION
+! iflag_mix: 0=OLD, 
+!            1=NEW (JYG),            
+!            2=NEW + conv. depth inhib. by tropos. dryness
+! '2' is NOT operationnal and should not be used.
+!
+!Config Key  = iflag_mix
+!Config Desc =
+!Config Def  = 1
+!Config Help =
+!
+  iflag_mix_omp = 1
+  call getin('iflag_mix',iflag_mix_omp)
+
+!
+!Config Key  = scut
+!Config Desc =
+!Config Def  = 0.95
+!Config Help =
+!
+  scut_omp = 0.95
+  call getin('scut',scut_omp)
+
+!
+!Config Key  = qqa1
+!Config Desc =
+!Config Def  = 1.0
+!Config Help =
+!
+  qqa1_omp = 1.0
+  call getin('qqa1',qqa1_omp)
+
+!
+!Config Key  = qqa2
+!Config Desc =
+!Config Def  = 0.0
+!Config Help =
+!
+  qqa2_omp = 0.0
+  call getin('qqa2',qqa2_omp)
+
+!
+!Config Key  = gammas
+!Config Desc =
+!Config Def  = 0.05
+!Config Help =
+!
+  gammas_omp = 0.05
+  call getin('gammas',gammas_omp)
+
+!
+!Config Key  = Fmax
+!Config Desc =
+!Config Def  = 0.65
+!Config Help =
+!
+  Fmax_omp = 0.65
+  call getin('Fmax',Fmax_omp)
+
+!
+!Config Key  = alphas  
+!Config Desc =
+!Config Def  = -5.
+!Config Help =
+!
+  alphas_omp = -5.
+  call getin('alphas',alphas_omp)
+
+!Config key = ok_strato
+!Config  Desc = activation de la version strato
+!Config  Def  = .FALSE.
+!Config  Help = active la version stratosphérique de LMDZ de F. Lott
+
+  ok_strato_omp=.FALSE.
+  CALL getin('ok_strato',ok_strato_omp)
+      
+!Config  key = ok_hines
+!Config  Desc = activation de la parametrisation de hines
+!Config  Def  = .FALSE.
+!Config  Help = Clefs controlant la parametrization de Hines
+!               Et la sponge layer (Runs Stratospheriques)
+
+  ok_hines_omp=.FALSE.
+  CALL getin('ok_hines',ok_hines_omp)
+
+!Config Key  = OK_LES                                               
+!Config Desc = Pour des sorties LES                                 
+!Config Def  = .false.                                              
+!Config Help = Pour creer le fichier histLES contenant les sorties  
+!              LES                                                  
+!                                                                   
+  ok_LES_omp = .false.                                              
+  call getin('OK_LES', ok_LES_omp)                                  
+
+!Config Key  = callstats                                               
+!Config Desc = Pour des sorties callstats                                 
+!Config Def  = .false.                                              
+!Config Help = Pour creer le fichier stats contenant les sorties  
+!              stats                                                  
+!                                                                   
+  callstats_omp = .false.                                              
+  call getin('callstats', callstats_omp)                                  
+!
+!Config Key  = ecrit_LES
+!Config Desc = Frequence d'ecriture des resultats du LES en nombre de jours;
+!              par defaut 1., i.e. 1 jour
+!Config Def  = 1./8.
+!Config Help = ... 
+!
+!
+  ecrit_LES_omp = 1./8.
+  call getin('ecrit_LES', ecrit_LES_omp)
+!
+  read_climoz = 0 ! default value
+  call getin('read_climoz', read_climoz)
+
+  carbon_cycle_tr_omp=.FALSE.
+  CALL getin('carbon_cycle_tr',carbon_cycle_tr_omp)
+
+  carbon_cycle_cpl_omp=.FALSE.
+  CALL getin('carbon_cycle_cpl',carbon_cycle_cpl_omp)
+
+!$OMP END MASTER
+!$OMP BARRIER
+
+    R_ecc = R_ecc_omp
+    R_peri = R_peri_omp
+    R_incl = R_incl_omp
+    solaire = solaire_omp
+    co2_ppm = co2_ppm_omp
+    RCO2 = RCO2_omp
+    CH4_ppb = CH4_ppb_omp
+    RCH4 = RCH4_omp
+    N2O_ppb = N2O_ppb_omp
+    RN2O = RN2O_omp
+    CFC11_ppt = CFC11_ppt_omp
+    RCFC11 = RCFC11_omp
+    CFC12_ppt = CFC12_ppt_omp
+    RCFC12 = RCFC12_omp
+    RCO2_act = RCO2
+    RCH4_act = RCH4
+    RN2O_act = RN2O
+    RCFC11_act = RCFC11
+    RCFC12_act = RCFC12
+    RCO2_per = RCO2_per_omp
+    RCH4_per = RCH4_per_omp
+    RN2O_per = RN2O_per_omp
+    RCFC11_per = RCFC11_per_omp
+    RCFC12_per = RCFC12_per_omp
+    
+    cycle_diurne = cycle_diurne_omp
+    soil_model = soil_model_omp
+    new_oliq = new_oliq_omp
+    ok_orodr = ok_orodr_omp
+    ok_orolf = ok_orolf_omp
+    ok_limitvrai = ok_limitvrai_omp
+    nbapp_rad = nbapp_rad_omp
+    iflag_con = iflag_con_omp
+
+    epmax = epmax_omp
+    ok_adj_ema = ok_adj_ema_omp
+    iflag_clw = iflag_clw_omp
+    cld_lc_lsc = cld_lc_lsc_omp
+    cld_lc_con = cld_lc_con_omp
+    cld_tau_lsc = cld_tau_lsc_omp
+    cld_tau_con = cld_tau_con_omp
+    ffallv_lsc = ffallv_lsc_omp
+    ffallv_con = ffallv_con_omp
+    coef_eva = coef_eva_omp
+    reevap_ice = reevap_ice_omp
+    iflag_pdf = iflag_pdf_omp
+    solarlong0 = solarlong0_omp
+    qsol0 = qsol0_omp
+    inertie_sol = inertie_sol_omp
+    inertie_ice = inertie_ice_omp
+    inertie_sno = inertie_sno_omp
+    rad_froid = rad_froid_omp
+    rad_chau1 = rad_chau1_omp
+    rad_chau2 = rad_chau2_omp
+    t_glace_min = t_glace_min_omp
+    t_glace_max = t_glace_max_omp
+    rei_min = rei_min_omp
+    rei_max = rei_max_omp
+    top_height = top_height_omp
+    overlap = overlap_omp
+    cdmmax = cdmmax_omp
+    cdhmax = cdhmax_omp
+    ksta = ksta_omp
+    ksta_ter = ksta_ter_omp
+    ok_kzmin = ok_kzmin_omp
+    fmagic = fmagic_omp
+    pmagic = pmagic_omp
+    iflag_pbl = iflag_pbl_omp
+    lev_histhf = lev_histhf_omp
+    lev_histday = lev_histday_omp
+    lev_histmth = lev_histmth_omp
+    lev_histins = lev_histins_omp
+    lev_histLES = lev_histLES_omp
+    lev_histdayNMC = lev_histdayNMC_omp
+    ok_histNMC(:) = ok_histNMC_omp(:)
+    freq_outNMC(:) = freq_outNMC_omp(:)
+    freq_calNMC(:) = freq_calNMC_omp(:)
+
+    type_ocean = type_ocean_omp
+    version_ocean = version_ocean_omp
+    ok_veget = ok_veget_omp
+    ok_newmicro = ok_newmicro_omp
+    ok_journe = ok_journe_omp
+    ok_hf = ok_hf_omp
+    ok_mensuel = ok_mensuel_omp
+    ok_instan = ok_instan_omp
+    freq_ISCCP = freq_ISCCP_omp
+    ecrit_ISCCP = ecrit_ISCCP_omp
+    freq_COSP = freq_COSP_omp
+    ok_ade = ok_ade_omp
+    ok_aie = ok_aie_omp
+    aerosol_couple = aerosol_couple_omp
+    flag_aerosol=flag_aerosol_omp
+    new_aod=new_aod_omp
+    aer_type = aer_type_omp
+    bl95_b0 = bl95_b0_omp
+    bl95_b1 = bl95_b1_omp
+    fact_cldcon = fact_cldcon_omp
+    facttemps = facttemps_omp
+    ratqsbas = ratqsbas_omp
+    ratqshaut = ratqshaut_omp
+    tau_ratqs = tau_ratqs_omp
+
+    iflag_radia = iflag_radia_omp
+    iflag_rrtm = iflag_rrtm_omp
+    iflag_cldcon = iflag_cldcon_omp
+    iflag_ratqs = iflag_ratqs_omp
+    ip_ebil_phy = ip_ebil_phy_omp
+    iflag_thermals = iflag_thermals_omp
+    iflag_thermals_ed = iflag_thermals_ed_omp
+    iflag_thermals_optflux = iflag_thermals_optflux_omp
+    nsplit_thermals = nsplit_thermals_omp
+    tau_thermals = tau_thermals_omp
+    alp_bl_k = alp_bl_k_omp
+!!! nrlmd le 10/04/2012
+    iflag_trig_bl = iflag_trig_bl_omp
+    s_trig = s_trig_omp
+    tau_trig_shallow = tau_trig_shallow_omp
+    tau_trig_deep = tau_trig_deep_omp
+    iflag_clos_bl = iflag_clos_bl_omp
+!!! fin nrlmd le 10/04/2012
+    iflag_coupl = iflag_coupl_omp
+    iflag_clos = iflag_clos_omp
+    iflag_wake = iflag_wake_omp
+    alp_offset = alp_offset_omp
+    iflag_cvl_sigd = iflag_cvl_sigd_omp
+    type_run = type_run_omp
+    ok_isccp = ok_isccp_omp
+    ok_cosp = ok_cosp_omp
+    ok_mensuelCOSP = ok_mensuelCOSP_omp
+    ok_journeCOSP = ok_journeCOSP_omp
+    ok_hfCOSP = ok_hfCOSP_omp
+    seuil_inversion=seuil_inversion_omp
+    lonmin_ins = lonmin_ins_omp
+    lonmax_ins = lonmax_ins_omp
+    latmin_ins = latmin_ins_omp
+    latmax_ins = latmax_ins_omp
+    ecrit_hf   = ecrit_hf_omp
+    ecrit_ins   = ecrit_ins_omp
+    ecrit_day = ecrit_day_omp
+    ecrit_mth = ecrit_mth_omp
+    ecrit_tra = ecrit_tra_omp
+    ecrit_reg = ecrit_reg_omp
+    cvl_corr = cvl_corr_omp
+    ok_lic_melt = ok_lic_melt_omp
+    f_cdrag_ter=f_cdrag_ter_omp
+    f_cdrag_oce=f_cdrag_oce_omp
+    f_rugoro=f_rugoro_omp
+    supcrit1 = supcrit1_omp
+    supcrit2 = supcrit2_omp
+    iflag_mix = iflag_mix_omp
+    scut = scut_omp
+    qqa1 = qqa1_omp
+    qqa2 = qqa2_omp
+    gammas = gammas_omp
+    Fmax = Fmax_omp
+    alphas = alphas_omp
+    ok_strato = ok_strato_omp
+    ok_hines = ok_hines_omp
+    ok_LES = ok_LES_omp
+    callstats = callstats_omp
+    ecrit_LES = ecrit_LES_omp
+    carbon_cycle_tr = carbon_cycle_tr_omp
+    carbon_cycle_cpl = carbon_cycle_cpl_omp
+
+! Test of coherence between type_ocean and version_ocean
+    IF (type_ocean=='couple' .AND. (version_ocean/='opa8' .AND. version_ocean/='nemo') ) THEN
+       WRITE(lunout,*)' ERROR version_ocean=',version_ocean,' not valid in coupled configuration'
+       CALL abort_gcm('conf_phys','version_ocean not valid',1)
+    END IF
+
+    IF (type_ocean=='slab' .AND. version_ocean=='xxxxxx') THEN
+       version_ocean='sicOBS'
+    ELSE IF (type_ocean=='slab' .AND. version_ocean/='sicOBS') THEN
+       WRITE(lunout,*)' ERROR version_ocean=',version_ocean,' not valid with slab ocean'
+       CALL abort_gcm('conf_phys','version_ocean not valid',1)
+    END IF
+
+! Test sur new_aod. Ce flag permet de retrouver les resultats de l'AR4
+! il n'est utilisable que lors du couplage avec le SO4 seul 
+    IF (ok_ade .OR. ok_aie) THEN 
+       IF ( flag_aerosol .EQ. 0 ) THEN
+          CALL abort_gcm('conf_phys','flag_aerosol=0 not compatible avec ok_ade ou ok_aie=.TRUE.',1)
+       END IF
+       IF ( .NOT. new_aod .AND.  flag_aerosol .NE. 1) THEN
+          CALL abort_gcm('conf_phys','new_aod=.FALSE. not compatible avec flag_aerosol=1',1)
+       END IF
+    END IF
+
+!$OMP MASTER
+
+  write(lunout,*)' ##############################################'
+  write(lunout,*)' Configuration des parametres de la physique: '
+  write(lunout,*)' Type ocean = ', type_ocean
+  write(lunout,*)' Version ocean = ', version_ocean
+  write(lunout,*)' Config veget = ', ok_veget
+  write(lunout,*)' Sortie journaliere = ', ok_journe
+  write(lunout,*)' Sortie haute frequence = ', ok_hf
+  write(lunout,*)' Sortie mensuelle = ', ok_mensuel
+  write(lunout,*)' Sortie instantanee = ', ok_instan
+  write(lunout,*)' Frequence appel simulateur ISCCP, freq_ISCCP =', freq_ISCCP
+  write(lunout,*)' Frequence appel simulateur ISCCP, ecrit_ISCCP =', ecrit_ISCCP
+  write(lunout,*)' Frequence appel simulateur COSP, freq_COSP =', freq_COSP
+  write(lunout,*)' Sortie bilan d''energie, ip_ebil_phy =', ip_ebil_phy
+  write(lunout,*)' Excentricite = ',R_ecc
+  write(lunout,*)' Equinoxe = ',R_peri
+  write(lunout,*)' Inclinaison =',R_incl
+  write(lunout,*)' Constante solaire =',solaire
+  write(lunout,*)' co2_ppm =',co2_ppm
+  write(lunout,*)' RCO2_act = ',RCO2_act
+  write(lunout,*)' CH4_ppb =',CH4_ppb,' RCH4_act = ',RCH4_act
+  write(lunout,*)' N2O_ppb =',N2O_ppb,' RN2O_act=  ',RN2O_act
+  write(lunout,*)' CFC11_ppt=',CFC11_ppt,' RCFC11_act=  ',RCFC11_act
+  write(lunout,*)' CFC12_ppt=',CFC12_ppt,' RCFC12_act=  ',RCFC12_act
+  write(lunout,*)' RCO2_per = ',RCO2_per,' RCH4_per = ', RCH4_per
+  write(lunout,*)' RN2O_per = ',RN2O_per,' RCFC11_per = ', RCFC11_per
+  write(lunout,*)' RCFC12_per = ',RCFC12_per
+  write(lunout,*)' cvl_corr=', cvl_corr
+  write(lunout,*)'ok_lic_melt=', ok_lic_melt
+  write(lunout,*)'cycle_diurne=',cycle_diurne
+  write(lunout,*)'soil_model=',soil_model
+  write(lunout,*)'new_oliq=',new_oliq
+  write(lunout,*)'ok_orodr=',ok_orodr
+  write(lunout,*)'ok_orolf=',ok_orolf
+  write(lunout,*)'ok_limitvrai=',ok_limitvrai
+  write(lunout,*)'nbapp_rad=',nbapp_rad
+  write(lunout,*)'iflag_con=',iflag_con
+  write(lunout,*)' epmax = ', epmax
+  write(lunout,*)' ok_adj_ema = ', ok_adj_ema
+  write(lunout,*)' iflag_clw = ', iflag_clw
+  write(lunout,*)' cld_lc_lsc = ', cld_lc_lsc
+  write(lunout,*)' cld_lc_con = ', cld_lc_con
+  write(lunout,*)' cld_tau_lsc = ', cld_tau_lsc
+  write(lunout,*)' cld_tau_con = ', cld_tau_con
+  write(lunout,*)' ffallv_lsc = ', ffallv_lsc
+  write(lunout,*)' ffallv_con = ', ffallv_con
+  write(lunout,*)' coef_eva = ', coef_eva
+  write(lunout,*)' reevap_ice = ', reevap_ice
+  write(lunout,*)' iflag_pdf = ', iflag_pdf
+  write(lunout,*)' iflag_cldcon = ', iflag_cldcon
+  write(lunout,*)' iflag_radia = ', iflag_radia
+  write(lunout,*)' iflag_rrtm = ', iflag_rrtm
+  write(lunout,*)' iflag_ratqs = ', iflag_ratqs
+  write(lunout,*)' seuil_inversion = ', seuil_inversion
+  write(lunout,*)' fact_cldcon = ', fact_cldcon
+  write(lunout,*)' facttemps = ', facttemps
+  write(lunout,*)' ok_newmicro = ',ok_newmicro 
+  write(lunout,*)' ratqsbas = ',ratqsbas 
+  write(lunout,*)' ratqshaut = ',ratqshaut 
+  write(lunout,*)' tau_ratqs = ',tau_ratqs 
+  write(lunout,*)' top_height = ',top_height 
+  write(lunout,*)' rad_froid = ',rad_froid
+  write(lunout,*)' rad_chau1 = ',rad_chau1
+  write(lunout,*)' rad_chau2 = ',rad_chau2
+  write(lunout,*)' t_glace_min = ',t_glace_min
+  write(lunout,*)' t_glace_max = ',t_glace_max
+  write(lunout,*)' rei_min = ',rei_min
+  write(lunout,*)' rei_max = ',rei_max
+  write(lunout,*)' overlap = ',overlap 
+  write(lunout,*)' cdmmax = ',cdmmax 
+  write(lunout,*)' cdhmax = ',cdhmax 
+  write(lunout,*)' ksta = ',ksta 
+  write(lunout,*)' ksta_ter = ',ksta_ter 
+  write(lunout,*)' ok_kzmin = ',ok_kzmin 
+  write(lunout,*)' fmagic = ',fmagic
+  write(lunout,*)' pmagic = ',pmagic
+  write(lunout,*)' ok_ade = ',ok_ade
+  write(lunout,*)' ok_aie = ',ok_aie
+  write(lunout,*)' aerosol_couple = ', aerosol_couple
+  write(lunout,*)' flag_aerosol = ', flag_aerosol
+  write(lunout,*)' new_aod = ', new_aod
+  write(lunout,*)' aer_type = ',aer_type
+  write(lunout,*)' bl95_b0 = ',bl95_b0
+  write(lunout,*)' bl95_b1 = ',bl95_b1
+  write(lunout,*)' lev_histhf = ',lev_histhf 
+  write(lunout,*)' lev_histday = ',lev_histday 
+  write(lunout,*)' lev_histmth = ',lev_histmth 
+  write(lunout,*)' lev_histins = ',lev_histins
+  write(lunout,*)' lev_histLES = ',lev_histLES
+  write(lunout,*)' lev_histdayNMC = ',lev_histdayNMC
+  write(lunout,*)' ok_histNMC = ',ok_histNMC
+  write(lunout,*)' freq_outNMC = ',freq_outNMC
+  write(lunout,*)' freq_calNMC = ',freq_calNMC
+  write(lunout,*)' iflag_pbl = ', iflag_pbl
+  write(lunout,*)' iflag_thermals = ', iflag_thermals
+  write(lunout,*)' iflag_thermals_ed = ', iflag_thermals_ed
+  write(lunout,*)' iflag_thermals_optflux = ', iflag_thermals_optflux
+  write(lunout,*)' iflag_clos = ', iflag_clos
+  write(lunout,*)' type_run = ',type_run 
+  write(lunout,*)' ok_isccp = ',ok_isccp 
+  write(lunout,*)' ok_cosp = ',ok_cosp
+  write(lunout,*)' ok_mensuelCOSP = ',ok_mensuelCOSP
+  write(lunout,*)' ok_journeCOSP = ',ok_journeCOSP
+  write(lunout,*)' ok_hfCOSP =',ok_hfCOSP
+  write(lunout,*)' solarlong0 = ', solarlong0
+  write(lunout,*)' qsol0 = ', qsol0
+  write(lunout,*)' inertie_sol = ', inertie_sol
+  write(lunout,*)' inertie_ice = ', inertie_ice
+  write(lunout,*)' inertie_sno = ', inertie_sno
+  write(lunout,*)' f_cdrag_ter = ',f_cdrag_ter
+  write(lunout,*)' f_cdrag_oce = ',f_cdrag_oce
+  write(lunout,*)' f_rugoro = ',f_rugoro
+  write(lunout,*)' supcrit1 = ', supcrit1
+  write(lunout,*)' supcrit2 = ', supcrit2
+  write(lunout,*)' iflag_mix = ', iflag_mix
+  write(lunout,*)' scut = ', scut
+  write(lunout,*)' qqa1 = ', qqa1
+  write(lunout,*)' qqa2 = ', qqa2
+  write(lunout,*)' gammas = ', gammas
+  write(lunout,*)' Fmax = ', Fmax
+  write(lunout,*)' alphas = ', alphas
+  write(lunout,*)' iflag_wake = ', iflag_wake
+  write(lunout,*)' alp_offset = ', alp_offset
+!!! nrlmd le 10/04/2012
+  write(lunout,*)' iflag_trig_bl = ', iflag_trig_bl
+  write(lunout,*)' s_trig = ', s_trig
+  write(lunout,*)' tau_trig_shallow = ', tau_trig_shallow
+  write(lunout,*)' tau_trig_deep = ', tau_trig_deep
+  write(lunout,*)' iflag_clos_bl = ', iflag_clos_bl
+!!! fin nrlmd le 10/04/2012
+
+  write(lunout,*)' lonmin lonmax latmin latmax bilKP_ins =',&
+   lonmin_ins, lonmax_ins, latmin_ins, latmax_ins
+  write(lunout,*)' ecrit_ hf, ins, day, mth, reg, tra, ISCCP, LES',&
+   ecrit_hf, ecrit_ins, ecrit_day, ecrit_mth, ecrit_reg, ecrit_tra, ecrit_ISCCP, ecrit_LES
+
+  write(lunout,*) 'ok_strato = ', ok_strato
+  write(lunout,*) 'ok_hines = ',  ok_hines
+  write(lunout,*) 'read_climoz = ', read_climoz
+  write(lunout,*) 'carbon_cycle_tr = ', carbon_cycle_tr
+  write(lunout,*) 'carbon_cycle_cpl = ', carbon_cycle_cpl
+  
+!$OMP END MASTER
+
+  return
+  
+  end subroutine conf_phys
+
+end module conf_phys_m
+!
+!#################################################################
+!
+
+   subroutine conf_interface(tau_calv)
+
+   use IOIPSL
+   implicit none
+   include "iniprint.h"
+! Configuration de l'interace atm/surf
+!
+! tau_calv:    temps de relaxation pour la fonte des glaciers
+
+  REAL          :: tau_calv
+  REAL,SAVE     :: tau_calv_omp
+
+!
+!Config Key  = tau_calv
+!Config Desc = temps de relaxation pour fonte des glaciers en jours
+!Config Def  = 1 an 
+!Config Help = 
+!
+  tau_calv_omp = 360.*10.
+!$OMP MASTER
+  call getin('tau_calv',tau_calv_omp)
+!$OMP END MASTER
+!$OMP BARRIER
+
+  tau_calv=tau_calv_omp
+  
+!$OMP MASTER
+  write(lunout,*)' ##############################################'
+  WRITE(lunout,*)' Configuration de l''interface atm/surfaces  : '
+  WRITE(lunout,*)' tau_calv = ',tau_calv
+!$OMP END MASTER
+
+  return
+
+  end subroutine conf_interface
Index: LMDZ5/branches/testing/libf/phylmd/declare_STDlev.h
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/declare_STDlev.h	(revision 1707)
+++ LMDZ5/branches/testing/libf/phylmd/declare_STDlev.h	(revision 1707)
@@ -0,0 +1,61 @@
+cIM for NMC files
+      real twriteSTD(klon,nlevSTD,nfiles)
+      real qwriteSTD(klon,nlevSTD,nfiles)
+      real rhwriteSTD(klon,nlevSTD,nfiles)
+      real phiwriteSTD(klon,nlevSTD,nfiles)
+      real uwriteSTD(klon,nlevSTD,nfiles)
+      real vwriteSTD(klon,nlevSTD,nfiles)
+      real wwriteSTD(klon,nlevSTD,nfiles)
+
+      real twriteSTD3(klon,nlevSTD3)
+      real qwriteSTD3(klon,nlevSTD3)
+      real rhwriteSTD3(klon,nlevSTD3)
+      real phiwriteSTD3(klon,nlevSTD3)
+      real uwriteSTD3(klon,nlevSTD3)
+      real vwriteSTD3(klon,nlevSTD3)
+      real wwriteSTD3(klon,nlevSTD3)
+
+      real tnondefSTD8(klon,nlevSTD8)
+      real twriteSTD8(klon,nlevSTD8)
+      real qwriteSTD8(klon,nlevSTD8)
+      real rhwriteSTD8(klon,nlevSTD8)
+      real phiwriteSTD8(klon,nlevSTD8)
+      real uwriteSTD8(klon,nlevSTD8)
+      real vwriteSTD8(klon,nlevSTD8)
+      real wwriteSTD8(klon,nlevSTD8)
+
+      real, save :: rlevSTD(nlevSTD)
+      DATA rlevSTD/100000., 92500., 85000., 70000.,
+     .60000., 50000., 40000., 30000., 25000., 20000.,
+     .15000., 10000., 7000., 5000., 3000., 2000., 1000./
+c$OMP THREADPRIVATE(rlevstd)
+
+      CHARACTER*4, SAVE :: clevSTD(nlevSTD)
+      DATA clevSTD/'1000','925 ','850 ','700 ','600 ',
+     .'500 ','400 ','300 ','250 ','200 ','150 ','100 ',
+     .'70  ','50  ','30  ','20  ','10  '/
+c$OMP THREADPRIVATE(clevSTD)
+
+      real, save :: rlevSTD3(nlevSTD3)
+      DATA rlevSTD3/85000., 50000., 25000./
+c$OMP THREADPRIVATE(rlevSTD3)
+
+      real, save :: rlevSTD8(nlevSTD8)
+      DATA rlevSTD8/100000., 85000., 70000., 50000., 25000., 10000.,
+     $     5000., 1000./
+c$OMP THREADPRIVATE(rlevSTD8) 
+c
+      REAL geo500(klon)
+
+c nout : niveau de output des variables a une pression donnee
+      logical oknondef(klon,nlevSTD,nout)
+c
+c les produits uvSTD, vqSTD, .., T2STD sont calcules
+c a partir des valeurs instantannees toutes les 6 h
+c qui sont moyennees sur le mois
+
+      REAL zx_tmp_fiNC(klon,nlevSTD)
+
+      REAL missing_val
+      REAL, SAVE :: freq_moyNMC(nout)
+c$OMP THREADPRIVATE(freq_moyNMC)
Index: LMDZ5/branches/testing/libf/phylmd/etat0_netcdf.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/etat0_netcdf.F90	(revision 1707)
+++ LMDZ5/branches/testing/libf/phylmd/etat0_netcdf.F90	(revision 1707)
@@ -0,0 +1,530 @@
+!
+! $Id: etat0_netcdf.F90 1625 2012-05-09 13:14:48Z lguez $
+!
+!-------------------------------------------------------------------------------
+!
+SUBROUTINE etat0_netcdf(ib, masque, phis, letat0)
+!
+!-------------------------------------------------------------------------------
+! Purpose: Creates initial states
+!-------------------------------------------------------------------------------
+! Note: This routine is designed to work for Earth
+!-------------------------------------------------------------------------------
+  USE control_mod
+#ifdef CPP_EARTH
+  USE startvar
+  USE ioipsl
+  USE dimphy
+  USE infotrac
+  USE fonte_neige_mod
+  USE pbl_surface_mod
+  USE phys_state_var_mod
+  USE filtreg_mod
+  USE regr_lat_time_climoz_m, ONLY: regr_lat_time_climoz
+  USE conf_phys_m,            ONLY: conf_phys
+! For parameterization of ozone chemistry:
+  use regr_lat_time_coefoz_m, only: regr_lat_time_coefoz
+  use press_coefoz_m, only: press_coefoz
+  use regr_pr_o3_m, only: regr_pr_o3
+  USE netcdf, ONLY : NF90_OPEN, NF90_NOWRITE, NF90_CLOSE, NF90_NOERR
+#endif
+  IMPLICIT NONE
+!-------------------------------------------------------------------------------
+! Arguments:
+#include "dimensions.h"
+#include "paramet.h"
+#include "iniprint.h"
+  LOGICAL,                    INTENT(IN)    :: ib     ! barycentric interpolat.
+  REAL, DIMENSION(iip1,jjp1), INTENT(INOUT) :: masque ! land mask
+  REAL, DIMENSION(iip1,jjp1), INTENT(OUT)   :: phis   ! geopotentiel au sol
+  LOGICAL,                    INTENT(IN)    :: letat0 ! F: masque only required
+#ifndef CPP_EARTH
+  WRITE(lunout,*)'limit_netcdf: Earth-specific routine, needs Earth physics'
+#else
+!-------------------------------------------------------------------------------
+! Local variables:
+#include "comgeom2.h"
+#include "comvert.h"
+#include "comconst.h"
+#include "indicesol.h"
+#include "dimsoil.h"
+#include "temps.h"
+  REAL,    DIMENSION(klon)                 :: tsol, qsol
+  REAL,    DIMENSION(klon)                 :: sn, rugmer, run_off_lic_0
+  REAL,    DIMENSION(iip1,jjp1)            :: orog, rugo, psol
+  REAL,    DIMENSION(iip1,jjp1,llm+1)      :: p3d
+  REAL,    DIMENSION(iip1,jjp1,llm)        :: uvent, t3d, tpot, qsat, qd
+  REAL,    DIMENSION(iip1,jjm ,llm)        :: vvent
+  REAL,    DIMENSION(:,:,:,:), ALLOCATABLE :: q3d
+  REAL,    DIMENSION(klon,nbsrf)           :: qsolsrf, snsrf, evap
+  REAL,    DIMENSION(klon,nbsrf)           :: frugs, agesno
+  REAL,    DIMENSION(klon,nsoilmx,nbsrf)   :: tsoil
+
+!--- Local variables for sea-ice reading:
+  INTEGER                                  :: iml_lic, jml_lic, llm_tmp
+  INTEGER                                  :: ttm_tmp, iret, fid
+  INTEGER, DIMENSION(1)                    :: itaul
+  REAL,    DIMENSION(1)                    :: lev
+  REAL                                     :: date
+  REAL,    DIMENSION(:,:),   ALLOCATABLE   ::  lon_lic,  lat_lic, fraclic
+  REAL,    DIMENSION(:),     ALLOCATABLE   :: dlon_lic, dlat_lic
+  REAL,    DIMENSION(iip1,jjp1)            :: flic_tmp
+
+!--- Misc
+  CHARACTER(LEN=80)                        :: x, fmt
+  INTEGER                                  :: i, j, l, ji
+  REAL,    DIMENSION(iip1,jjp1,llm)        :: alpha, beta, pk, pls, y
+  REAL,    DIMENSION(ip1jmp1)              :: pks
+
+#include "comdissnew.h"
+#include "serre.h"
+#include "clesphys.h"
+
+  REAL,    DIMENSION(iip1,jjp1,llm)        :: masse
+  INTEGER :: itau, iday
+  REAL    :: xpn, xps, time, phystep
+  REAL,    DIMENSION(iim)                  :: xppn, xpps
+  REAL,    DIMENSION(ip1jmp1,llm)          :: pbaru, phi, w
+  REAL,    DIMENSION(ip1jm  ,llm)          :: pbarv
+  REAL,    DIMENSION(klon)                 :: fder
+
+!--- Local variables for ocean mask reading:
+  INTEGER :: nid_o2a, iml_omask, jml_omask
+  LOGICAL :: couple=.FALSE.
+  REAL,    DIMENSION(:,:), ALLOCATABLE ::  lon_omask, lat_omask, ocemask, ocetmp
+  REAL,    DIMENSION(:),   ALLOCATABLE :: dlon_omask,dlat_omask
+  REAL,    DIMENSION(klon)             :: ocemask_fi
+  INTEGER, DIMENSION(klon-2)           :: isst
+  REAL,    DIMENSION(iim,jjp1)         :: zx_tmp_2d
+  REAL    :: dummy
+  LOGICAL :: ok_newmicro, ok_journe, ok_mensuel, ok_instan, ok_hf
+  LOGICAL :: ok_LES, ok_ade, ok_aie, aerosol_couple, new_aod, callstats
+  INTEGER :: iflag_radia, flag_aerosol
+  REAL    :: bl95_b0, bl95_b1, fact_cldcon, facttemps, ratqsbas, ratqshaut
+  REAL    :: tau_ratqs
+  INTEGER :: iflag_cldcon, iflag_ratqs, iflag_coupl, iflag_clos, iflag_wake
+  INTEGER :: iflag_thermals, nsplit_thermals
+  INTEGER :: iflag_thermals_ed, iflag_thermals_optflux
+  REAL    :: tau_thermals, solarlong0,  seuil_inversion
+  INTEGER :: read_climoz ! read ozone climatology
+!  Allowed values are 0, 1 and 2
+!     0: do not read an ozone climatology
+!     1: read a single ozone climatology that will be used day and night
+!     2: read two ozone climatologies, the average day and night
+!     climatology and the daylight climatology
+!-------------------------------------------------------------------------------
+  REAL    :: alp_offset
+  logical found
+
+!--- Constants
+  pi     = 4. * ATAN(1.)
+  rad    = 6371229.
+  daysec = 86400.
+  omeg   = 2.*pi/daysec
+  g      = 9.8
+  kappa  = 0.2857143
+  cpp    = 1004.70885
+  preff  = 101325.
+  pa     = 50000.
+  jmp1   = jjm + 1
+
+!--- CONSTRUCT A GRID
+  CALL conf_phys(  ok_journe, ok_mensuel, ok_instan, ok_hf, ok_LES,     &
+                   callstats,                                           &
+                   solarlong0,seuil_inversion,                          &
+                   fact_cldcon, facttemps,ok_newmicro,iflag_radia,      &
+                   iflag_cldcon,                                        &
+                   iflag_ratqs,ratqsbas,ratqshaut,tau_ratqs,            &
+                   ok_ade, ok_aie, aerosol_couple,                      &
+                   flag_aerosol, new_aod,                               &
+                   bl95_b0, bl95_b1,                                    &
+                   read_climoz,                                         &
+                   alp_offset)
+
+! co2_ppm0 : initial value of atmospheric CO2 from .def file (co2_ppm value)
+  co2_ppm0 = co2_ppm
+
+  dtvr   = daysec/FLOAT(day_step)
+  WRITE(lunout,*)'dtvr',dtvr
+
+  CALL iniconst()
+  CALL inigeom()
+
+!--- Initializations for tracers
+  CALL infotrac_init
+  ALLOCATE(q3d(iip1,jjp1,llm,nqtot))
+
+  CALL inifilr()
+  CALL phys_state_var_init(read_climoz)
+
+  rlat(1) = ASIN(1.0)
+  DO j=2,jjm; rlat((j-2)*iim+2:(j-1)*iim+1)=rlatu(j);     END DO
+  rlat(klon) = - ASIN(1.0)
+  rlat(:)=rlat(:)*(180.0/pi)
+
+  rlon(1) = 0.0
+  DO j=2,jjm; rlon((j-2)*iim+2:(j-1)*iim+1)=rlonv(1:iim); END DO
+  rlon(klon) = 0.0
+  rlon(:)=rlon(:)*(180.0/pi)
+
+! For a coupled simulation, the ocean mask from ocean model is used to compute
+! the weights an to insure ocean fractions are the same for atmosphere and ocean
+! Otherwise, mask is created using Relief file.
+
+  WRITE(lunout,*)'Essai de lecture masque ocean'
+  iret = NF90_OPEN("o2a.nc", NF90_NOWRITE, nid_o2a)
+  IF(iret/=NF90_NOERR) THEN
+    WRITE(lunout,*)'ATTENTION!! pas de fichier o2a.nc trouve'
+    WRITE(lunout,*)'Run force'
+    x='masque'
+    masque(:,:)=0.0
+    CALL startget_phys2d(x, iip1, jjp1, rlonv, rlatu, masque, 0.0, jjm, &
+   &              rlonu, rlatv, ib)
+    WRITE(lunout,*)'MASQUE construit : Masque'
+    WRITE(lunout,'(97I1)') nINT(masque)
+    CALL gr_dyn_fi(1, iip1, jjp1, klon, masque, zmasq)
+    WHERE(   zmasq(:)<EPSFRA) zmasq(:)=0.
+    WHERE(1.-zmasq(:)<EPSFRA) zmasq(:)=1.
+  ELSE
+    WRITE(lunout,*)'ATTENTION!! fichier o2a.nc trouve'
+    WRITE(lunout,*)'Run couple'
+    couple=.true.
+    iret=NF90_CLOSE(nid_o2a)
+    CALL flininfo("o2a.nc", iml_omask, jml_omask, llm_tmp, ttm_tmp, nid_o2a)
+    IF(iml_omask/=iim .OR.jml_omask/=jjp1) THEN
+      WRITE(lunout,*)'Dimensions non compatibles pour masque ocean'
+      WRITE(lunout,*)'iim = ',iim,' iml_omask = ',iml_omask
+      WRITE(lunout,*)'jjp1 = ',jjp1,' jml_omask = ',jml_omask
+      CALL abort_gcm('etat0_netcdf','Dimensions non compatibles pour masque oc&
+     &ean',1)
+    END IF
+    ALLOCATE(   ocemask(iml_omask,jml_omask),   ocetmp(iml_omask,jml_omask))
+    ALLOCATE( lon_omask(iml_omask,jml_omask),lat_omask(iml_omask,jml_omask))
+    ALLOCATE(dlon_omask(iml_omask),         dlat_omask(jml_omask))
+    CALL flinopen("o2a.nc", .FALSE., iml_omask, jml_omask, llm_tmp, lon_omask,&
+   &              lat_omask, lev, ttm_tmp, itaul, date, dt, fid)
+    CALL flinget(fid, 'OceMask', iml_omask, jml_omask, llm_tmp, ttm_tmp, &
+   &              1, 1, ocetmp)
+    CALL flinclo(fid)
+    dlon_omask(1:iml_omask) = lon_omask(1:iml_omask,1)
+    dlat_omask(1:jml_omask) = lat_omask(1,1:jml_omask)
+    ocemask = ocetmp
+    IF(dlat_omask(1)<dlat_omask(jml_omask)) THEN
+      DO j=1,jml_omask
+        ocemask(:,j) = ocetmp(:,jml_omask-j+1)
+      END DO
+    END IF
+!
+! Ocean mask to physical grid
+!*******************************************************************************
+    WRITE(lunout,*)'ocemask '
+    WRITE(fmt,"(i4,'i1)')")iml_omask ; fmt='('//ADJUSTL(fmt)
+    WRITE(lunout,fmt)int(ocemask)
+    ocemask_fi(1)=ocemask(1,1)
+    DO j=2,jjm; ocemask_fi((j-2)*iim+2:(j-1)*iim+1)=ocemask(1:iim,j); END DO
+    ocemask_fi(klon)=ocemask(1,jjp1)
+    zmasq=1.-ocemask_fi
+  END IF
+
+  CALL gr_fi_dyn(1,klon,iip1,jjp1,zmasq,masque)
+
+  ! The startget calls need to be replaced by a call to restget to get the
+  ! values in the restart file
+  x = 'relief'; orog(:,:) = 0.0
+  CALL startget_phys2d(x,iip1,jjp1,rlonv,rlatu, orog, 0.0,jjm,rlonu,rlatv,ib,&
+ &               masque)
+
+  x = 'rugosite'; rugo(:,:) = 0.0
+  CALL startget_phys2d(x,iip1,jjp1,rlonv,rlatu, rugo, 0.0,jjm, rlonu,rlatv,ib)
+!  WRITE(lunout,'(49I1)') INT(orog(:,:)*10)
+!  WRITE(lunout,'(49I1)') INT(rugo(:,:)*10)
+
+! Sub-surfaces initialization
+!*******************************************************************************
+  pctsrf=0.
+  x = 'psol'; psol(:,:) = 0.0
+  CALL startget_phys2d(x,iip1,jjp1,rlonv,rlatu,psol,0.0,jjm,rlonu,rlatv,ib)
+!  WRITE(lunout,*) 'PSOL :', psol(10,20)
+!  WRITE(lunout,*) ap(:), bp(:)
+
+! Mid-levels pressure computation
+!*******************************************************************************
+  CALL pression(ip1jmp1, ap, bp, psol, p3d)
+  if (pressure_exner) then
+    CALL exner_hyb(ip1jmp1, psol, p3d, alpha, beta, pks, pk, y)
+  else
+    CALL exner_milieu(ip1jmp1,psol,p3d,beta,pks,pk,y)
+  endif
+  pls(:,:,:)=preff*(pk(:,:,:)/cpp)**(1./kappa)
+!  WRITE(lunout,*) 'P3D :', p3d(10,20,:)
+!  WRITE(lunout,*) 'PK:',    pk(10,20,:)
+!  WRITE(lunout,*) 'PLS :', pls(10,20,:)
+
+  x = 'surfgeo'; phis(:,:) = 0.0
+  CALL startget_phys2d(x,iip1,jjp1,rlonv,rlatu,phis, 0.0,jjm, rlonu,rlatv,ib)
+
+  x = 'u';    uvent(:,:,:) = 0.0
+  CALL startget_dyn(x,rlonu,rlatu,pls,y,uvent,0.0,  &
+ &                  rlonv,rlatv,ib)
+
+  x = 'v';    vvent(:,:,:) = 0.0
+  CALL startget_dyn(x, rlonv,rlatv,pls(:, :jjm, :),y(:, :jjm, :),vvent,0.0, &
+ &                  rlonu,rlatu(:jjm),ib)
+
+  x = 't';    t3d(:,:,:) = 0.0
+  CALL startget_dyn(x,rlonv,rlatu,pls,y,t3d,0.0,    &
+ &                  rlonu,rlatv,ib)
+
+  x = 'tpot'; tpot(:,:,:) = 0.0
+  CALL startget_dyn(x,rlonv,rlatu,pls,pk,tpot,0.0,  &
+ &                  rlonu,rlatv,ib)
+
+  WRITE(lunout,*) 'T3D min,max:',minval(t3d(:,:,:)),maxval(t3d(:,:,:))
+  WRITE(lunout,*) 'PLS min,max:',minval(pls(:,:,:)),maxval(pls(:,:,:))
+
+! Humidity at saturation computation
+!*******************************************************************************
+  WRITE(lunout,*) 'avant q_sat'
+  CALL q_sat(llm*jjp1*iip1, t3d, pls, qsat)
+  WRITE(lunout,*) 'apres q_sat'
+  WRITE(lunout,*) 'QSAT min,max:',minval(qsat(:,:,:)),maxval(qsat(:,:,:))
+!  WRITE(lunout,*) 'QSAT :',qsat(10,20,:)
+
+  x = 'q';    qd (:,:,:) = 0.0
+  CALL startget_dyn(x,rlonv,rlatu,pls,qsat,qd,0.0, rlonu,rlatv,ib)
+  q3d(:,:,:,:) = 0.0 ; q3d(:,:,:,1) = qd(:,:,:)
+
+! Parameterization of ozone chemistry:
+! Look for ozone tracer:
+  i = 1
+  DO
+    found = tname(i)=="O3" .OR. tname(i)=="o3"
+    if (found .or. i == nqtot) exit
+    i = i + 1
+  end do
+  if (found) then
+    call regr_lat_time_coefoz
+    call press_coefoz
+    call regr_pr_o3(p3d, q3d(:, :, :, i))
+!   Convert from mole fraction to mass fraction:
+    q3d(:, :, :, i) = q3d(:, :, :, i)  * 48. / 29.
+  end if
+
+!--- OZONE CLIMATOLOGY
+  IF(read_climoz>=1) CALL regr_lat_time_climoz(read_climoz)
+
+  x = 'tsol'; tsol(:) = 0.0
+  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,tsol,0.0,jjm,rlonu,rlatv,ib)
+
+  x = 'qsol';  qsol(:) = 0.0
+  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,qsol,0.0,jjm,rlonu,rlatv,ib)
+
+  x = 'snow';  sn(:) = 0.0
+  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,sn,0.0,jjm,rlonu,rlatv,ib)
+
+  x = 'rads';  radsol(:) = 0.0
+  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,radsol,0.0,jjm,rlonu,rlatv,ib)
+
+  x = 'rugmer'; rugmer(:) = 0.0
+  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,rugmer,0.0,jjm,rlonu,rlatv,ib)
+
+  x = 'zmea';  zmea(:) = 0.0
+  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,zmea,0.0,jjm,rlonu,rlatv,ib)
+
+  x = 'zstd';  zstd(:) = 0.0
+  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,zstd,0.0,jjm,rlonu,rlatv,ib)
+
+  x = 'zsig';  zsig(:) = 0.0
+  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,zsig,0.0,jjm,rlonu,rlatv,ib)
+
+  x = 'zgam';  zgam(:) = 0.0
+  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,zgam,0.0,jjm,rlonu,rlatv,ib)
+
+  x = 'zthe';  zthe(:) = 0.0
+  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,zthe,0.0,jjm,rlonu,rlatv,ib)
+
+  x = 'zpic';  zpic(:) = 0.0
+  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,zpic,0.0,jjm,rlonu,rlatv,ib)
+
+  x = 'zval';  zval(:) = 0.0
+  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,zval,0.0,jjm,rlonu,rlatv,ib)
+
+!  WRITE(lunout,'(48I3)') 'TSOL :', INT(tsol(2:klon)-273)
+
+! Soil ice file reading for soil fraction and soil ice fraction
+!*******************************************************************************
+  CALL flininfo("landiceref.nc", iml_lic, jml_lic, llm_tmp, ttm_tmp, fid)
+  ALLOCATE( lat_lic(iml_lic,jml_lic),lon_lic(iml_lic, jml_lic))
+  ALLOCATE(dlat_lic(jml_lic),       dlon_lic(iml_lic))
+  ALLOCATE( fraclic(iml_lic,jml_lic))
+  CALL flinopen("landiceref.nc", .FALSE., iml_lic, jml_lic, llm_tmp,  &
+ &               lon_lic, lat_lic, lev, ttm_tmp, itaul, date, dt, fid)
+  CALL flinget(fid, 'landice', iml_lic, jml_lic, llm_tmp, ttm_tmp, 1,1, fraclic)
+  CALL flinclo(fid)
+
+! Interpolation on model T-grid
+!*******************************************************************************
+  WRITE(lunout,*)'dimensions de landice iml_lic, jml_lic : ',iml_lic,jml_lic
+! conversion if coordinates are in degrees
+  IF(MAXVAL(lon_lic)>pi) lon_lic=lon_lic*pi/180.
+  IF(MAXVAL(lat_lic)>pi) lat_lic=lat_lic*pi/180.
+  dlon_lic(:)=lon_lic(:,1)
+  dlat_lic(:)=lat_lic(1,:)
+  CALL grille_m( iml_lic, jml_lic, dlon_lic, dlat_lic, fraclic, iim,jjp1,   &
+ &               rlonv, rlatu, flic_tmp(1:iim,:) )
+  flic_tmp(iip1,:)=flic_tmp(1,:)
+
+!--- To the physical grid
+  CALL gr_dyn_fi(1, iip1, jjp1, klon, flic_tmp, pctsrf(:,is_lic))
+
+!--- Adequation with soil/sea mask
+  WHERE(pctsrf(:,is_lic)<EPSFRA) pctsrf(:,is_lic)=0. 
+  WHERE(zmasq(:)<EPSFRA)         pctsrf(:,is_lic)=0.
+  pctsrf(:,is_ter)=zmasq(:)
+  DO ji=1,klon
+    IF(zmasq(ji)>EPSFRA) THEN 
+      IF(pctsrf(ji,is_lic)>=zmasq(ji)) THEN
+        pctsrf(ji,is_lic)=zmasq(ji)
+        pctsrf(ji,is_ter)=0.
+      ELSE
+        pctsrf(ji,is_ter)=zmasq(ji)-pctsrf(ji,is_lic)
+        IF(pctsrf(ji,is_ter)<EPSFRA) THEN
+          pctsrf(ji,is_ter)=0.
+          pctsrf(ji,is_lic)=zmasq(ji)
+        END IF 
+      END IF 
+    END IF 
+  END DO 
+
+! sub-surface ocean and sea ice (sea ice set to zero for start)
+!*******************************************************************************
+  pctsrf(:,is_oce)=(1.-zmasq(:))
+  WHERE(pctsrf(:,is_oce)<EPSFRA) pctsrf(:,is_oce)=0.
+  IF(couple) pctsrf(:,is_oce)=ocemask_fi(:)
+  isst=0
+  WHERE(pctsrf(2:klon-1,is_oce)>0.) isst=1
+
+! It is checked that the sub-surfaces sum is equal to 1
+!*******************************************************************************
+  ji=COUNT((ABS(SUM(pctsrf(:,:),dim=2))-1.0)>EPSFRA)
+  IF(ji/=0) WRITE(lunout,*) 'pb repartition sous maille pour ',ji,' points'
+  CALL gr_fi_ecrit(1, klon, iim, jjp1, zmasq, zx_tmp_2d)
+!  WRITE(fmt,"(i3,')')")iim; fmt='(i'//ADJUSTL(fmt)
+!  WRITE(lunout,*)'zmasq = '
+!  WRITE(lunout,TRIM(fmt))NINT(zx_tmp_2d)
+  CALL gr_fi_dyn(1, klon, iip1, jjp1, zmasq, masque)
+  WRITE(fmt,"(i4,'i1)')")iip1 ; fmt='('//ADJUSTL(fmt)
+  WRITE(lunout,*) 'MASQUE construit : Masque'
+  WRITE(lunout,TRIM(fmt))NINT(masque(:,:))
+
+! Intermediate computation
+!*******************************************************************************
+  CALL massdair(p3d,masse)
+  WRITE(lunout,*)' ALPHAX ',alphax
+  DO l=1,llm
+    xppn(:)=aire(1:iim,1   )*masse(1:iim,1   ,l)
+    xpps(:)=aire(1:iim,jjp1)*masse(1:iim,jjp1,l)
+    xpn=SUM(xppn)/apoln
+    xps=SUM(xpps)/apols
+    masse(:,1   ,l)=xpn
+    masse(:,jjp1,l)=xps
+  END DO
+  q3d(iip1,:,:,:)=q3d(1,:,:,:)
+  phis(iip1,:) = phis(1,:)
+
+  IF(.NOT.letat0) RETURN
+
+! Writing
+!*******************************************************************************
+  CALL inidissip(lstardis,nitergdiv,nitergrot,niterh,tetagdiv,tetagrot,tetatemp)
+  WRITE(lunout,*)'sortie inidissip'
+  itau=0
+  itau_dyn=0
+  itau_phy=0
+  iday=dayref+itau/day_step
+  time=FLOAT(itau-(iday-dayref)*day_step)/day_step
+  IF(time>1.) THEN
+   time=time-1
+   iday=iday+1
+  END IF
+  day_ref=dayref
+  annee_ref=anneeref
+
+  CALL geopot( ip1jmp1, tpot, pk, pks, phis, phi )
+  WRITE(lunout,*)'sortie geopot'
+
+  CALL caldyn0( itau, uvent, vvent, tpot, psol, masse, pk, phis,               &
+                phi,  w, pbaru, pbarv, time+iday-dayref)
+  WRITE(lunout,*)'sortie caldyn0'     
+  CALL dynredem0( "start.nc", dayref, phis)
+  WRITE(lunout,*)'sortie dynredem0'
+  CALL dynredem1( "start.nc", 0.0, vvent, uvent, tpot, q3d, masse, psol)
+  WRITE(lunout,*)'sortie dynredem1' 
+
+! Physical initial state writting
+!*******************************************************************************
+  WRITE(lunout,*)'phystep ',dtvr,iphysiq,nbapp_rad
+  phystep   = dtvr * FLOAT(iphysiq)
+  radpas    = NINT (86400./phystep/ FLOAT(nbapp_rad) )
+  WRITE(lunout,*)'phystep =', phystep, radpas
+
+! Init: tsol, qsol, sn, evap, tsoil, rain_fall, snow_fall, solsw, sollw, frugs
+!*******************************************************************************
+  DO i=1,nbsrf; ftsol(:,i) = tsol; END DO
+  DO i=1,nbsrf; snsrf(:,i) = sn;   END DO
+  falb1(:,is_ter) = 0.08; falb1(:,is_lic) = 0.6
+  falb1(:,is_oce) = 0.5;  falb1(:,is_sic) = 0.6
+  falb2 = falb1
+  evap(:,:) = 0.
+  DO i=1,nbsrf; qsolsrf(:,i)=150.; END DO
+  DO i=1,nbsrf; DO j=1,nsoilmx; tsoil(:,j,i) = tsol; END DO; END DO
+  rain_fall = 0.; snow_fall = 0.
+  solsw = 165.;   sollw = -53.
+  t_ancien = 273.15
+  q_ancien = 0.
+  agesno = 0.
+  frugs(:,is_oce) = rugmer(:)
+  frugs(:,is_ter) = MAX(1.0e-05,zstd(:)*zsig(:)/2.0)
+  frugs(:,is_lic) = MAX(1.0e-05,zstd(:)*zsig(:)/2.0)
+  frugs(:,is_sic) = 0.001
+  fder = 0.0
+  clwcon = 0.0
+  rnebcon = 0.0
+  ratqs = 0.0
+  run_off_lic_0 = 0.0 
+  rugoro = 0.0
+
+! Before phyredem calling, surface modules and values to be saved in startphy.nc
+! are initialized
+!*******************************************************************************
+  dummy = 1.0
+  pbl_tke(:,:,:) = 1.e-8 
+  zmax0(:) = 40.
+  f0(:) = 1.e-5
+  ema_work1(:,:) = 0.
+  ema_work2(:,:) = 0.
+  wake_deltat(:,:) = 0.
+  wake_deltaq(:,:) = 0.
+  wake_s(:) = 0.
+  wake_cstar(:) = 0.
+  wake_fip(:) = 0.
+  wake_pe = 0.
+  fm_therm = 0.
+  entr_therm = 0.
+  detr_therm = 0.
+
+  CALL fonte_neige_init(run_off_lic_0)
+  CALL pbl_surface_init( qsol, fder, snsrf, qsolsrf, evap, frugs, agesno, tsoil )
+  CALL phyredem( "startphy.nc" )
+
+!  WRITE(lunout,*)'CCCCCCCCCCCCCCCCCC REACTIVER SORTIE VISU DANS ETAT0'
+!  WRITE(lunout,*)'entree histclo'
+  CALL histclo()
+
+#endif 
+!#endif of #ifdef CPP_EARTH
+  RETURN
+
+END SUBROUTINE etat0_netcdf
+!
+!-------------------------------------------------------------------------------
Index: LMDZ5/branches/testing/libf/phylmd/iniphysiq.F
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/iniphysiq.F	(revision 1669)
+++ LMDZ5/branches/testing/libf/phylmd/iniphysiq.F	(revision 1707)
@@ -8,9 +8,10 @@
      $           pdayref,ptimestep,
      $           plat,plon,parea,pcu,pcv,
-     $           prad,pg,pr,pcpp)
-      USE dimphy
-      USE mod_grid_phy_lmdz
-      USE mod_phys_lmdz_para
-      USE comgeomphy
+     $           prad,pg,pr,pcpp,iflag_phys)
+      USE dimphy, only : klev
+      USE mod_grid_phy_lmdz, only : klon_glo
+      USE mod_phys_lmdz_para, only : klon_omp,klon_omp_begin,
+     &                               klon_omp_end,klon_mpi_begin
+      USE comgeomphy, only : airephy,cuphy,cvphy,rlond,rlatd
 
       IMPLICIT NONE
@@ -18,18 +19,7 @@
 c=======================================================================
 c
-c   subject:
-c   --------
+c   Initialisation of the physical constants and some positional and 
+c   geometrical arrays for the physics
 c
-c   Initialisation for the physical parametrisations of the LMD 
-c   martian atmospheric general circulation modele.
-c
-c   author: Frederic Hourdin 15 / 10 /93
-c   -------
-c
-c   arguments:
-c   ----------
-c
-c   input:
-c   ------
 c
 c    ngrid                 Size of the horizontal grid.
@@ -37,14 +27,6 @@
 c    nlayer                Number of vertical layers.
 c    pdayref               Day of reference for the simulation
-c    firstcall             True at the first call
-c    lastcall              True at the last call
-c    pday                  Number of days counted from the North. Spring
-c                          equinoxe.
 c
 c=======================================================================
-c
-c-----------------------------------------------------------------------
-c   declarations:
-c   -------------
  
 cym#include "dimensions.h"
@@ -52,21 +34,31 @@
 cym#include "comgeomphy.h"
 #include "YOMCST.h"
-      REAL prad,pg,pr,pcpp,punjours
- 
-      INTEGER ngrid,nlayer
-      REAL plat(ngrid),plon(ngrid),parea(klon_glo)
-      REAL pcu(klon_glo),pcv(klon_glo)
-      INTEGER pdayref
-      INTEGER :: ibegin,iend,offset
- 
-      REAL ptimestep
+#include "iniprint.h"
+
+      REAL,INTENT(IN) :: prad ! radius of the planet (m)
+      REAL,INTENT(IN) :: pg ! gravitational acceleration (m/s2)
+      REAL,INTENT(IN) :: pr ! ! reduced gas constant R/mu
+      REAL,INTENT(IN) :: pcpp ! specific heat Cp
+      REAL,INTENT(IN) :: punjours ! length (in s) of a standard day
+      INTEGER,INTENT(IN) :: ngrid ! number of horizontal grid points in the physics
+      INTEGER,INTENT(IN) :: nlayer ! number of atmospheric layers
+      REAL,INTENT(IN) :: plat(ngrid) ! latitudes of the physics grid
+      REAL,INTENT(IN) :: plon(ngrid) ! longitudes of the physics grid
+      REAL,INTENT(IN) :: parea(klon_glo) ! area (m2)
+      REAL,INTENT(IN) :: pcu(klon_glo) ! cu coeff. (u_covariant = cu * u)
+      REAL,INTENT(IN) :: pcv(klon_glo) ! cv coeff. (v_covariant = cv * v)
+      INTEGER,INTENT(IN) :: pdayref ! reference day of for the simulation
+      REAL,INTENT(IN) :: ptimestep !physics time step (s)
+      INTEGER,INTENT(IN) :: iflag_phys ! type of physics to be called
+
+      INTEGER :: ibegin,iend,offset 
       CHARACTER (LEN=20) :: modname='iniphysiq'
       CHARACTER (LEN=80) :: abort_message
  
       IF (nlayer.NE.klev) THEN
-         PRINT*,'STOP in inifis'
-         PRINT*,'Probleme de dimensions :'
-         PRINT*,'nlayer     = ',nlayer
-         PRINT*,'klev   = ',klev
+         write(lunout,*) 'STOP in ',trim(modname)
+         write(lunout,*) 'Problem with dimensions :'
+         write(lunout,*) 'nlayer     = ',nlayer
+         write(lunout,*) 'klev   = ',klev
          abort_message = ''
          CALL abort_gcm (modname,abort_message,1)
@@ -74,13 +66,14 @@
 
       IF (ngrid.NE.klon_glo) THEN
-         PRINT*,'STOP in inifis'
-         PRINT*,'Probleme de dimensions :'
-         PRINT*,'ngrid     = ',ngrid
-         PRINT*,'klon   = ',klon_glo
+         write(lunout,*) 'STOP in ',trim(modname)
+         write(lunout,*) 'Problem with dimensions :'
+         write(lunout,*) 'ngrid     = ',ngrid
+         write(lunout,*) 'klon   = ',klon_glo
          abort_message = ''
          CALL abort_gcm (modname,abort_message,1)
       ENDIF
-c$OMP PARALLEL PRIVATE(ibegin,iend) 
-c$OMP+         SHARED(parea,pcu,pcv,plon,plat)
+
+!$OMP PARALLEL PRIVATE(ibegin,iend) 
+!$OMP+         SHARED(parea,pcu,pcv,plon,plat)
       
       offset=klon_mpi_begin-1
@@ -92,16 +85,76 @@
       rlatd(1:klon_omp)=plat(offset+klon_omp_begin:offset+klon_omp_end)
 
+      ! suphel => initialize some physical constants (orbital parameters,
+      !           geoid, gravity, thermodynamical constants, etc.) in the
+      !           physics
       call suphel
+      
+!$OMP END PARALLEL
 
-c$OMP END PARALLEL
+      ! check that physical constants set in 'suphel' are coherent
+      ! with values set in the dynamics:
+      if (RDAY.ne.punjours) then
+        write(lunout,*) "iniphysiq: length of day discrepancy!!!"
+        write(lunout,*) "  in the dynamics punjours=",punjours
+        write(lunout,*) "   but in the physics RDAY=",RDAY
+        if (abs(RDAY-punjours).gt.0.01) then
+          ! stop here if the relative difference is more than 1%
+          abort_message = 'length of day discrepancy'
+          CALL abort_gcm (modname,abort_message,1)
+        endif
+      endif
+      if (RG.ne.pg) then
+        write(lunout,*) "iniphysiq: gravity discrepancy !!!"
+        write(lunout,*) "     in the dynamics pg=",pg
+        write(lunout,*) "  but in the physics RG=",RG
+        if (abs(RG-pg).gt.0.01) then
+          ! stop here if the relative difference is more than 1%
+          abort_message = 'gravity discrepancy'
+          CALL abort_gcm (modname,abort_message,1)
+        endif
+      endif
+      if (RA.ne.prad) then
+        write(lunout,*) "iniphysiq: planet radius discrepancy !!!"
+        write(lunout,*) "   in the dynamics prad=",prad
+        write(lunout,*) "  but in the physics RA=",RA
+        if (abs(RA-prad).gt.0.01) then
+          ! stop here if the relative difference is more than 1%
+          abort_message = 'planet radius discrepancy'
+          CALL abort_gcm (modname,abort_message,1)
+        endif
+      endif
+      if (RD.ne.pr) then
+        write(lunout,*)"iniphysiq: reduced gas constant discrepancy !!!"
+        write(lunout,*)"     in the dynamics pr=",pr
+        write(lunout,*)"  but in the physics RD=",RD
+        if (abs(RD-pr).gt.0.01) then
+          ! stop here if the relative difference is more than 1%
+          abort_message = 'reduced gas constant discrepancy'
+          CALL abort_gcm (modname,abort_message,1)
+        endif
+      endif
+      if (RCPD.ne.pcpp) then
+        write(lunout,*)"iniphysiq: specific heat discrepancy !!!"
+        write(lunout,*)"     in the dynamics pcpp=",pcpp
+        write(lunout,*)"  but in the physics RCPD=",RCPD
+        if (abs(RCPD-pcpp).gt.0.01) then
+          ! stop here if the relative difference is more than 1%
+          abort_message = 'specific heat discrepancy'
+          CALL abort_gcm (modname,abort_message,1)
+        endif
+      endif
 
-      print*,'ATTENTION !!! TRAVAILLER SUR INIPHYSIQ'
-      print*,'CONTROLE DES LATITUDES, LONGITUDES, PARAMETRES ...'
+! Additional initializations for aquaplanets
+!$OMP PARALLEL
+      if (iflag_phys>=100) then
+        call iniaqua(klon_omp,rlatd,rlond,iflag_phys)
+      endif
+!$OMP END PARALLEL
 
-      RETURN
-9999  CONTINUE
-      abort_message ='Cette version demande les fichier rnatur.dat
-     & et surf.def'
-      CALL abort_gcm (modname,abort_message,1)
+!      RETURN
+!9999  CONTINUE
+!      abort_message ='Cette version demande les fichier rnatur.dat
+!     & et surf.def'
+!      CALL abort_gcm (modname,abort_message,1)
 
       END
Index: LMDZ5/branches/testing/libf/phylmd/iophy.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/iophy.F90	(revision 1669)
+++ LMDZ5/branches/testing/libf/phylmd/iophy.F90	(revision 1707)
@@ -51,8 +51,8 @@
     
 !$OMP MASTER  
-    ALLOCATE(io_lat(jjm+1-1/iim))
+    ALLOCATE(io_lat(jjm+1-1/(iim*jjm)))
     io_lat(1)=rlat_glo(1)
-    io_lat(jjm+1-1/iim)=rlat_glo(klon_glo)
-    IF (iim > 1) then
+    io_lat(jjm+1-1/(iim*jjm))=rlat_glo(klon_glo)
+    IF ((iim*jjm) > 1) then
       DO i=2,jjm
         io_lat(i)=rlat_glo(2+(i-2)*iim)
@@ -61,8 +61,8 @@
 
     ALLOCATE(io_lon(iim))
-    io_lon(:)=rlon_glo(2-1/iim:iim+1-1/iim)
+    io_lon(:)=rlon_glo(2-1/(iim*jjm):iim+1-1/(iim*jjm))
 
     ddid=(/ 1,2 /)
-    dsg=(/ iim, jjm+1-1/iim /)
+    dsg=(/ iim, jjm+1-1/(iim*jjm) /)
     dsl=(/ iim, jj_nb /)
     dpf=(/ 1,jj_begin /)
@@ -89,5 +89,5 @@
   include 'dimensions.h'   
     real,dimension(iim),intent(in) :: lon
-    real,dimension(jjm+1-1/iim),intent(in) :: lat
+    real,dimension(jjm+1-1/(iim*jjm)),intent(in) :: lat
 
     INTEGER,DIMENSION(2) :: ddid
@@ -100,5 +100,5 @@
 
 !$OMP MASTER  
-    allocate(io_lat(jjm+1-1/iim))
+    allocate(io_lat(jjm+1-1/(iim*jjm)))
     io_lat(:)=lat(:)
     allocate(io_lon(iim))
@@ -106,5 +106,5 @@
    
     ddid=(/ 1,2 /)
-    dsg=(/ iim, jjm+1-1/iim /)
+    dsg=(/ iim, jjm+1-1/(iim*jjm) /)
     dsl=(/ iim, jj_nb /)
     dpf=(/ 1,jj_begin /)
@@ -234,5 +234,5 @@
 
        CALL gr_fi_ecrit(1,klon,iim,jjmp1,rlon_glo,zx_lon)
-       if (iim.gt.1) then
+       if ((iim*jjm).gt.1) then
        DO i = 1, iim
          zx_lon(i,1) = rlon_glo(i+1)
Index: LMDZ5/branches/testing/libf/phylmd/limit_netcdf.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/limit_netcdf.F90	(revision 1707)
+++ LMDZ5/branches/testing/libf/phylmd/limit_netcdf.F90	(revision 1707)
@@ -0,0 +1,642 @@
+!
+! $Id: limit_netcdf.F90 1508 2011-04-15 13:05:34Z jghattas $
+!-------------------------------------------------------------------------------
+!
+SUBROUTINE limit_netcdf(interbar, extrap, oldice, masque)
+!
+!-------------------------------------------------------------------------------
+! Author : L. Fairhead, 27/01/94
+!-------------------------------------------------------------------------------
+! Purpose: Boundary conditions files building for new model using climatologies.
+!          Both grids have to be regular.
+!-------------------------------------------------------------------------------
+! Note: This routine is designed to work for Earth
+!-------------------------------------------------------------------------------
+! Modification history:
+!  * 23/03/1994: Z. X. Li
+!  *    09/1999: L. Fairhead (netcdf reading in LMDZ.3.3)
+!  *    07/2001: P. Le Van
+!  *    11/2009: L. Guez     (ozone day & night climatos, see etat0_netcdf.F90)
+!  *    12/2009: D. Cugnet   (f77->f90, calendars, files from coupled runs)
+!-------------------------------------------------------------------------------
+  USE control_mod
+#ifdef CPP_EARTH
+  USE dimphy
+  USE ioipsl,             ONLY : ioget_year_len
+  USE phys_state_var_mod, ONLY : pctsrf
+  USE netcdf,             ONLY : NF90_OPEN,    NF90_CREATE,  NF90_CLOSE,       &
+                   NF90_DEF_DIM, NF90_DEF_VAR, NF90_PUT_VAR, NF90_PUT_ATT,     &
+                   NF90_NOERR,   NF90_NOWRITE, NF90_DOUBLE,  NF90_GLOBAL,      &
+		   NF90_CLOBBER, NF90_ENDDEF,  NF90_UNLIMITED, NF90_FLOAT
+  USE inter_barxy_m, only: inter_barxy
+#endif
+  IMPLICIT NONE
+!-------------------------------------------------------------------------------
+! Arguments:
+#include "dimensions.h"
+#include "paramet.h"
+#include "iniprint.h"
+  LOGICAL,                    INTENT(IN) :: interbar ! barycentric interpolation
+  LOGICAL,                    INTENT(IN) :: extrap   ! SST extrapolation flag
+  LOGICAL,                    INTENT(IN) :: oldice   ! old way ice computation
+  REAL, DIMENSION(iip1,jjp1), INTENT(IN) :: masque   ! land mask
+#ifndef CPP_EARTH
+  CALL abort_gcm('limit_netcdf','Earth-specific routine, needs Earth physics',1)
+#else
+!-------------------------------------------------------------------------------
+! Local variables:
+#include "logic.h"
+#include "comvert.h"
+#include "comgeom2.h"
+#include "comconst.h"
+#include "indicesol.h"
+
+!--- INPUT NETCDF FILES NAMES --------------------------------------------------
+  CHARACTER(LEN=25) :: icefile, sstfile, dumstr
+  CHARACTER(LEN=25), PARAMETER :: famipsst='amipbc_sst_1x1.nc        ',        &
+                                  famipsic='amipbc_sic_1x1.nc        ',        &
+                                  fcpldsst='cpl_atm_sst.nc           ',        &
+                                  fcpldsic='cpl_atm_sic.nc           ',        &
+                                  fhistsst='histmth_sst.nc           ',        &
+                                  fhistsic='histmth_sic.nc           ',        &
+                                  frugo   ='Rugos.nc                 ',        &
+                                  falbe   ='Albedo.nc                '
+  CHARACTER(LEN=10) :: varname
+!--- OUTPUT VARIABLES FOR NETCDF FILE ------------------------------------------
+  REAL,   DIMENSION(klon)                :: fi_ice, verif
+  REAL,   DIMENSION(:,:),   POINTER      :: phy_rug=>NULL(), phy_ice=>NULL()
+  REAL,   DIMENSION(:,:),   POINTER      :: phy_sst=>NULL(), phy_alb=>NULL()
+  REAL,   DIMENSION(:,:),   ALLOCATABLE  :: phy_bil
+  REAL,   DIMENSION(:,:,:), ALLOCATABLE  :: pctsrf_t
+  INTEGER                                :: nbad
+
+!--- VARIABLES FOR OUTPUT FILE WRITING -----------------------------------------
+  INTEGER :: ierr, nid, ndim, ntim, k
+  INTEGER, DIMENSION(2) :: dims
+  INTEGER :: id_tim,  id_SST,  id_BILS, id_RUG, id_ALB
+  INTEGER :: id_FOCE, id_FSIC, id_FTER, id_FLIC
+  INTEGER :: NF90_FORMAT
+  INTEGER :: ndays                   !--- Depending on the output calendar
+
+!--- INITIALIZATIONS -----------------------------------------------------------
+#ifdef NC_DOUBLE
+  NF90_FORMAT=NF90_DOUBLE
+#else
+  NF90_FORMAT=NF90_FLOAT
+#endif
+
+  pi    = 4.*ATAN(1.)
+  rad   = 6371229.
+  daysec= 86400.
+  omeg  = 2.*pi/daysec
+  g     = 9.8
+  kappa = 0.2857143
+  cpp   = 1004.70885
+  dtvr  = daysec/REAL(day_step)
+  CALL inigeom
+
+!--- Beware: anneeref (from gcm.def) is used to determine output time sampling
+  ndays=ioget_year_len(anneeref)
+
+!--- RUGOSITY TREATMENT --------------------------------------------------------
+  IF (prt_level>1) WRITE(lunout,*) 'Traitement de la rugosite'
+  varname='RUGOS'
+  CALL get_2Dfield(frugo,varname,'RUG',interbar,ndays,phy_rug,mask=masque(1:iim,:))
+
+!--- OCEAN TREATMENT -----------------------------------------------------------
+  IF (prt_level>1) WRITE(lunout,*) 'Traitement de la glace oceanique'
+
+! Input SIC file selection
+! Open file only to test if available
+  IF ( NF90_OPEN(TRIM(famipsic),NF90_NOWRITE,nid)==NF90_NOERR ) THEN
+     icefile=TRIM(famipsic)
+     varname='sicbcs'
+  ELSE IF( NF90_OPEN(TRIM(fcpldsic),NF90_NOWRITE,nid)==NF90_NOERR ) THEN
+     icefile=TRIM(fcpldsic)
+     varname='SIICECOV'
+  ELSE IF ( NF90_OPEN(TRIM(fhistsic),NF90_NOWRITE,nid)==NF90_NOERR ) THEN
+     icefile=TRIM(fhistsic)
+     varname='pourc_sic'
+  ELSE
+     WRITE(lunout,*) 'ERROR! No sea-ice input file was found.'
+     WRITE(lunout,*) 'One of following files must be availible : ',trim(famipsic),', ',trim(fcpldsic),', ',trim(fhistsic)
+     CALL abort_gcm('limit_netcdf','No sea-ice file was found',1)
+  END IF
+  ierr=NF90_CLOSE(nid)
+  IF (prt_level>=0) WRITE(lunout,*)'Pour la glace de mer a ete choisi le fichier '//TRIM(icefile)
+
+  CALL get_2Dfield(icefile,varname, 'SIC',interbar,ndays,phy_ice,flag=oldice)
+
+  ALLOCATE(pctsrf_t(klon,nbsrf,ndays))
+  DO k=1,ndays
+     fi_ice=phy_ice(:,k)
+     WHERE(fi_ice>=1.0  ) fi_ice=1.0
+     WHERE(fi_ice<EPSFRA) fi_ice=0.0
+     pctsrf_t(:,is_ter,k)=pctsrf(:,is_ter)       ! land soil
+     pctsrf_t(:,is_lic,k)=pctsrf(:,is_lic)       ! land ice
+     IF (icefile==trim(fcpldsic)) THEN           ! SIC=pICE*(1-LIC-TER)
+        pctsrf_t(:,is_sic,k)=fi_ice(:)*(1.-pctsrf(:,is_lic)-pctsrf(:,is_ter))
+     ELSE IF (icefile==trim(fhistsic)) THEN      ! SIC=pICE
+        pctsrf_t(:,is_sic,k)=fi_ice(:)
+     ELSE ! icefile==famipsic                    ! SIC=pICE-LIC
+        pctsrf_t(:,is_sic,k)=fi_ice-pctsrf_t(:,is_lic,k)
+     END IF
+     WHERE(pctsrf_t(:,is_sic,k)<=0) pctsrf_t(:,is_sic,k)=0.
+     WHERE(1.0-zmasq<EPSFRA)
+        pctsrf_t(:,is_sic,k)=0.0
+        pctsrf_t(:,is_oce,k)=0.0
+     ELSEWHERE
+        WHERE(pctsrf_t(:,is_sic,k)>=1.0-zmasq)
+           pctsrf_t(:,is_sic,k)=1.0-zmasq
+           pctsrf_t(:,is_oce,k)=0.0
+        ELSEWHERE
+           pctsrf_t(:,is_oce,k)=1.0-zmasq-pctsrf_t(:,is_sic,k)
+           WHERE(pctsrf_t(:,is_oce,k)<EPSFRA)
+              pctsrf_t(:,is_oce,k)=0.0
+              pctsrf_t(:,is_sic,k)=1.0-zmasq
+           END WHERE
+        END WHERE
+     END WHERE
+     nbad=COUNT(pctsrf_t(:,is_oce,k)<0.0)
+     IF(nbad>0) WRITE(lunout,*) 'pb sous maille pour nb point = ',nbad
+     nbad=COUNT(abs(sum(pctsrf_t(:,:,k),dim=2)-1.0)>EPSFRA)
+     IF(nbad>0) WRITE(lunout,*) 'pb sous surface pour nb points = ',nbad
+  END DO
+  DEALLOCATE(phy_ice)
+
+!--- SST TREATMENT -------------------------------------------------------------
+  IF (prt_level>1) WRITE(lunout,*) 'Traitement de la sst'
+
+! Input SST file selection
+! Open file only to test if available
+  IF ( NF90_OPEN(TRIM(famipsst),NF90_NOWRITE,nid)==NF90_NOERR ) THEN
+     sstfile=TRIM(famipsst)
+     varname='tosbcs'
+  ELSE IF ( NF90_OPEN(TRIM(fcpldsst),NF90_NOWRITE,nid)==NF90_NOERR ) THEN
+     sstfile=TRIM(fcpldsst)
+     varname='SISUTESW'
+  ELSE IF ( NF90_OPEN(TRIM(fhistsst),NF90_NOWRITE,nid)==NF90_NOERR ) THEN
+     sstfile=TRIM(fhistsst)
+     varname='tsol_oce'
+  ELSE
+     WRITE(lunout,*) 'ERROR! No sst input file was found.'
+     WRITE(lunout,*) 'One of following files must be availible : ',trim(famipsst),trim(fcpldsst),trim(fhistsst)
+     CALL abort_gcm('limit_netcdf','No sst file was found',1)
+  END IF
+  ierr=NF90_CLOSE(nid)
+  IF (prt_level>=0) WRITE(lunout,*)'Pour la temperature de mer a ete choisi un fichier '//TRIM(sstfile)
+
+  CALL get_2Dfield(sstfile,varname,'SST',interbar,ndays,phy_sst,flag=extrap)
+
+!--- ALBEDO TREATMENT ----------------------------------------------------------
+  IF (prt_level>1) WRITE(lunout,*) 'Traitement de l albedo'
+  varname='ALBEDO'
+  CALL get_2Dfield(falbe,varname,'ALB',interbar,ndays,phy_alb)
+
+!--- REFERENCE GROUND HEAT FLUX TREATMENT --------------------------------------
+  ALLOCATE(phy_bil(klon,ndays)); phy_bil=0.0
+
+!--- OUTPUT FILE WRITING -------------------------------------------------------
+  IF (prt_level>5) WRITE(lunout,*) 'Ecriture du fichier limit : debut'
+
+  !--- File creation
+  ierr=NF90_CREATE("limit.nc",NF90_CLOBBER,nid)
+  ierr=NF90_PUT_ATT(nid,NF90_GLOBAL,"title","Fichier conditions aux limites")
+
+  !--- Dimensions creation
+  ierr=NF90_DEF_DIM(nid,"points_physiques",klon,ndim)
+  ierr=NF90_DEF_DIM(nid,"time",NF90_UNLIMITED,ntim)
+
+  dims=(/ndim,ntim/)
+
+  !--- Variables creation
+  ierr=NF90_DEF_VAR(nid,"TEMPS",NF90_FORMAT,(/ntim/),id_tim)
+  ierr=NF90_DEF_VAR(nid,"FOCE", NF90_FORMAT,dims,id_FOCE)
+  ierr=NF90_DEF_VAR(nid,"FSIC", NF90_FORMAT,dims,id_FSIC)
+  ierr=NF90_DEF_VAR(nid,"FTER", NF90_FORMAT,dims,id_FTER)
+  ierr=NF90_DEF_VAR(nid,"FLIC", NF90_FORMAT,dims,id_FLIC)
+  ierr=NF90_DEF_VAR(nid,"SST",  NF90_FORMAT,dims,id_SST)
+  ierr=NF90_DEF_VAR(nid,"BILS", NF90_FORMAT,dims,id_BILS)
+  ierr=NF90_DEF_VAR(nid,"ALB",  NF90_FORMAT,dims,id_ALB)
+  ierr=NF90_DEF_VAR(nid,"RUG",  NF90_FORMAT,dims,id_RUG)
+
+  !--- Attributes creation
+  ierr=NF90_PUT_ATT(nid,id_tim, "title","Jour dans l annee")
+  ierr=NF90_PUT_ATT(nid,id_FOCE,"title","Fraction ocean")
+  ierr=NF90_PUT_ATT(nid,id_FSIC,"title","Fraction glace de mer")
+  ierr=NF90_PUT_ATT(nid,id_FTER,"title","Fraction terre")
+  ierr=NF90_PUT_ATT(nid,id_FLIC,"title","Fraction land ice")
+  ierr=NF90_PUT_ATT(nid,id_SST ,"title","Temperature superficielle de la mer")
+  ierr=NF90_PUT_ATT(nid,id_BILS,"title","Reference flux de chaleur au sol")
+  ierr=NF90_PUT_ATT(nid,id_ALB, "title","Albedo a la surface")
+  ierr=NF90_PUT_ATT(nid,id_RUG, "title","Rugosite")
+
+  ierr=NF90_ENDDEF(nid)
+
+  !--- Variables saving
+  ierr=NF90_PUT_VAR(nid,id_tim,(/(REAL(k),k=1,ndays)/))
+  ierr=NF90_PUT_VAR(nid,id_FOCE,pctsrf_t(:,is_oce,:),(/1,1/),(/klon,ndays/))
+  ierr=NF90_PUT_VAR(nid,id_FSIC,pctsrf_t(:,is_sic,:),(/1,1/),(/klon,ndays/))
+  ierr=NF90_PUT_VAR(nid,id_FTER,pctsrf_t(:,is_ter,:),(/1,1/),(/klon,ndays/))
+  ierr=NF90_PUT_VAR(nid,id_FLIC,pctsrf_t(:,is_lic,:),(/1,1/),(/klon,ndays/))
+  ierr=NF90_PUT_VAR(nid,id_SST ,phy_sst(:,:),(/1,1/),(/klon,ndays/))
+  ierr=NF90_PUT_VAR(nid,id_BILS,phy_bil(:,:),(/1,1/),(/klon,ndays/))
+  ierr=NF90_PUT_VAR(nid,id_ALB ,phy_alb(:,:),(/1,1/),(/klon,ndays/))
+  ierr=NF90_PUT_VAR(nid,id_RUG ,phy_rug(:,:),(/1,1/),(/klon,ndays/))
+
+  ierr=NF90_CLOSE(nid)
+
+  IF (prt_level>5) WRITE(lunout,*) 'Ecriture du fichier limit : fin'
+
+  DEALLOCATE(pctsrf_t,phy_sst,phy_bil,phy_alb,phy_rug)
+
+
+!===============================================================================
+!
+  CONTAINS
+!
+!===============================================================================
+
+
+!-------------------------------------------------------------------------------
+!
+SUBROUTINE get_2Dfield(fnam, varname, mode, ibar, ndays, champo, flag, mask)
+!
+!-----------------------------------------------------------------------------
+! Comments:
+!   There are two assumptions concerning the NetCDF files, that are satisfied
+!   with files that are conforming NC convention:
+!     1) The last dimension of the variables used is the time record.
+!     2) Dimensional variables have the same names as corresponding dimensions.
+!-----------------------------------------------------------------------------
+  USE netcdf, ONLY: NF90_OPEN, NF90_INQ_VARID, NF90_INQUIRE_VARIABLE, &
+       NF90_CLOSE, NF90_INQ_DIMID, NF90_INQUIRE_DIMENSION, NF90_GET_VAR, &
+       NF90_GET_ATT
+  USE dimphy, ONLY : klon
+  USE phys_state_var_mod, ONLY : pctsrf
+  USE control_mod
+  use pchsp_95_m, only: pchsp_95
+  use pchfe_95_m, only: pchfe_95
+  use arth_m, only: arth
+
+  IMPLICIT NONE
+#include "dimensions.h"
+#include "paramet.h"
+#include "comgeom2.h"
+#include "indicesol.h"
+#include "iniprint.h"
+!-----------------------------------------------------------------------------
+! Arguments:
+  CHARACTER(LEN=*),  INTENT(IN)     :: fnam     ! NetCDF file name
+  CHARACTER(LEN=10), INTENT(IN)     :: varname  ! NetCDF variable name
+  CHARACTER(LEN=3),  INTENT(IN)     :: mode     ! RUG, SIC, SST or ALB
+  LOGICAL,           INTENT(IN)     :: ibar     ! interp on pressure levels
+  INTEGER,           INTENT(IN)     :: ndays    ! current year number of days
+  REAL,    POINTER,  DIMENSION(:, :) :: champo  ! output field = f(t)
+  LOGICAL, OPTIONAL, INTENT(IN)     :: flag     ! extrapol. (SST) old ice (SIC)
+  REAL,    OPTIONAL, DIMENSION(iim, jjp1), INTENT(IN) :: mask
+!------------------------------------------------------------------------------
+! Local variables:
+!--- NetCDF
+  INTEGER :: ncid, varid                  ! NetCDF identifiers
+  CHARACTER(LEN=30)               :: dnam       ! dimension name
+!--- dimensions
+  INTEGER,           DIMENSION(4) :: dids       ! NetCDF dimensions identifiers
+  REAL, ALLOCATABLE, DIMENSION(:) :: dlon_ini   ! initial longitudes vector
+  REAL, ALLOCATABLE, DIMENSION(:) :: dlat_ini   ! initial latitudes  vector
+  REAL, POINTER,     DIMENSION(:) :: dlon, dlat ! reordered lon/lat  vectors
+!--- fields
+  INTEGER :: imdep, jmdep, lmdep                ! dimensions of 'champ'
+  REAL, ALLOCATABLE, DIMENSION(:, :) :: champ   ! wanted field on initial grid
+  REAL, ALLOCATABLE, DIMENSION(:) :: yder, timeyear
+  REAL,              DIMENSION(iim, jjp1) :: champint   ! interpolated field
+  REAL, ALLOCATABLE, DIMENSION(:, :, :)    :: champtime
+  REAL, ALLOCATABLE, DIMENSION(:, :, :)    :: champan
+!--- input files
+  CHARACTER(LEN=20)                 :: cal_in   ! calendar
+  CHARACTER(LEN=20)                 :: unit_sic ! attribute unit in sea-ice file
+  INTEGER                           :: ndays_in ! number of days
+!--- misc
+  INTEGER :: i, j, k, l                         ! loop counters
+  REAL, ALLOCATABLE, DIMENSION(:, :) :: work     ! used for extrapolation
+  CHARACTER(LEN=25)                 :: title    ! for messages
+  LOGICAL                           :: extrp    ! flag for extrapolation
+  LOGICAL                           :: oldice   ! flag for old way ice computation 
+  REAL                              :: chmin, chmax
+  INTEGER ierr
+  integer n_extrap ! number of extrapolated points
+  logical skip
+
+!------------------------------------------------------------------------------
+!---Variables depending on keyword 'mode' -------------------------------------
+  NULLIFY(champo)
+
+  SELECT CASE(mode)
+  CASE('RUG'); title='Rugosite'
+  CASE('SIC'); title='Sea-ice'
+  CASE('SST'); title='SST'
+  CASE('ALB'); title='Albedo'
+  END SELECT
+  
+
+  extrp=.FALSE. 
+  oldice=.FALSE.
+  IF ( PRESENT(flag) ) THEN 
+    IF ( flag .AND. mode=='SST' ) extrp=.TRUE. 
+    IF ( flag .AND. mode=='SIC' ) oldice=.TRUE. 
+  END IF
+
+!--- GETTING SOME DIMENSIONAL VARIABLES FROM FILE -----------------------------
+  IF (prt_level>5) WRITE(lunout,*) ' Now reading file : ',fnam
+  ierr=NF90_OPEN(fnam, NF90_NOWRITE, ncid);             CALL ncerr(ierr, fnam)
+  ierr=NF90_INQ_VARID(ncid, trim(varname), varid);            CALL ncerr(ierr, fnam)
+  ierr=NF90_INQUIRE_VARIABLE(ncid, varid, dimids=dids); CALL ncerr(ierr, fnam)
+
+!--- Read unit for sea-ice variable only
+  IF (mode=='SIC') THEN
+     ierr=NF90_GET_ATT(ncid, varid, 'units', unit_sic)
+     IF(ierr/=NF90_NOERR) THEN
+        IF (prt_level>5) WRITE(lunout,*) 'No unit was given in sea-ice file. Take percentage as default value'
+        unit_sic='X'
+     ELSE
+        IF (prt_level>5) WRITE(lunout,*) ' Sea-ice cover has unit=',unit_sic
+     END IF
+  END IF
+
+!--- Longitude
+  ierr=NF90_INQUIRE_DIMENSION(ncid, dids(1), name=dnam, len=imdep)
+  CALL ncerr(ierr, fnam); ALLOCATE(dlon_ini(imdep), dlon(imdep))
+  ierr=NF90_INQ_VARID(ncid, dnam, varid);                CALL ncerr(ierr, fnam)
+  ierr=NF90_GET_VAR(ncid, varid, dlon_ini);              CALL ncerr(ierr, fnam)
+  IF (prt_level>5) WRITE(lunout, *) 'variable ', dnam, 'dimension ', imdep
+
+!--- Latitude
+  ierr=NF90_INQUIRE_DIMENSION(ncid, dids(2), name=dnam, len=jmdep)
+  CALL ncerr(ierr, fnam); ALLOCATE(dlat_ini(jmdep), dlat(jmdep))
+  ierr=NF90_INQ_VARID(ncid, dnam, varid);                CALL ncerr(ierr, fnam)
+  ierr=NF90_GET_VAR(ncid, varid, dlat_ini);              CALL ncerr(ierr, fnam)
+  IF (prt_level>5) WRITE(lunout, *) 'variable ', dnam, 'dimension ', jmdep
+
+!--- Time (variable is not needed - it is rebuilt - but calendar is)
+  ierr=NF90_INQUIRE_DIMENSION(ncid, dids(3), name=dnam, len=lmdep)
+  CALL ncerr(ierr, fnam); ALLOCATE(timeyear(lmdep))
+  ierr=NF90_INQ_VARID(ncid, dnam, varid);                CALL ncerr(ierr, fnam)
+  cal_in=' '
+  ierr=NF90_GET_ATT(ncid, varid, 'calendar', cal_in)
+  IF(ierr/=NF90_NOERR) THEN
+    SELECT CASE(mode)
+      CASE('RUG', 'ALB'); cal_in='360d'
+      CASE('SIC', 'SST'); cal_in='gregorian'
+    END SELECT
+    IF (prt_level>5) WRITE(lunout, *)'ATTENTION: variable "time" sans attribut "calendrier" ' &
+         // 'dans '//TRIM(fnam)//'. On choisit la valeur par defaut.'
+  END IF
+  IF (prt_level>5) WRITE(lunout, *) 'variable ', dnam, 'dimension ', lmdep, 'calendrier ', &
+       cal_in
+
+  
+!--- CONSTRUCTING THE INPUT TIME VECTOR FOR INTERPOLATION --------------------
+  !--- Determining input file number of days, depending on calendar
+  ndays_in=year_len(anneeref, cal_in)
+
+!--- Time vector reconstruction (time vector from file is not trusted)
+!--- If input records are not monthly, time sampling has to be constant !
+  timeyear=mid_months(anneeref, cal_in, lmdep)
+  IF (lmdep /= 12) WRITE(lunout,*) 'Note : les fichiers de ', TRIM(mode), &
+       ' ne comportent pas 12, mais ', lmdep, ' enregistrements.'
+
+!--- GETTING THE FIELD AND INTERPOLATING IT ----------------------------------
+  ALLOCATE(champ(imdep, jmdep), champtime(iim, jjp1, lmdep))
+  IF(extrp) ALLOCATE(work(imdep, jmdep))
+
+  IF (prt_level>5) WRITE(lunout, *)
+  IF (prt_level>5) WRITE(lunout,*)'LECTURE ET INTERPOLATION HORIZ. DE ', lmdep, ' CHAMPS.'
+  ierr=NF90_INQ_VARID(ncid, varname, varid);             CALL ncerr(ierr, fnam)
+  DO l=1, lmdep
+    ierr=NF90_GET_VAR(ncid, varid, champ, (/1, 1, l/), (/imdep, jmdep, 1/))
+    CALL ncerr(ierr, fnam)
+    CALL conf_dat2d(title, imdep, jmdep, dlon_ini, dlat_ini, dlon, dlat, &
+         champ, ibar)
+
+    IF (extrp) CALL extrapol(champ, imdep, jmdep, 999999., .TRUE., .TRUE., 2, &
+         work)
+
+    IF(ibar .AND. .NOT.oldice) THEN
+      IF(l==1 .AND. prt_level>5) THEN
+        WRITE(lunout, *) '-------------------------------------------------------------------------'
+        WRITE(lunout, *) 'Utilisation de l''interpolation barycentrique pour ',TRIM(title),' $$$'
+        WRITE(lunout, *) '-------------------------------------------------------------------------'
+      END IF
+      IF(mode=='RUG') champ=LOG(champ)
+      CALL inter_barxy(dlon, dlat(:jmdep-1), champ, rlonu(:iim),     &
+                         rlatv, champint)
+      IF(mode=='RUG') THEN
+        champint=EXP(champint)
+        WHERE(NINT(mask)/=1) champint=0.001
+      END IF
+    ELSE
+      SELECT CASE(mode)
+        CASE('RUG');       CALL rugosite(imdep, jmdep, dlon, dlat, champ,    &
+                                    iim, jjp1, rlonv, rlatu, champint, mask)
+        CASE('SIC');       CALL sea_ice (imdep, jmdep, dlon, dlat, champ,    &
+                                    iim, jjp1, rlonv, rlatu, champint)
+        CASE('SST', 'ALB'); CALL grille_m(imdep, jmdep, dlon, dlat, champ,    &
+                                    iim, jjp1, rlonv, rlatu, champint)
+      END SELECT
+    END IF
+    champtime(:, :, l)=champint
+  END DO
+  ierr=NF90_CLOSE(ncid);                                 CALL ncerr(ierr, fnam)
+
+  DEALLOCATE(dlon_ini, dlat_ini, dlon, dlat, champ)
+  IF(extrp) DEALLOCATE(work)
+
+!--- TIME INTERPOLATION ------------------------------------------------------
+  IF (prt_level>5) THEN
+     WRITE(lunout, *)
+     WRITE(lunout, *)'INTERPOLATION TEMPORELLE.'
+     WRITE(lunout, *)' Vecteur temps en entree: ', timeyear
+     WRITE(lunout, *)' Vecteur temps en sortie de 0 a ', ndays
+  END IF
+
+  ALLOCATE(yder(lmdep), champan(iip1, jjp1, ndays))
+  skip = .false.
+  n_extrap = 0
+  DO j=1, jjp1
+    DO i=1, iim
+      yder = pchsp_95(timeyear, champtime(i, j, :), ibeg=2, iend=2, &
+           vc_beg=0., vc_end=0.)
+      CALL pchfe_95(timeyear, champtime(i, j, :), yder, skip, &
+           arth(0., real(ndays_in) / ndays, ndays), champan(i, j, :), ierr)
+      if (ierr < 0) stop 1
+      n_extrap = n_extrap + ierr
+    END DO
+  END DO
+  if (n_extrap /= 0) then
+     WRITE(lunout,*) "get_2Dfield pchfe_95: n_extrap = ", n_extrap
+  end if
+  champan(iip1, :, :)=champan(1, :, :)
+  DEALLOCATE(yder, champtime, timeyear)
+
+!--- Checking the result
+  DO j=1, jjp1
+    CALL minmax(iip1, champan(1, j, 10), chmin, chmax)
+    IF (prt_level>5) WRITE(lunout, *)' ',TRIM(title),' au temps 10 ', chmin, chmax, j
+  END DO
+
+!--- SPECIAL FILTER FOR SST: SST>271.38 --------------------------------------
+  IF(mode=='SST') THEN
+    IF (prt_level>5) WRITE(lunout, *) 'Filtrage de la SST: SST >= 271.38'
+    WHERE(champan<271.38) champan=271.38
+  END IF
+
+!--- SPECIAL FILTER FOR SIC: 0.0<SIC<1.0 -------------------------------------
+  IF(mode=='SIC') THEN
+    IF (prt_level>5) WRITE(lunout, *) 'Filtrage de la SIC: 0.0 < Sea-ice < 1.0'
+
+    IF (unit_sic=='1') THEN
+       ! Nothing to be done for sea-ice field is already in fraction of 1
+       ! This is the case for sea-ice in file cpl_atm_sic.nc
+       IF (prt_level>5) WRITE(lunout,*) 'Sea-ice field already in fraction of 1'
+    ELSE
+       ! Convert sea ice from percentage to fraction of 1
+       IF (prt_level>5) WRITE(lunout,*) 'Transformt sea-ice field from percentage to fraction of 1.' 
+       champan(:, :, :)=champan(:, :, :)/100.
+    END IF
+
+    champan(iip1, :, :)=champan(1, :, :)
+    WHERE(champan>1.0) champan=1.0
+    WHERE(champan<0.0) champan=0.0
+ END IF
+
+!--- DYNAMICAL TO PHYSICAL GRID ----------------------------------------------
+  ALLOCATE(champo(klon, ndays))
+  DO k=1, ndays
+    CALL gr_dyn_fi(1, iip1, jjp1, klon, champan(1, 1, k), champo(1, k))
+  END DO
+  DEALLOCATE(champan)
+
+END SUBROUTINE get_2Dfield
+!
+!-------------------------------------------------------------------------------
+
+
+
+!-------------------------------------------------------------------------------
+!
+FUNCTION year_len(y,cal_in)
+!
+!-------------------------------------------------------------------------------
+  USE ioipsl, ONLY : ioget_calendar,ioconf_calendar,lock_calendar,ioget_year_len
+  IMPLICIT NONE
+!-------------------------------------------------------------------------------
+! Arguments:
+  INTEGER                       :: year_len
+  INTEGER,           INTENT(IN) :: y
+  CHARACTER(LEN=*),  INTENT(IN) :: cal_in
+!-------------------------------------------------------------------------------
+! Local variables:
+  CHARACTER(LEN=20)             :: cal_out              ! calendar (for outputs)
+!-------------------------------------------------------------------------------
+!--- Getting the input calendar to reset at the end of the function
+  CALL ioget_calendar(cal_out)
+
+!--- Unlocking calendar and setting it to wanted one
+  CALL lock_calendar(.FALSE.); CALL ioconf_calendar(TRIM(cal_in))
+
+!--- Getting the number of days in this year
+  year_len=ioget_year_len(y)
+
+!--- Back to original calendar
+  CALL lock_calendar(.FALSE.); CALL ioconf_calendar(TRIM(cal_out))
+
+END FUNCTION year_len
+!
+!-------------------------------------------------------------------------------
+
+
+!-------------------------------------------------------------------------------
+!
+FUNCTION mid_months(y,cal_in,nm)
+!
+!-------------------------------------------------------------------------------
+  USE ioipsl, ONLY : ioget_calendar,ioconf_calendar,lock_calendar,ioget_mon_len
+  IMPLICIT NONE
+!-------------------------------------------------------------------------------
+! Arguments:
+  INTEGER,                INTENT(IN) :: y               ! year
+  CHARACTER(LEN=*),       INTENT(IN) :: cal_in          ! calendar
+  INTEGER,                INTENT(IN) :: nm              ! months/year number
+  REAL,    DIMENSION(nm)             :: mid_months      ! mid-month times
+!-------------------------------------------------------------------------------
+! Local variables:
+  CHARACTER(LEN=99)                  :: mess            ! error message
+  CHARACTER(LEN=20)                  :: cal_out         ! calendar (for outputs)
+  INTEGER, DIMENSION(nm)             :: mnth            ! months lengths (days)
+  INTEGER                            :: m               ! months counter
+  INTEGER                            :: nd              ! number of days
+!-------------------------------------------------------------------------------
+  nd=year_len(y,cal_in)
+
+  IF(nm==12) THEN
+
+  !--- Getting the input calendar to reset at the end of the function
+    CALL ioget_calendar(cal_out)
+
+  !--- Unlocking calendar and setting it to wanted one
+    CALL lock_calendar(.FALSE.); CALL ioconf_calendar(TRIM(cal_in))
+
+  !--- Getting the length of each month
+    DO m=1,nm; mnth(m)=ioget_mon_len(y,m); END DO
+
+  !--- Back to original calendar
+    CALL lock_calendar(.FALSE.); CALL ioconf_calendar(TRIM(cal_out))
+
+  ELSE IF(MODULO(nd,nm)/=0) THEN
+    WRITE(mess,'(a,i3,a,i3,a)')'Unconsistent calendar: ',nd,' days/year, but ',&
+      nm,' months/year. Months number should divide days number.'
+    CALL abort_gcm('mid_months',TRIM(mess),1)
+
+  ELSE
+    mnth=(/(m,m=1,nm,nd/nm)/)
+  END IF
+
+!--- Mid-months times
+  mid_months(1)=0.5*REAL(mnth(1))
+  DO k=2,nm
+    mid_months(k)=mid_months(k-1)+0.5*REAL(mnth(k-1)+mnth(k))
+  END DO
+
+END FUNCTION mid_months
+!
+!-------------------------------------------------------------------------------
+
+
+!-------------------------------------------------------------------------------
+!
+SUBROUTINE ncerr(ncres,fnam)
+!
+!-------------------------------------------------------------------------------
+! Purpose: NetCDF errors handling.
+!-------------------------------------------------------------------------------
+  USE netcdf, ONLY : NF90_NOERR, NF90_STRERROR
+  IMPLICIT NONE
+!-------------------------------------------------------------------------------
+! Arguments:
+  INTEGER,          INTENT(IN) :: ncres
+  CHARACTER(LEN=*), INTENT(IN) :: fnam
+!-------------------------------------------------------------------------------
+#include "iniprint.h"
+  IF(ncres/=NF90_NOERR) THEN
+    WRITE(lunout,*)'Problem with file '//TRIM(fnam)//' in routine limit_netcdf.'
+    CALL abort_gcm('limit_netcdf',NF90_STRERROR(ncres),1)
+  END IF
+
+END SUBROUTINE ncerr
+!
+!-------------------------------------------------------------------------------
+
+#endif
+! of #ifdef CPP_EARTH
+
+END SUBROUTINE limit_netcdf
Index: LMDZ5/branches/testing/libf/phylmd/mod_grid_phy_lmdz.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/mod_grid_phy_lmdz.F90	(revision 1669)
+++ LMDZ5/branches/testing/libf/phylmd/mod_grid_phy_lmdz.F90	(revision 1707)
@@ -1,6 +1,11 @@
 !
-!$Header$
+!$Id $
 !
 MODULE mod_grid_phy_lmdz
+
+  PUBLIC
+  PRIVATE :: grid1dTo2d_glo_igen, grid1dTo2d_glo_rgen, grid1dTo2d_glo_lgen, &
+             grid2dTo1d_glo_igen, grid2dTo1d_glo_rgen, grid2dTo1d_glo_lgen
+  
   INTEGER,SAVE :: nbp_lon  ! == iim
   INTEGER,SAVE :: nbp_lat  ! == jjmp1
@@ -271,10 +276,10 @@
   END SUBROUTINE grid2dTo1d_glo_l3
 
-END MODULE mod_grid_phy_lmdz
-
-
+!---------------------------------------------------------------- 
+!  Generic (private) fonctions
+!---------------------------------------------------------------- 
   
   SUBROUTINE grid1dTo2d_glo_igen(VarIn,VarOut,dimsize)
-    USE mod_grid_phy_lmdz
+
     IMPLICIT NONE
 
@@ -311,5 +316,5 @@
 
   SUBROUTINE grid1dTo2d_glo_rgen(VarIn,VarOut,dimsize)
-    USE mod_grid_phy_lmdz
+
     IMPLICIT NONE
 
@@ -345,5 +350,5 @@
 
   SUBROUTINE grid1dTo2d_glo_lgen(VarIn,VarOut,dimsize)
-    USE mod_grid_phy_lmdz
+
     IMPLICIT NONE
     
@@ -379,5 +384,5 @@
   
   SUBROUTINE grid2dTo1d_glo_igen(VarIn,VarOut,dimsize)
-    USE mod_grid_phy_lmdz
+
     IMPLICIT NONE
 
@@ -402,5 +407,5 @@
   
   SUBROUTINE grid2dTo1d_glo_rgen(VarIn,VarOut,dimsize)
-    USE mod_grid_phy_lmdz
+
     IMPLICIT NONE
 
@@ -425,5 +430,5 @@
     
   SUBROUTINE grid2dTo1d_glo_lgen(VarIn,VarOut,dimsize)
-    USE mod_grid_phy_lmdz
+
     IMPLICIT NONE
 
@@ -446,2 +451,4 @@
     
   END SUBROUTINE grid2dTo1d_glo_lgen   
+
+END MODULE mod_grid_phy_lmdz
Index: LMDZ5/branches/testing/libf/phylmd/pbl_surface_mod.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/pbl_surface_mod.F90	(revision 1669)
+++ LMDZ5/branches/testing/libf/phylmd/pbl_surface_mod.F90	(revision 1707)
@@ -172,5 +172,5 @@
        t,         q,         u,        v,             &
        pplay,     paprs,     pctsrf,                  &
-       ts,        alb1,      alb2,     u10m,   v10m,  &
+       ts,        alb1,      alb2,ustar, u10m, v10m,  &
        lwdown_m,  cdragh,    cdragm,   zu1,    zv1,   &
        alb1_m,    alb2_m,    zxsens,   zxevap,        &
@@ -181,5 +181,5 @@
        s_capCL,   s_oliqCL,  s_cteiCL, s_pblT,        &
        s_therm,   s_trmb1,   s_trmb2,  s_trmb3,       &
-       zxrugs,    zu10m,     zv10m,    fder_print,    &
+       zxrugs,zustar,zu10m,  zv10m,    fder_print,    &
        zxqsurf,   rh2m,      zxfluxu,  zxfluxv,       &
        rugos_d,   agesno_d,  sollw,    solsw,         &
@@ -288,4 +288,5 @@
     REAL, DIMENSION(klon, nbsrf), INTENT(INOUT)     :: alb1    ! albedo in visible SW interval
     REAL, DIMENSION(klon, nbsrf), INTENT(INOUT)     :: alb2    ! albedo in near infra-red SW interval
+    REAL, DIMENSION(klon, nbsrf), INTENT(INOUT)     :: ustar   ! u* (m/s)
     REAL, DIMENSION(klon, nbsrf), INTENT(INOUT)     :: u10m    ! u speed at 10m
     REAL, DIMENSION(klon, nbsrf), INTENT(INOUT)     :: v10m    ! v speed at 10m
@@ -330,4 +331,5 @@
     REAL, DIMENSION(klon),        INTENT(OUT)       :: s_trmb3    ! point Omega, mean for each grid point
     REAL, DIMENSION(klon),        INTENT(OUT)       :: zxrugs     ! rugosity at surface (m), mean for each grid point
+    REAL, DIMENSION(klon),        INTENT(OUT)       :: zustar     ! u*
     REAL, DIMENSION(klon),        INTENT(OUT)       :: zu10m      ! u speed at 10m, mean for each grid point
     REAL, DIMENSION(klon),        INTENT(OUT)       :: zv10m      ! v speed at 10m, mean for each grid point
@@ -1019,7 +1021,7 @@
        t2m(:,nsrf)    = 0.
        q2m(:,nsrf)    = 0.
+       ustar(:,nsrf)   = 0.
        u10m(:,nsrf)   = 0.
        v10m(:,nsrf)   = 0.
-
        pblh(:,nsrf)   = 0.        ! Hauteur de couche limite
        plcl(:,nsrf)   = 0.        ! Niveau de condensation de la CLA
@@ -1069,6 +1071,8 @@
           
           ! u10m, v10m : composantes du vent a 10m sans spirale de Ekman
+          ustar(i,nsrf)=yustar(j)
           u10m(i,nsrf)=(yu10m(j) * uzon(j))/SQRT(uzon(j)**2+vmer(j)**2)
           v10m(i,nsrf)=(yu10m(j) * vmer(j))/SQRT(uzon(j)**2+vmer(j)**2)
+
        END DO
 
@@ -1150,5 +1154,5 @@
     zxtsol(:) = 0.0  ; zxfluxlat(:) = 0.0
     zt2m(:) = 0.0    ; zq2m(:) = 0.0 
-    zu10m(:) = 0.0   ; zv10m(:) = 0.0
+    zustar(:)=0.0 ; zu10m(:) = 0.0   ; zv10m(:) = 0.0
     s_pblh(:) = 0.0  ; s_plcl(:) = 0.0 
     s_capCL(:) = 0.0 ; s_oliqCL(:) = 0.0
@@ -1172,4 +1176,5 @@
           zt2m(i)  = zt2m(i)  + t2m(i,nsrf)  * pctsrf(i,nsrf)
           zq2m(i)  = zq2m(i)  + q2m(i,nsrf)  * pctsrf(i,nsrf)
+          zustar(i) = zustar(i) + ustar(i,nsrf) * pctsrf(i,nsrf)
           zu10m(i) = zu10m(i) + u10m(i,nsrf) * pctsrf(i,nsrf)
           zv10m(i) = zv10m(i) + v10m(i,nsrf) * pctsrf(i,nsrf)
@@ -1305,5 +1310,5 @@
 !****************************************************************************************
 ! 
-  SUBROUTINE pbl_surface_newfrac(itime, pctsrf_new, pctsrf_old, tsurf, alb1, alb2, u10m, v10m, tke)
+  SUBROUTINE pbl_surface_newfrac(itime, pctsrf_new, pctsrf_old, tsurf, alb1, alb2, ustar, u10m, v10m, tke)
 
     ! Give default values where new fraction has appread
@@ -1323,5 +1328,5 @@
     REAL, DIMENSION(klon,nbsrf), INTENT(INOUT)        :: tsurf
     REAL, DIMENSION(klon,nbsrf), INTENT(INOUT)        :: alb1, alb2
-    REAL, DIMENSION(klon,nbsrf), INTENT(INOUT)        :: u10m, v10m
+    REAL, DIMENSION(klon,nbsrf), INTENT(INOUT)        :: ustar,u10m, v10m
     REAL, DIMENSION(klon,klev+1,nbsrf), INTENT(INOUT) :: tke
 
@@ -1369,4 +1374,5 @@
                 alb1(i,nsrf)  = alb1(i,nsrf_comp1)
                 alb2(i,nsrf)  = alb2(i,nsrf_comp1)
+                ustar(i,nsrf)  = ustar(i,nsrf_comp1)
                 u10m(i,nsrf)  = u10m(i,nsrf_comp1)
                 v10m(i,nsrf)  = v10m(i,nsrf_comp1)
@@ -1383,4 +1389,5 @@
                 alb1(i,nsrf)  = alb1(i,nsrf_comp2) *pctsrf_old(i,nsrf_comp2) + alb1(i,nsrf_comp3) *pctsrf_old(i,nsrf_comp3)
                 alb2(i,nsrf)  = alb2(i,nsrf_comp2) *pctsrf_old(i,nsrf_comp2) + alb2(i,nsrf_comp3) *pctsrf_old(i,nsrf_comp3)
+                ustar(i,nsrf)  = ustar(i,nsrf_comp2) *pctsrf_old(i,nsrf_comp2) + ustar(i,nsrf_comp3) *pctsrf_old(i,nsrf_comp3)
                 u10m(i,nsrf)  = u10m(i,nsrf_comp2) *pctsrf_old(i,nsrf_comp2) + u10m(i,nsrf_comp3) *pctsrf_old(i,nsrf_comp3)
                 v10m(i,nsrf)  = v10m(i,nsrf_comp2) *pctsrf_old(i,nsrf_comp2) + v10m(i,nsrf_comp3) *pctsrf_old(i,nsrf_comp3)
Index: LMDZ5/branches/testing/libf/phylmd/phyaqua.F
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/phyaqua.F	(revision 1669)
+++ LMDZ5/branches/testing/libf/phylmd/phyaqua.F	(revision 1707)
@@ -16,12 +16,11 @@
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
-      use comgeomphy
-      use dimphy
+      use comgeomphy, only : rlatd,rlond
+      use dimphy, only : klon
       use surface_data, only : type_ocean,ok_veget
       use pbl_surface_mod, only : pbl_surface_init
       USE fonte_neige_mod, only : fonte_neige_init
       use phys_state_var_mod
-      use control_mod
-
+      use control_mod, only : dayref,nday,iphysiq
 
       USE IOIPSL 
@@ -35,8 +34,10 @@
 #include "dimsoil.h"
 #include "indicesol.h"
-
-      integer nlon,iflag_phys
+#include "temps.h"
+
+      integer,intent(in) :: nlon,iflag_phys
 cIM ajout latfi, lonfi
-      REAL, DIMENSION (nlon) :: lonfi, latfi
+      real,intent(in) :: lonfi(nlon),latfi(nlon)
+
       INTEGER type_profil,type_aqua
 
@@ -71,6 +72,4 @@
 !      integer demih_pas
 
-      integer day_ini
-
       CHARACTER*80 ans,file_forctl, file_fordat, file_start
       character*100 file,var
@@ -88,5 +87,5 @@
       REAL phy_flic(nlon,360)
 
-      integer, save::  read_climoz ! read ozone climatology
+      integer, save::  read_climoz=0 ! read ozone climatology
 
 
@@ -131,7 +130,10 @@
       type_aqua=iflag_phys/100
       type_profil=iflag_phys-type_aqua*100
-      print*,'type_aqua, type_profil',type_aqua, type_profil
-
-      if (klon.ne.nlon) stop'probleme de dimensions dans iniaqua'
+      print*,'iniaqua:type_aqua, type_profil',type_aqua, type_profil
+
+      if (klon.ne.nlon) then
+        write(*,*)"iniaqua: klon=",klon," nlon=",nlon
+        stop'probleme de dimensions dans iniaqua'
+      endif
       call phys_state_var_init(read_climoz)
 
@@ -154,4 +156,5 @@
 
          day_ini=dayref
+         day_end=day_ini+nday
          airefi=1.
          zcufi=1.
@@ -171,5 +174,5 @@
       radsol=0.
       qsol_f=10.
-      CALL getin('albedo',albedo)
+!      CALL getin('albedo',albedo) ! albedo is set below, depending on type_aqua
       alb_ocean=.true.
       CALL getin('alb_ocean',alb_ocean)
@@ -180,4 +183,7 @@
       qsol(:)    = qsol_f
       rugsrel = 0.0    ! (rugsrel = rugoro)
+      rugoro = 0.0
+      u_ancien = 0.0
+      v_ancien = 0.0
       agesno  = 50.0
 ! Relief plat
@@ -308,5 +314,5 @@
      .     evap, frugs, agesno, tsoil)
 
-        print*,'avant phyredem dans iniaqua'
+        print*,'iniaqua: before phyredem'
 
       falb1=albedo
@@ -329,5 +335,5 @@
       CALL phyredem ("startphy.nc")
 
-        print*,'apres phyredem'
+        print*,'iniaqua: after phyredem'
       call phys_state_var_end
 
@@ -450,24 +456,32 @@
       RETURN
       END
+
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
       subroutine writelim
      s   (klon,phy_nat,phy_alb,phy_sst,phy_bil,phy_rug,phy_ice,
      s    phy_fter,phy_foce,phy_flic,phy_fsic)
 c
+      use mod_phys_lmdz_para, only: is_mpi_root,is_omp_root
+      use mod_grid_phy_lmdz, only : klon_glo
+      use mod_phys_lmdz_transfert_para, only : gather
 !#include "dimensions.h"
 !#include "dimphy.h"
 #include "netcdf.inc"
  
-      integer klon
-      REAL phy_nat(klon,360)
-      REAL phy_alb(klon,360)
-      REAL phy_sst(klon,360)
-      REAL phy_bil(klon,360)
-      REAL phy_rug(klon,360)
-      REAL phy_ice(klon,360)
-      REAL phy_fter(klon,360)
-      REAL phy_foce(klon,360)
-      REAL phy_flic(klon,360)
-      REAL phy_fsic(klon,360)
- 
+      integer,intent(in) :: klon
+      real,intent(in) :: phy_nat(klon,360)
+      real,intent(in) :: phy_alb(klon,360)
+      real,intent(in) :: phy_sst(klon,360)
+      real,intent(in) :: phy_bil(klon,360)
+      real,intent(in) :: phy_rug(klon,360)
+      real,intent(in) :: phy_ice(klon,360)
+      real,intent(in) :: phy_fter(klon,360)
+      real,intent(in) :: phy_foce(klon,360)
+      real,intent(in) :: phy_flic(klon,360)
+      real,intent(in) :: phy_fsic(klon,360)
+
+      real :: phy_glo(klon_glo,360) ! temporary variable, to store phy_***(:)
+                                    ! on the whole physics grid 
       INTEGER ierr
       INTEGER dimfirst(3)
@@ -480,93 +494,194 @@
       INTEGER id_FTER,id_FOCE,id_FSIC,id_FLIC
  
-      PRINT*, 'Ecriture du fichier limit'
-c
-      ierr = NF_CREATE ("limit.nc", NF_CLOBBER, nid)
-c
-      ierr = NF_PUT_ATT_TEXT (nid, NF_GLOBAL, "title", 30,
+      if (is_mpi_root.and.is_omp_root) then
+      
+        PRINT*, 'writelim: Ecriture du fichier limit'
+c
+        ierr = NF_CREATE ("limit.nc", NF_CLOBBER, nid)
+c
+        ierr = NF_PUT_ATT_TEXT (nid, NF_GLOBAL, "title", 30,
      .                       "Fichier conditions aux limites")
-      ierr = NF_DEF_DIM (nid, "points_physiques", klon, ndim)
-      ierr = NF_DEF_DIM (nid, "time", NF_UNLIMITED, ntim)
-c
-      dims(1) = ndim
-      dims(2) = ntim
+!!        ierr = NF_DEF_DIM (nid, "points_physiques", klon, ndim)
+        ierr = NF_DEF_DIM (nid, "points_physiques", klon_glo, ndim)
+        ierr = NF_DEF_DIM (nid, "time", NF_UNLIMITED, ntim)
+c
+        dims(1) = ndim
+        dims(2) = ntim
 c
 ccc      ierr = NF_DEF_VAR (nid, "TEMPS", NF_DOUBLE, 1,ntim, id_tim)
-      ierr = NF_DEF_VAR (nid, "TEMPS", NF_FLOAT, 1,ntim, id_tim)
-      ierr = NF_PUT_ATT_TEXT (nid, id_tim, "title", 17,
+        ierr = NF_DEF_VAR (nid, "TEMPS", NF_FLOAT, 1,ntim, id_tim)
+        ierr = NF_PUT_ATT_TEXT (nid, id_tim, "title", 17,
      .                        "Jour dans l annee")
 ccc      ierr = NF_DEF_VAR (nid, "NAT", NF_DOUBLE, 2,dims, id_NAT)
-      ierr = NF_DEF_VAR (nid, "NAT", NF_FLOAT, 2,dims, id_NAT)
-      ierr = NF_PUT_ATT_TEXT (nid, id_NAT, "title", 23,
+        ierr = NF_DEF_VAR (nid, "NAT", NF_FLOAT, 2,dims, id_NAT)
+        ierr = NF_PUT_ATT_TEXT (nid, id_NAT, "title", 23,
      .                        "Nature du sol (0,1,2,3)")
 ccc      ierr = NF_DEF_VAR (nid, "SST", NF_DOUBLE, 2,dims, id_SST)
-      ierr = NF_DEF_VAR (nid, "SST", NF_FLOAT, 2,dims, id_SST)
-      ierr = NF_PUT_ATT_TEXT (nid, id_SST, "title", 35,
+        ierr = NF_DEF_VAR (nid, "SST", NF_FLOAT, 2,dims, id_SST)
+        ierr = NF_PUT_ATT_TEXT (nid, id_SST, "title", 35,
      .                        "Temperature superficielle de la mer")
 ccc      ierr = NF_DEF_VAR (nid, "BILS", NF_DOUBLE, 2,dims, id_BILS)
-      ierr = NF_DEF_VAR (nid, "BILS", NF_FLOAT, 2,dims, id_BILS)
-      ierr = NF_PUT_ATT_TEXT (nid, id_BILS, "title", 32,
+        ierr = NF_DEF_VAR (nid, "BILS", NF_FLOAT, 2,dims, id_BILS)
+        ierr = NF_PUT_ATT_TEXT (nid, id_BILS, "title", 32,
      .                        "Reference flux de chaleur au sol")
 ccc      ierr = NF_DEF_VAR (nid, "ALB", NF_DOUBLE, 2,dims, id_ALB)
-      ierr = NF_DEF_VAR (nid, "ALB", NF_FLOAT, 2,dims, id_ALB)
-      ierr = NF_PUT_ATT_TEXT (nid, id_ALB, "title", 19,
+        ierr = NF_DEF_VAR (nid, "ALB", NF_FLOAT, 2,dims, id_ALB)
+        ierr = NF_PUT_ATT_TEXT (nid, id_ALB, "title", 19,
      .                        "Albedo a la surface")
 ccc      ierr = NF_DEF_VAR (nid, "RUG", NF_DOUBLE, 2,dims, id_RUG)
-      ierr = NF_DEF_VAR (nid, "RUG", NF_FLOAT, 2,dims, id_RUG)
-      ierr = NF_PUT_ATT_TEXT (nid, id_RUG, "title", 8,
+        ierr = NF_DEF_VAR (nid, "RUG", NF_FLOAT, 2,dims, id_RUG)
+        ierr = NF_PUT_ATT_TEXT (nid, id_RUG, "title", 8,
      .                        "Rugosite")
 
-      ierr = NF_DEF_VAR (nid, "FTER", NF_FLOAT, 2,dims, id_FTER)
-      ierr = NF_PUT_ATT_TEXT (nid, id_FTER, "title", 8,"Frac. Terre")
-      ierr = NF_DEF_VAR (nid, "FOCE", NF_FLOAT, 2,dims, id_FOCE)
-      ierr = NF_PUT_ATT_TEXT (nid, id_FOCE, "title", 8,"Frac. Terre")
-      ierr = NF_DEF_VAR (nid, "FSIC", NF_FLOAT, 2,dims, id_FSIC)
-      ierr = NF_PUT_ATT_TEXT (nid, id_FSIC, "title", 8,"Frac. Terre")
-      ierr = NF_DEF_VAR (nid, "FLIC", NF_FLOAT, 2,dims, id_FLIC)
-      ierr = NF_PUT_ATT_TEXT (nid, id_FLIC, "title", 8,"Frac. Terre")
-c
-      ierr = NF_ENDDEF(nid)
-c
-      DO k = 1, 360
-c
-      debut(1) = 1
-      debut(2) = k
-      epais(1) = klon
-      epais(2) = 1
-c
-      print*,'Instant ',k
-#ifdef NC_DOUBLE
-      print*,'NC DOUBLE'
-      ierr = NF_PUT_VAR1_DOUBLE (nid,id_tim,k,DBLE(k))
-      ierr = NF_PUT_VARA_DOUBLE (nid,id_NAT,debut,epais,phy_nat(1,k))
-      ierr = NF_PUT_VARA_DOUBLE (nid,id_SST,debut,epais,phy_sst(1,k))
-      ierr = NF_PUT_VARA_DOUBLE (nid,id_BILS,debut,epais,phy_bil(1,k))
-      ierr = NF_PUT_VARA_DOUBLE (nid,id_ALB,debut,epais,phy_alb(1,k))
-      ierr = NF_PUT_VARA_DOUBLE (nid,id_RUG,debut,epais,phy_rug(1,k))
-      ierr = NF_PUT_VARA_DOUBLE (nid,id_FTER,debut,epais,phy_fter(1,k))
-      ierr = NF_PUT_VARA_DOUBLE (nid,id_FOCE,debut,epais,phy_foce(1,k))
-      ierr = NF_PUT_VARA_DOUBLE (nid,id_FSIC,debut,epais,phy_fsic(1,k))
-      ierr = NF_PUT_VARA_DOUBLE (nid,id_FLIC,debut,epais,phy_flic(1,k))
-#else
-      print*,'NC PAS DOUBLE'
-      ierr = NF_PUT_VAR1_REAL (nid,id_tim,k,FLOAT(k))
-      ierr = NF_PUT_VARA_REAL (nid,id_NAT,debut,epais,phy_nat(1,k))
-      ierr = NF_PUT_VARA_REAL (nid,id_SST,debut,epais,phy_sst(1,k))
-      ierr = NF_PUT_VARA_REAL (nid,id_BILS,debut,epais,phy_bil(1,k))
-      ierr = NF_PUT_VARA_REAL (nid,id_ALB,debut,epais,phy_alb(1,k))
-      ierr = NF_PUT_VARA_REAL (nid,id_RUG,debut,epais,phy_rug(1,k))
-      ierr = NF_PUT_VARA_REAL (nid,id_FTER,debut,epais,phy_fter(1,k))
-      ierr = NF_PUT_VARA_REAL (nid,id_FOCE,debut,epais,phy_foce(1,k))
-      ierr = NF_PUT_VARA_REAL (nid,id_FSIC,debut,epais,phy_fsic(1,k))
-      ierr = NF_PUT_VARA_REAL (nid,id_FLIC,debut,epais,phy_flic(1,k))
-
-#endif
-c
-      ENDDO
-c
-      ierr = NF_CLOSE(nid)
-c
-      return
+        ierr = NF_DEF_VAR (nid, "FTER", NF_FLOAT, 2,dims, id_FTER)
+        ierr = NF_PUT_ATT_TEXT (nid, id_FTER, "title", 8,"Frac. Terre")
+        ierr = NF_DEF_VAR (nid, "FOCE", NF_FLOAT, 2,dims, id_FOCE)
+        ierr = NF_PUT_ATT_TEXT (nid, id_FOCE, "title", 8,"Frac. Terre")
+        ierr = NF_DEF_VAR (nid, "FSIC", NF_FLOAT, 2,dims, id_FSIC)
+        ierr = NF_PUT_ATT_TEXT (nid, id_FSIC, "title", 8,"Frac. Terre")
+        ierr = NF_DEF_VAR (nid, "FLIC", NF_FLOAT, 2,dims, id_FLIC)
+        ierr = NF_PUT_ATT_TEXT (nid, id_FLIC, "title", 8,"Frac. Terre")
+c
+        ierr = NF_ENDDEF(nid)
+c
+
+! write the 'times'
+        do k=1,360
+#ifdef NC_DOUBLE
+          ierr = NF_PUT_VAR1_DOUBLE (nid,id_tim,k,DBLE(k))
+#else
+          ierr = NF_PUT_VAR1_REAL (nid,id_tim,k,FLOAT(k))
+#endif
+        enddo
+
+      endif ! of if (is_mpi_root.and.is_omp_root)
+
+! write the fields, after having collected them on master
+
+      call gather(phy_nat,phy_glo)
+      if (is_mpi_root.and.is_omp_root) then
+#ifdef NC_DOUBLE
+        ierr=NF_PUT_VAR_DOUBLE(nid,id_NAT,phy_glo)
+#else
+        ierr=NF_PUT_VAR_REAL(nid,id_NAT,phy_glo)
+#endif
+        if(ierr.ne.NF_NOERR) then
+          write(*,*) "writelim error with phy_nat"
+          write(*,*) NF_STRERROR(ierr)
+        endif
+      endif
+
+      call gather(phy_sst,phy_glo)
+      if (is_mpi_root.and.is_omp_root) then
+#ifdef NC_DOUBLE
+        ierr=NF_PUT_VAR_DOUBLE(nid,id_SST,phy_glo)
+#else
+        ierr=NF_PUT_VAR_REAL(nid,id_SST,phy_glo)
+#endif
+        if(ierr.ne.NF_NOERR) then
+          write(*,*) "writelim error with phy_sst"
+          write(*,*) NF_STRERROR(ierr)
+        endif
+      endif
+
+      call gather(phy_bil,phy_glo)
+      if (is_mpi_root.and.is_omp_root) then
+#ifdef NC_DOUBLE
+        ierr=NF_PUT_VAR_DOUBLE(nid,id_BILS,phy_glo)
+#else
+        ierr=NF_PUT_VAR_REAL(nid,id_BILS,phy_glo)
+#endif
+        if(ierr.ne.NF_NOERR) then
+          write(*,*) "writelim error with phy_bil"
+          write(*,*) NF_STRERROR(ierr)
+        endif
+      endif
+
+      call gather(phy_alb,phy_glo)
+      if (is_mpi_root.and.is_omp_root) then
+#ifdef NC_DOUBLE
+        ierr=NF_PUT_VAR_DOUBLE(nid,id_ALB,phy_glo)
+#else
+        ierr=NF_PUT_VAR_REAL(nid,id_ALB,phy_glo)
+#endif
+        if(ierr.ne.NF_NOERR) then
+          write(*,*) "writelim error with phy_alb"
+          write(*,*) NF_STRERROR(ierr)
+        endif
+      endif
+
+      call gather(phy_rug,phy_glo)
+      if (is_mpi_root.and.is_omp_root) then
+#ifdef NC_DOUBLE
+        ierr=NF_PUT_VAR_DOUBLE(nid,id_RUG,phy_glo)
+#else
+        ierr=NF_PUT_VAR_REAL(nid,id_RUG,phy_glo)
+#endif
+        if(ierr.ne.NF_NOERR) then
+          write(*,*) "writelim error with phy_rug"
+          write(*,*) NF_STRERROR(ierr)
+        endif
+      endif
+
+      call gather(phy_fter,phy_glo)
+      if (is_mpi_root.and.is_omp_root) then
+#ifdef NC_DOUBLE
+        ierr=NF_PUT_VAR_DOUBLE(nid,id_FTER,phy_glo)
+#else
+        ierr=NF_PUT_VAR_REAL(nid,id_FTER,phy_glo)
+#endif
+        if(ierr.ne.NF_NOERR) then
+          write(*,*) "writelim error with phy_fter"
+          write(*,*) NF_STRERROR(ierr)
+        endif
+      endif
+
+      call gather(phy_foce,phy_glo)
+      if (is_mpi_root.and.is_omp_root) then
+#ifdef NC_DOUBLE
+        ierr=NF_PUT_VAR_DOUBLE(nid,id_FOCE,phy_glo)
+#else
+        ierr=NF_PUT_VAR_REAL(nid,id_FOCE,phy_glo)
+#endif
+        if(ierr.ne.NF_NOERR) then
+          write(*,*) "writelim error with phy_foce"
+          write(*,*) NF_STRERROR(ierr)
+        endif
+      endif
+
+      call gather(phy_fsic,phy_glo)
+      if (is_mpi_root.and.is_omp_root) then
+#ifdef NC_DOUBLE
+        ierr=NF_PUT_VAR_DOUBLE(nid,id_FSIC,phy_glo)
+#else
+        ierr=NF_PUT_VAR_REAL(nid,id_FSIC,phy_glo)
+#endif
+        if(ierr.ne.NF_NOERR) then
+          write(*,*) "writelim error with phy_fsic"
+          write(*,*) NF_STRERROR(ierr)
+        endif
+      endif
+
+      call gather(phy_flic,phy_glo)
+      if (is_mpi_root.and.is_omp_root) then
+#ifdef NC_DOUBLE
+        ierr=NF_PUT_VAR_DOUBLE(nid,id_FLIC,phy_glo)
+#else
+        ierr=NF_PUT_VAR_REAL(nid,id_FLIC,phy_glo)
+#endif
+        if(ierr.ne.NF_NOERR) then
+          write(*,*) "writelim error with phy_flic"
+          write(*,*) NF_STRERROR(ierr)
+        endif
+      endif
+
+!  close file:
+      if (is_mpi_root.and.is_omp_root) then
+        ierr = NF_CLOSE(nid)
+      endif
+
       end
+
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
       SUBROUTINE profil_sst(nlon, rlatd, type_profil, phy_sst)
Index: LMDZ5/branches/testing/libf/phylmd/phyetat0.F
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/phyetat0.F	(revision 1669)
+++ LMDZ5/branches/testing/libf/phylmd/phyetat0.F	(revision 1707)
@@ -76,5 +76,5 @@
 c FH1D
 c     real iolat(jjm+1)
-      real iolat(jjm+1-1/iim)
+      real iolat(jjm+1-1/(iim*jjm))
 c
 c Ouvrir le fichier contenant l'etat initial:
Index: LMDZ5/branches/testing/libf/phylmd/phys_output_mod.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/phys_output_mod.F90	(revision 1669)
+++ LMDZ5/branches/testing/libf/phylmd/phys_output_mod.F90	(revision 1707)
@@ -81,4 +81,5 @@
   type(ctrl_out),save :: o_sicf         = ctrl_out((/ 1, 1, 10, 10, 10, 10 /),'sicf')
   type(ctrl_out),save :: o_q2m          = ctrl_out((/ 1, 1, 1, 5, 10, 10 /),'q2m')
+  type(ctrl_out),save :: o_ustar        = ctrl_out((/ 1, 1, 1, 5, 10, 10 /),'ustar')
   type(ctrl_out),save :: o_u10m         = ctrl_out((/ 1, 1, 1, 5, 10, 10 /),'u10m')
   type(ctrl_out),save :: o_v10m         = ctrl_out((/ 1, 1, 1, 5, 10, 10 /),'v10m')
@@ -86,4 +87,8 @@
   type(ctrl_out),save :: o_qsurf        = ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'qsurf')
 
+  type(ctrl_out),save,dimension(4) :: o_ustar_srf     = (/ ctrl_out((/ 10, 6, 10, 10, 10, 10 /),'ustar_ter'), &
+       ctrl_out((/ 10, 6, 10, 10, 10, 10 /),'ustar_lic'), &
+       ctrl_out((/ 10, 6, 10, 10, 10, 10 /),'ustar_oce'), &
+       ctrl_out((/ 10, 6, 10, 10, 10, 10 /),'ustar_sic') /)
   type(ctrl_out),save,dimension(4) :: o_u10m_srf     = (/ ctrl_out((/ 10, 6, 10, 10, 10, 10 /),'u10m_ter'), &
        ctrl_out((/ 10, 6, 10, 10, 10, 10 /),'u10m_lic'), &
@@ -585,4 +590,5 @@
 
   type(ctrl_out),save,allocatable :: o_trac(:)
+  type(ctrl_out),save,allocatable :: o_trac_cum(:)
 
   type(ctrl_out),save :: o_rsu        = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'rsu')
@@ -719,4 +725,5 @@
 
     if (.not. allocated(o_trac)) ALLOCATE(o_trac(nqtot))
+    if (.not. allocated(o_trac_cum)) ALLOCATE(o_trac_cum(nqtot))
 
     levmax = (/ klev, klev, klev, klev, klev, klev /)
@@ -960,4 +967,5 @@
           CALL histdef2d(iff,clef_stations(iff),o_sicf%flag,o_sicf%name, "Sea-ice fraction", "-" )
           CALL histdef2d(iff,clef_stations(iff),o_q2m%flag,o_q2m%name, "Specific humidity 2m", "kg/kg")
+          CALL histdef2d(iff,clef_stations(iff),o_ustar%flag,o_ustar%name, "Friction velocity", "m/s" )
           CALL histdef2d(iff,clef_stations(iff),o_u10m%flag,o_u10m%name, "Vent zonal 10m", "m/s" )
           CALL histdef2d(iff,clef_stations(iff),o_v10m%flag,o_v10m%name, "Vent meridien 10m", "m/s")
@@ -969,5 +977,12 @@
           endif
 
+             type_ecri(1) = 'inst(X)'
+             type_ecri(2) = 'inst(X)'
+             type_ecri(3) = 'inst(X)'
+             type_ecri(4) = 'inst(X)'
+             type_ecri(5) = 'inst(X)'
+             type_ecri(6) = 'inst(X)'
           CALL histdef2d(iff,clef_stations(iff),o_ndayrain%flag,o_ndayrain%name, "Number of dayrain(liq+sol)", "-")
+             type_ecri(:) = type_ecri_files(:)
           CALL histdef2d(iff,clef_stations(iff),o_precip%flag,o_precip%name, "Precip Totale liq+sol", "kg/(s*m2)" )
           CALL histdef2d(iff,clef_stations(iff),o_plul%flag,o_plul%name, "Large-scale Precip.", "kg/(s*m2)") 
@@ -1027,4 +1042,6 @@
                   o_tsol_srf(nsrf)%flag,o_tsol_srf(nsrf)%name,"Temperature "//clnsurf(nsrf),"K")
              CALL histdef2d(iff,clef_stations(iff), &
+                  o_ustar_srf(nsrf)%flag,o_ustar_srf(nsrf)%name,"Friction velocity "//clnsurf(nsrf),"m/s")
+             CALL histdef2d(iff,clef_stations(iff), &
                   o_u10m_srf(nsrf)%flag,o_u10m_srf(nsrf)%name,"Vent Zonal 10m "//clnsurf(nsrf),"m/s")
              CALL histdef2d(iff,clef_stations(iff), &
@@ -1756,5 +1773,8 @@
                 o_trac(iq-2) = ctrl_out((/ 4, 5, 1, 1, 1, 10 /),tname(iiq))
                 CALL histdef3d (iff,clef_stations(iff), &
-                     o_trac(iq-2)%flag,o_trac(iq-2)%name,'Tracer '//ttext(iiq), "-" )
+                o_trac(iq-2)%flag,o_trac(iq-2)%name,'Tracer '//ttext(iiq), "-" )
+                o_trac_cum(iq-2) = ctrl_out((/ 3, 4, 10, 10, 10, 10 /),'cum'//tname(iiq))
+                CALL histdef2d (iff,clef_stations(iff), &
+                o_trac_cum(iq-2)%flag,o_trac_cum(iq-2)%name,'Cumulated tracer '//ttext(iiq), "-" )
              ENDDO
           ENDIF
Index: LMDZ5/branches/testing/libf/phylmd/phys_output_write.h
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/phys_output_write.h	(revision 1669)
+++ LMDZ5/branches/testing/libf/phylmd/phys_output_write.h	(revision 1707)
@@ -101,4 +101,9 @@
       CALL histwrite_phy(nid_files(iff),clef_stations(iff),
      $o_q2m%name,itau_w,zq2m)
+       ENDIF
+
+       IF (o_ustar%flag(iff)<=lev_files(iff)) THEN
+      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
+     $o_ustar%name,itau_w,zustar)
        ENDIF
 
@@ -437,4 +442,11 @@
      $      zx_tmp_fi2d)
         ENDIF
+
+      IF (o_ustar_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN
+      zx_tmp_fi2d(1 : klon) = ustar(1 : klon, nsrf)
+      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
+     $o_ustar_srf(nsrf)%name,
+     $                 itau_w,zx_tmp_fi2d)
+      ENDIF
 
       IF (o_u10m_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN
@@ -2248,4 +2260,15 @@
        ENDIF
          ENDDO
+         DO iq=3,nqtot
+       IF (o_trac_cum(iq-2)%flag(iff)<=lev_files(iff)) THEN
+         zx_tmp_fi2d=0.
+         do k=1,klev
+            zx_tmp_fi2d(:)=zx_tmp_fi2d(:)+zmasse(:,k)*qx(:,k,iq)
+         enddo
+         CALL histwrite_phy(nid_files(iff),clef_stations(iff),
+     s                  o_trac_cum(iq-2)%name,itau_w,zx_tmp_fi2d)
+
+       ENDIF
+         ENDDO
         endif
 
Index: LMDZ5/branches/testing/libf/phylmd/phys_state_var_mod.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/phys_state_var_mod.F90	(revision 1669)
+++ LMDZ5/branches/testing/libf/phylmd/phys_state_var_mod.F90	(revision 1707)
@@ -326,6 +326,6 @@
       REAL,SAVE,ALLOCATABLE :: newsst(:)
 !$OMP THREADPRIVATE(newsst)
-      REAL,SAVE,ALLOCATABLE :: u10m(:,:), v10m(:,:)
-!$OMP THREADPRIVATE(u10m,v10m)
+      REAL,SAVE,ALLOCATABLE :: ustar(:,:),u10m(:,:), v10m(:,:)
+!$OMP THREADPRIVATE(ustar,u10m,v10m)
 !
 ! ok_ade=T -ADE=topswad-topsw
@@ -496,5 +496,5 @@
       ALLOCATE(rlonPOS(klon))
       ALLOCATE(newsst(klon))
-      ALLOCATE(u10m(klon,nbsrf), v10m(klon,nbsrf))
+      ALLOCATE(ustar(klon,nbsrf),u10m(klon,nbsrf), v10m(klon,nbsrf))
       ALLOCATE(topswad(klon), solswad(klon))
       ALLOCATE(topswai(klon), solswai(klon))
@@ -606,5 +606,5 @@
       deallocate(rlonPOS)
       deallocate(newsst)
-      deallocate(u10m, v10m)
+      deallocate(ustar,u10m, v10m)
       deallocate(topswad, solswad)
       deallocate(topswai, solswai)
Index: LMDZ5/branches/testing/libf/phylmd/physiq.F
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/physiq.F	(revision 1669)
+++ LMDZ5/branches/testing/libf/phylmd/physiq.F	(revision 1707)
@@ -178,5 +178,5 @@
       save iflag_ratqs
 c$OMP THREADPRIVATE(iflag_ratqs)
-      real facteur,zfratqs1,zfratqs2
+      real facteur
 
       REAL zz,znum,zden
@@ -257,63 +257,8 @@
 c variables a une pression donnee
 c
-      real rlevSTD(nlevSTD)
-      DATA rlevSTD/100000., 92500., 85000., 70000.,
-     .60000., 50000., 40000., 30000., 25000., 20000.,
-     .15000., 10000., 7000., 5000., 3000., 2000., 1000./
-      SAVE rlevstd
-c$OMP THREADPRIVATE(rlevstd)
-      CHARACTER*4 clevSTD(nlevSTD)
-      DATA clevSTD/'1000','925 ','850 ','700 ','600 ',
-     .'500 ','400 ','300 ','250 ','200 ','150 ','100 ',
-     .'70  ','50  ','30  ','20  ','10  '/
-      SAVE clevSTD
-c$OMP THREADPRIVATE(clevSTD)
+#include "declare_STDlev.h"
 c
       CHARACTER*4 bb2
       CHARACTER*2 bb3
-
-      real twriteSTD(klon,nlevSTD,nfiles)
-      real qwriteSTD(klon,nlevSTD,nfiles)
-      real rhwriteSTD(klon,nlevSTD,nfiles)
-      real phiwriteSTD(klon,nlevSTD,nfiles)
-      real uwriteSTD(klon,nlevSTD,nfiles)
-      real vwriteSTD(klon,nlevSTD,nfiles)
-      real wwriteSTD(klon,nlevSTD,nfiles)
-cIM for NMC files
-      REAL geo500(klon)
-      real :: rlevSTD3(nlevSTD3)
-      DATA rlevSTD3/85000., 50000., 25000./
-      SAVE rlevSTD3
-c$OMP THREADPRIVATE(rlevSTD3)
-      real :: rlevSTD8(nlevSTD8)
-      DATA rlevSTD8/100000., 85000., 70000., 50000., 25000., 10000.,
-     $     5000., 1000./
-      SAVE rlevSTD8
-c$OMP THREADPRIVATE(rlevSTD8) 
-      real twriteSTD3(klon,nlevSTD3)
-      real qwriteSTD3(klon,nlevSTD3)
-      real rhwriteSTD3(klon,nlevSTD3)
-      real phiwriteSTD3(klon,nlevSTD3)
-      real uwriteSTD3(klon,nlevSTD3)
-      real vwriteSTD3(klon,nlevSTD3)
-      real wwriteSTD3(klon,nlevSTD3)
-c
-      real tnondefSTD8(klon,nlevSTD8)
-      real twriteSTD8(klon,nlevSTD8)
-      real qwriteSTD8(klon,nlevSTD8)
-      real rhwriteSTD8(klon,nlevSTD8)
-      real phiwriteSTD8(klon,nlevSTD8)
-      real uwriteSTD8(klon,nlevSTD8)
-      real vwriteSTD8(klon,nlevSTD8)
-      real wwriteSTD8(klon,nlevSTD8)
-c
-c plevSTD3 END
-c
-c nout : niveau de output des variables a une pression donnee
-      logical oknondef(klon,nlevSTD,nout)
-c
-c les produits uvSTD, vqSTD, .., T2STD sont calcules
-c a partir des valeurs instantannees toutes les 6 h
-c qui sont moyennees sur le mois
 c
 #include "radopt.h"
@@ -958,5 +903,5 @@
       REAL snow_lsc(klon)
 c
-      REAL ratqss(klon,klev),ratqsc(klon,klev)
+      REAL ratqsc(klon,klev)
       real ratqsbas,ratqshaut,tau_ratqs
       save ratqsbas,ratqshaut,tau_ratqs
@@ -1050,16 +995,7 @@
       REAL zx_tmp_fi3d(klon,klev) ! variable temporaire pour champs 3D 
       REAL zx_tmp_fi3d1(klon,klev+1) !variable temporaire pour champs 3D (kelvp1)
-c#ifdef histNMC
-cym   A voir plus tard !!!!
-cym      REAL zx_tmp_NC(iim,jjmp1,nlevSTD)
-      REAL zx_tmp_fiNC(klon,nlevSTD) 
-c#endif
       REAL(KIND=8) zx_tmp2_fi3d(klon,klev) ! variable temporaire pour champs 3D 
       REAL zx_tmp_2d(iim,jjmp1), zx_tmp_3d(iim,jjmp1,klev)
       REAL zx_lon(iim,jjmp1), zx_lat(iim,jjmp1)
-cIM for NMC files
-      REAL missing_val
-      REAL, SAVE :: freq_moyNMC(nout)
-c$OMP THREADPRIVATE(freq_moyNMC)
 c
       INTEGER nid_day, nid_mth, nid_ins, nid_mthnmc, nid_daynmc
@@ -1137,7 +1073,7 @@
       REAL q2m(klon,nbsrf)  ! humidite a 2m
 
-cIM: t2m, q2m, u10m, v10m et t2mincels, t2maxcels
+cIM: t2m, q2m, ustar, u10m, v10m et t2mincels, t2maxcels
       REAL zt2m(klon), zq2m(klon)             !temp., hum. 2m moyenne s/ 1 maille
-      REAL zu10m(klon), zv10m(klon)           !vents a 10m moyennes s/1 maille
+      REAL zustar(klon),zu10m(klon), zv10m(klon)  ! u* et vents a 10m moyennes s/1 maille
       CHARACTER*40 t2mincels, t2maxcels       !t2m min., t2m max
       CHARACTER*40 tinst, tave, typeval
@@ -1255,6 +1191,4 @@
       integer iostat
 
-cIM for NMC files
-      missing_val=nf90_fill_real
 c======================================================================
 ! Gestion calendrier : mise a jour du module phys_cal_mod
@@ -1326,12 +1260,5 @@
       call phys_output_var_init
       print*, '================================================='
-cIM for NMC files
-cIM freq_moyNMC = frequences auxquelles on moyenne les champs accumules 
-cIM               sur les niveaux de pression standard du NMC
-      DO n=1, nout
-       freq_moyNMC(n)=freq_outNMC(n)/freq_calNMC(n)
-      ENDDO
-c
-cIM beg
+c
           dnwd0=0.0
           ftd=0.0
@@ -1381,4 +1308,5 @@
          lalim_conv(:)=1 
 cRC
+         ustar(:,:)=0.
          u10m(:,:)=0.
          v10m(:,:)=0.
@@ -1768,5 +1696,5 @@
 !
       CALL change_srf_frac(itap, dtime, days_elapsed+1, 
-     *     pctsrf, falb1, falb2, ftsol, u10m, v10m, pbl_tke)
+     *     pctsrf, falb1, falb2, ftsol, ustar, u10m, v10m, pbl_tke)
 
 
@@ -2078,5 +2006,5 @@
      e     t_seri,    q_seri,    u_seri,  v_seri,   
      e     pplay,     paprs,     pctsrf,            
-     +     ftsol,     falb1,     falb2,   u10m,   v10m,
+     +     ftsol,     falb1,     falb2,   ustar, u10m,   v10m,
      s     sollwdown, cdragh,    cdragm,  u1,    v1,
      s     albsol1,   albsol2,   sens,    evap,  
@@ -2087,5 +2015,5 @@
      d     s_capCL,   s_oliqCL,  s_cteiCL,s_pblT,
      d     s_therm,   s_trmb1,   s_trmb2, s_trmb3,
-     d     zxrugs,    zu10m,     zv10m,   fder,
+     d     zxrugs,    zustar, zu10m,     zv10m,   fder,
      d     zxqsurf,   rh2m,      zxfluxu, zxfluxv,
      d     frugs,     agesno,    fsollw,  fsolsw,
@@ -2816,159 +2744,12 @@
 
 c-------------------------------------------------------------------------
-c  Caclul des ratqs
-c-------------------------------------------------------------------------
-
-c      print*,'calcul des ratqs'
-c   ratqs convectifs a l'ancienne en fonction de q(z=0)-q / q
-c   ----------------
-c   on ecrase le tableau ratqsc calcule par clouds_gno
-      if (iflag_cldcon.eq.1) then
-         do k=1,klev
-         do i=1,klon
-            if(ptconv(i,k)) then
-              ratqsc(i,k)=ratqsbas
-     s        +fact_cldcon*(q_seri(i,1)-q_seri(i,k))/q_seri(i,k)
-            else
-               ratqsc(i,k)=0.
-            endif
-         enddo
-         enddo
-
-c-----------------------------------------------------------------------
-c  par nversion de la fonction log normale
-c-----------------------------------------------------------------------
-      else if (iflag_cldcon.eq.4) then
-         ptconvth(:,:)=.false.
-         ratqsc(:,:)=0.
-         if(prt_level.ge.9) print*,'avant clouds_gno thermique'
-         call clouds_gno
-     s   (klon,klev,q_seri,zqsat,clwcon0th,ptconvth,ratqsc,rnebcon0th)
-         if(prt_level.ge.9) print*,' CLOUDS_GNO OK'
-       
-       endif
-
-c   ratqs stables
-c   -------------
-
-      if (iflag_ratqs.eq.0) then
-
-! Le cas iflag_ratqs=0 correspond a la version IPCC 2005 du modele.
-         do k=1,klev
-            do i=1, klon
-               ratqss(i,k)=ratqsbas+(ratqshaut-ratqsbas)*
-     s         min((paprs(i,1)-pplay(i,k))/(paprs(i,1)-30000.),1.) 
-            enddo 
-         enddo
-
-! Pour iflag_ratqs=1 ou 2, le ratqs est constant au dessus de 
-! 300 hPa (ratqshaut), varie lineariement en fonction de la pression
-! entre 600 et 300 hPa et est soit constant (ratqsbas) pour iflag_ratqs=1
-! soit lineaire (entre 0 a la surface et ratqsbas) pour iflag_ratqs=2
-! Il s'agit de differents tests dans la phase de reglage du modele
-! avec thermiques.
-
-      else if (iflag_ratqs.eq.1) then
-
-         do k=1,klev
-            do i=1, klon
-               if (pplay(i,k).ge.60000.) then
-                  ratqss(i,k)=ratqsbas
-               else if ((pplay(i,k).ge.30000.).and.
-     s            (pplay(i,k).lt.60000.)) then
-                  ratqss(i,k)=ratqsbas+(ratqshaut-ratqsbas)*
-     s            (60000.-pplay(i,k))/(60000.-30000.)
-               else
-                  ratqss(i,k)=ratqshaut
-               endif
-            enddo
-         enddo
-
-      else if (iflag_ratqs.eq.2) then
-
-         do k=1,klev
-            do i=1, klon
-               if (pplay(i,k).ge.60000.) then
-                  ratqss(i,k)=ratqsbas
-     s            *(paprs(i,1)-pplay(i,k))/(paprs(i,1)-60000.)
-               else if ((pplay(i,k).ge.30000.).and.
-     s             (pplay(i,k).lt.60000.)) then
-                    ratqss(i,k)=ratqsbas+(ratqshaut-ratqsbas)*
-     s              (60000.-pplay(i,k))/(60000.-30000.)
-               else
-                    ratqss(i,k)=ratqshaut
-               endif
-            enddo
-         enddo
-
-      else if (iflag_ratqs==3) then
-         do k=1,klev
-           ratqss(:,k)=ratqsbas+(ratqshaut-ratqsbas)
-     s     *min( ((paprs(:,1)-pplay(:,k))/70000.)**2 , 1. )
-         enddo
-
-      else if (iflag_ratqs==4) then
-         do k=1,klev
-           ratqss(:,k)=ratqsbas+0.5*(ratqshaut-ratqsbas)
-     s     *( tanh( (50000.-pplay(:,k))/20000.) + 1.)
-         enddo
-
-      endif
-
-
-
-
-c  ratqs final
-c  -----------
-
-      if (iflag_cldcon.eq.1 .or.iflag_cldcon.eq.2
-     s    .or.iflag_cldcon.eq.4) then
-
-! On ajoute une constante au ratqsc*2 pour tenir compte de 
-! fluctuations turbulentes de petite echelle
-
-         do k=1,klev
-            do i=1,klon
-               if ((fm_therm(i,k).gt.1.e-10)) then
-                  ratqsc(i,k)=sqrt(ratqsc(i,k)**2+0.05**2)
-               endif
-            enddo
-         enddo
-
-!   les ratqs sont une combinaison de ratqss et ratqsc
-       if(prt_level.ge.9)
-     $       write(lunout,*)'PHYLMD NOUVEAU TAU_RATQS ',tau_ratqs
-
-         if (tau_ratqs>1.e-10) then
-            facteur=exp(-pdtphys/tau_ratqs)
-         else
-            facteur=0.
-         endif
-         ratqs(:,:)=ratqsc(:,:)*(1.-facteur)+ratqs(:,:)*facteur
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-! FH 22/09/2009
-! La ligne ci-dessous faisait osciller le modele et donnait une solution
-! assymptotique bidon et dÃ©pendant fortement du pas de temps.
-!        ratqs(:,:)=sqrt(ratqs(:,:)**2+ratqss(:,:)**2)
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-         ratqs(:,:)=max(ratqs(:,:),ratqss(:,:))
-      else if (iflag_cldcon<=6) then
-!   on ne prend que le ratqs stable pour fisrtilp
-         ratqs(:,:)=ratqss(:,:)
-      else
-          zfratqs1=exp(-pdtphys/10800.)
-          zfratqs2=exp(-pdtphys/10800.)
-!         print*,'RAPPEL RATQS 1 ',zfratqs1,zfratqs2
-!    s    ,ratqss(1,14),ratqs(1,14),ratqsc(1,14)
-          do k=1,klev
-             do i=1,klon
-                if (ratqsc(i,k).gt.1.e-10) then
-                   ratqs(i,k)=ratqs(i,k)*zfratqs2
-     s             +(iflag_cldcon/100.)*ratqsc(i,k)*(1.-zfratqs2)
-                endif
-                ratqs(i,k)=min(ratqs(i,k)*zfratqs1
-     s          +ratqss(i,k)*(1.-zfratqs1),0.5)
-             enddo
-          enddo
-      endif
+! Computation of ratqs, the width (normalized) of the subrid scale 
+! water distribution
+      CALL  calcratqs(klon,klev,prt_level,lunout,       
+     s     iflag_ratqs,iflag_con,iflag_cldcon,pdtphys, 
+     s     ratqsbas,ratqshaut,tau_ratqs,fact_cldcon,  
+     s     ptconv,ptconvth,clwcon0th, rnebcon0th,    
+     s     paprs,pplay,q_seri,zqsat,fm_therm,
+     s     ratqs,ratqsc)
 
 
@@ -3843,4 +3624,5 @@
      I     cdragh,   coefh,     fm_therm, entr_therm,
      I     u1,       v1,        ftsol,    pctsrf,
+     I     ustar,     u10m,      v10m,
      I     rlat,     frac_impa, frac_nucl,rlon,
      I     presnivs, pphis,     pphi,     albsol1,
@@ -3933,82 +3715,4 @@
 c
 #include "calcul_STDlev.h"
-      twriteSTD(:,:,1)=tsumSTD(:,:,1)
-      qwriteSTD(:,:,1)=qsumSTD(:,:,1)
-      rhwriteSTD(:,:,1)=rhsumSTD(:,:,1)
-      phiwriteSTD(:,:,1)=phisumSTD(:,:,1)
-      uwriteSTD(:,:,1)=usumSTD(:,:,1)
-      vwriteSTD(:,:,1)=vsumSTD(:,:,1)
-      wwriteSTD(:,:,1)=wsumSTD(:,:,1)
-
-      twriteSTD(:,:,2)=tsumSTD(:,:,2)
-      qwriteSTD(:,:,2)=qsumSTD(:,:,2)
-      rhwriteSTD(:,:,2)=rhsumSTD(:,:,2)
-      phiwriteSTD(:,:,2)=phisumSTD(:,:,2)
-      uwriteSTD(:,:,2)=usumSTD(:,:,2)
-      vwriteSTD(:,:,2)=vsumSTD(:,:,2)
-      wwriteSTD(:,:,2)=wsumSTD(:,:,2)
-
-      twriteSTD(:,:,3)=tlevSTD(:,:)
-      qwriteSTD(:,:,3)=qlevSTD(:,:)
-      rhwriteSTD(:,:,3)=rhlevSTD(:,:)
-      phiwriteSTD(:,:,3)=philevSTD(:,:)
-      uwriteSTD(:,:,3)=ulevSTD(:,:)
-      vwriteSTD(:,:,3)=vlevSTD(:,:)
-      wwriteSTD(:,:,3)=wlevSTD(:,:)
-
-      twriteSTD(:,:,4)=tlevSTD(:,:)
-      qwriteSTD(:,:,4)=qlevSTD(:,:)
-      rhwriteSTD(:,:,4)=rhlevSTD(:,:)
-      phiwriteSTD(:,:,4)=philevSTD(:,:)
-      uwriteSTD(:,:,4)=ulevSTD(:,:)
-      vwriteSTD(:,:,4)=vlevSTD(:,:)
-      wwriteSTD(:,:,4)=wlevSTD(:,:)
-c
-cIM initialisation 5eme fichier de sortie 
-      twriteSTD(:,:,5)=tlevSTD(:,:)
-      qwriteSTD(:,:,5)=qlevSTD(:,:)
-      rhwriteSTD(:,:,5)=rhlevSTD(:,:)
-      phiwriteSTD(:,:,5)=philevSTD(:,:)
-      uwriteSTD(:,:,5)=ulevSTD(:,:)
-      vwriteSTD(:,:,5)=vlevSTD(:,:)
-      wwriteSTD(:,:,5)=wlevSTD(:,:)
-c
-cIM initialisation 6eme fichier de sortie 
-      twriteSTD(:,:,6)=tlevSTD(:,:)
-      qwriteSTD(:,:,6)=qlevSTD(:,:)
-      rhwriteSTD(:,:,6)=rhlevSTD(:,:)
-      phiwriteSTD(:,:,6)=philevSTD(:,:)
-      uwriteSTD(:,:,6)=ulevSTD(:,:)
-      vwriteSTD(:,:,6)=vlevSTD(:,:)
-      wwriteSTD(:,:,6)=wlevSTD(:,:)
-cIM for NMC files
-      DO n=1, nlevSTD3
-       DO k=1, nlevSTD
-        if(rlevSTD3(n).EQ.rlevSTD(k)) THEN
-         twriteSTD3(:,n)=tlevSTD(:,k)
-         qwriteSTD3(:,n)=qlevSTD(:,k)
-         rhwriteSTD3(:,n)=rhlevSTD(:,k)
-         phiwriteSTD3(:,n)=philevSTD(:,k)
-         uwriteSTD3(:,n)=ulevSTD(:,k)
-         vwriteSTD3(:,n)=vlevSTD(:,k)
-         wwriteSTD3(:,n)=wlevSTD(:,k)
-        endif !rlevSTD3(n).EQ.rlevSTD(k)
-       ENDDO 
-      ENDDO 
-c
-      DO n=1, nlevSTD8
-       DO k=1, nlevSTD
-        if(rlevSTD8(n).EQ.rlevSTD(k)) THEN
-         tnondefSTD8(:,n)=tnondef(:,k,2)
-         twriteSTD8(:,n)=tsumSTD(:,k,2)
-         qwriteSTD8(:,n)=qsumSTD(:,k,2)
-         rhwriteSTD8(:,n)=rhsumSTD(:,k,2)
-         phiwriteSTD8(:,n)=phisumSTD(:,k,2)
-         uwriteSTD8(:,n)=usumSTD(:,k,2)
-         vwriteSTD8(:,n)=vsumSTD(:,k,2)
-         wwriteSTD8(:,n)=wsumSTD(:,k,2)
-        endif !rlevSTD8(n).EQ.rlevSTD(k)
-       ENDDO 
-      ENDDO 
 c
 c slp sea level pressure
Index: LMDZ5/branches/testing/libf/phylmd/phytrac.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/phytrac.F90	(revision 1669)
+++ LMDZ5/branches/testing/libf/phylmd/phytrac.F90	(revision 1707)
@@ -8,4 +8,5 @@
      cdragh,    coefh,    fm_therm, entr_therm,&
      yu1,       yv1,      ftsol,    pctsrf,    &
+     ustar,     u10m,      v10m,               &
      xlat,      frac_impa,frac_nucl,xlon,      &
      presnivs,  pphis,    pphi,     albsol,    &
@@ -119,8 +120,9 @@
 !--------------
 !
-  REAL,DIMENSION(klon),INTENT(IN)      :: cdragh ! coeff drag pour T et Q
-  REAL,DIMENSION(klon,klev),INTENT(IN) :: coefh  ! coeff melange CL (m**2/s)
-  REAL,DIMENSION(klon),INTENT(IN)      :: yu1    ! vents au premier niveau
-  REAL,DIMENSION(klon),INTENT(IN)      :: yv1    ! vents au premier niveau
+  REAL,DIMENSION(klon),INTENT(IN)     :: cdragh ! coeff drag pour T et Q
+  REAL,DIMENSION(klon,klev),INTENT(IN):: coefh  ! coeff melange CL (m**2/s)
+  REAL,DIMENSION(klon),INTENT(IN)     :: ustar,u10m,v10m ! u* & vent a 10m (m/s)
+  REAL,DIMENSION(klon),INTENT(IN)     :: yu1    ! vents au premier niveau
+  REAL,DIMENSION(klon),INTENT(IN)     :: yv1    ! vents au premier niveau
 !
 !Lessivage:
@@ -244,6 +246,7 @@
      !    -- Traitement des traceurs avec traclmdz
      CALL traclmdz(nstep, julien, gmtime, pdtphys, t_seri, paprs, pplay, &
-          cdragh,  coefh, yu1, yv1, ftsol, pctsrf, xlat, xlon, couchelimite, &
-          sh, tr_seri, source, solsym, d_tr_cl, zmasse)
+          cdragh,  coefh, yu1, yv1, ftsol, pctsrf, xlat, xlon,couchelimite,sh,&
+          rh, pphi, ustar, u10m, v10m, &
+          tr_seri, source, solsym, d_tr_cl, zmasse)
   CASE('inca')
      !    -- CHIMIE INCA  config_inca = aero or chem --
Index: LMDZ5/branches/testing/libf/phylmd/printflag.F
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/printflag.F	(revision 1669)
+++ LMDZ5/branches/testing/libf/phylmd/printflag.F	(revision 1707)
@@ -87,5 +87,5 @@
 !        radpas0  = NINT( 86400./tabcntr0(1)/INT( tabcntr0(6) ) )
         PRINT 100
-        PRINT 22, radpas0, radpas
+!        PRINT 22, radpas0, radpas
         PRINT 100
        ENDIF
Index: LMDZ5/branches/testing/libf/phylmd/radiation_AR4_param.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/radiation_AR4_param.F90	(revision 1669)
+++ 	(revision )
@@ -1,241 +1,0 @@
-MODULE radiation_AR4_param
-
- REAL*8, parameter :: ZPDH2O = 0.8
- REAL*8, parameter :: ZPDUMG = 0.75
- REAL*8, parameter :: ZPRH2O = 30000.0
- REAL*8, parameter :: ZPRUMG = 30000.0
- REAL*8, parameter :: RTDH2O = 0.40
- REAL*8, parameter :: RTDUMG = 0.375
- REAL*8, parameter :: RTH2O = 240.0
- REAL*8, parameter :: RTUMG = 240.0
-
- REAL*8, dimension(2), parameter :: WG1 = (/1.0, 1.0/)
- REAL*8, dimension(11), parameter :: TINTP = (/ 187.5, 200., 212.5, 225., 237.5, 250., 262.5, 275., 287.5, 300., 312.5 /)
-
- real*8, dimension(11,16,3), parameter :: GA = reshape ( (/                                                                &
- 0.63499072E-02, 0.65566348E-02, 0.67849730E-02, 0.70481947E-02, 0.73585943E-02, 0.77242818E-02, 0.81472693E-02, 0.86227527E-02,&
- 0.91396814E-02, 0.96825438E-02, 0.10233955E-01, 0.77266491E-02, 0.81323287E-02, 0.86507620E-02, 0.92776391E-02, 0.99806312E-02,&
- 0.10709803E-01, 0.11414739E-01, 0.12058772E-01, 0.12623992E-01, 0.13108146E-01, 0.13518390E-01, 0.11644593E+01, 0.11747203E+01,&
- 0.11837872E+01, 0.11918561E+01, 0.11990757E+01, 0.12055643E+01, 0.12114186E+01, 0.12167192E+01, 0.12215344E+01, 0.12259226E+01,&
- 0.12299344E+01, 0.12006968E+01, 0.12108196E+01, 0.12196717E+01, 0.12274493E+01, 0.12343189E+01, 0.12404147E+01, 0.12458431E+01,&
- 0.12506907E+01, 0.12550299E+01, 0.12589256E+01, 0.12624402E+01, 0.15750172E+00, 0.16174076E+00, 0.16548628E+00, 0.16881124E+00,&
- 0.17177839E+00, 0.17443933E+00, 0.17683622E+00, 0.17900375E+00, 0.18097099E+00, 0.18276283E+00, 0.18440117E+00, 0.17770551E+00,&
- 0.18176757E+00, 0.18527967E+00, 0.18833348E+00, 0.19100108E+00, 0.19334122E+00, 0.19540288E+00, 0.19722732E+00, 0.19884918E+00,&
- 0.20029696E+00, 0.20159300E+00, 0.10192131E+02, 0.97258602E+01, 0.92992890E+01, 0.89154021E+01, 0.85730084E+01, 0.82685838E+01,&
- 0.79978921E+01, 0.77568055E+01, 0.75416266E+01, 0.73491694E+01, 0.71767400E+01, 0.92439050E+01, 0.87567422E+01, 0.83270144E+01,&
- 0.79528337E+01, 0.76286839E+01, 0.73477879E+01, 0.71035818E+01, 0.68903312E+01, 0.67032875E+01, 0.65386461E+01, 0.63934377E+01,&
- 0.24870635E+02, 0.24725591E+02, 0.24600320E+02, 0.24487300E+02, 0.24384935E+02, 0.24292341E+02, 0.24208572E+02, 0.24132642E+02,&
- 0.24063614E+02, 0.24000649E+02, 0.23943021E+02, 0.24586283E+02, 0.24441465E+02, 0.24311657E+02, 0.24196167E+02, 0.24093406E+02,&
- 0.24001597E+02, 0.23919098E+02, 0.23844511E+02, 0.23776708E+02, 0.23714816E+02, 0.23658197E+02, 0.11990218E+02, 0.10904073E+02,&
- 0.89126838E+01, 0.85622405E+01, 0.94892164E+01, 0.13580937E+02,-0.32050918E+03,-0.37133165E+01, 0.18890836E+00, 0.14209226E+01,&
- 0.19817679E+01, 0.79709806E+01, 0.75400737E+01, 0.81804377E+01, 0.10564339E+02, 0.46896789E+02,-0.30926524E+01, 0.85742941E+00,&
- 0.19164038E+01, 0.23513199E+01, 0.25566644E+01, 0.26555181E+01, 0.87668459E-01, 0.83754276E-01, 0.80460283E-01, 0.77659686E-01,&
- 0.75257056E-01, 0.73179175E-01, 0.71369063E-01, 0.69781812E-01, 0.68381606E-01, 0.67139539E-01, 0.66032012E-01, 0.74878820E-01,&
- 0.71650966E-01, 0.68979615E-01, 0.66745345E-01, 0.64857571E-01, 0.63248495E-01, 0.61866970E-01, 0.60673632E-01, 0.59637277E-01,&
- 0.58732178E-01, 0.57936092E-01, 0.13230067E+02, 0.13213564E+02, 0.13209140E+02, 0.13213894E+02, 0.13225963E+02, 0.13243806E+02,&
- 0.13266104E+02, 0.13291782E+02, 0.13319961E+02, 0.13349927E+02, 0.13381108E+02, 0.13183816E+02, 0.13189991E+02, 0.13209485E+02,&
- 0.13238789E+02, 0.13275017E+02, 0.13316096E+02, 0.13360555E+02, 0.13407324E+02, 0.13455544E+02, 0.13504450E+02, 0.13553282E+02,&
--0.99506586E-03,-0.10184169E-02,-0.10404730E-02,-0.10621792E-02,-0.10847662E-02,-0.11094726E-02,-0.11372949E-02,-0.11687683E-02,&
--0.12038314E-02,-0.12418367E-02,-0.12817135E-02,-0.11661515E-02,-0.11886130E-02,-0.12139929E-02,-0.12445811E-02,-0.12807672E-02,&
--0.13208251E-02,-0.13619034E-02,-0.14014165E-02,-0.14378639E-02,-0.14708488E-02,-0.15006791E-02, 0.41243390E+00, 0.43407282E+00,&
- 0.45331413E+00, 0.47048604E+00, 0.48586286E+00, 0.49968044E+00, 0.51214132E+00, 0.52341830E+00, 0.53365803E+00, 0.54298448E+00,&
- 0.55150227E+00, 0.48318936E+00, 0.50501827E+00, 0.52409502E+00, 0.54085277E+00, 0.55565422E+00, 0.56878618E+00, 0.58047395E+00,&
- 0.59089894E+00, 0.60021475E+00, 0.60856112E+00, 0.61607594E+00,-0.22159303E-01,-0.22748917E-01,-0.23269898E-01,-0.23732392E-01,&
--0.24145123E-01,-0.24515269E-01,-0.24848690E-01,-0.25150210E-01,-0.25423873E-01,-0.25673139E-01,-0.25901055E-01,-0.24972399E-01,&
--0.25537247E-01,-0.26025624E-01,-0.26450280E-01,-0.26821236E-01,-0.27146657E-01,-0.27433354E-01,-0.27687065E-01,-0.27912608E-01,&
--0.28113944E-01,-0.28294180E-01, 0.80737799E+01, 0.79171158E+01, 0.77609605E+01, 0.76087371E+01, 0.74627112E+01, 0.73239981E+01,&
- 0.71929934E+01, 0.70697065E+01, 0.69539626E+01, 0.68455144E+01, 0.67441020E+01, 0.77425778E+01, 0.75443460E+01, 0.73526151E+01,&
- 0.71711188E+01, 0.70015571E+01, 0.68442532E+01, 0.66987996E+01, 0.65644820E+01, 0.64405267E+01, 0.63262376E+01, 0.62210701E+01,&
- 0.10542131E+02, 0.10515895E+02, 0.10492949E+02, 0.10472049E+02, 0.10452961E+02, 0.10435562E+02, 0.10419710E+02, 0.10405247E+02,&
- 0.10392022E+02, 0.10379892E+02, 0.10368736E+02, 0.10490353E+02, 0.10463512E+02, 0.10439183E+02, 0.10417324E+02, 0.10397704E+02,&
- 0.10380038E+02, 0.10364052E+02, 0.10349509E+02, 0.10336215E+02, 0.10324018E+02, 0.10312808E+02,-0.12823142E+01,-0.10571588E+01,&
--0.74864953E+00,-0.58705980E+00,-0.49305772E+00,-0.51461431E+00, 0.12373350E+02, 0.44809588E+00, 0.46548918E+00, 0.59121475E+00,&
- 0.74676119E+00,-0.74805226E+00,-0.56252739E+00,-0.46188072E+00,-0.40712065E+00,-0.15295996E+01, 0.43555255E+00, 0.50380874E+00,&
- 0.68537352E+00, 0.89437630E+00, 0.11127003E+01, 0.13329782E+01, 0.13845511E+01, 0.13187042E+01, 0.12644396E+01, 0.12191543E+01,&
- 0.11809511E+01, 0.11484154E+01, 0.11204723E+01, 0.10962918E+01, 0.10752229E+01, 0.10567474E+01, 0.10404465E+01, 0.11718758E+01,&
- 0.11216131E+01, 0.10809473E+01, 0.10476396E+01, 0.10200373E+01, 0.99692726E+00, 0.97740923E+00, 0.96080188E+00, 0.94657562E+00,&
- 0.93430511E+00, 0.92363528E+00, 0.22042132E+02, 0.22107298E+02, 0.22180915E+02, 0.22259478E+02, 0.22341039E+02, 0.22424247E+02,&
- 0.22508089E+02, 0.22591771E+02, 0.22674661E+02, 0.22756246E+02, 0.22836093E+02, 0.22169501E+02, 0.22270075E+02, 0.22379193E+02,&
- 0.22492992E+02, 0.22608508E+02, 0.22723843E+02, 0.22837837E+02, 0.22949751E+02, 0.23059032E+02, 0.23165146E+02, 0.23267456E+02,&
- 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00,&
- 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00,&
- 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00,&
- 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00,&
- 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00,&
- 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00,&
- 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00,&
- 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00,&
- 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00,&
- 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00,&
- 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00,&
- 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00,&
- 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00,&
- 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00,&
- 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00,&
- 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00,&
- 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00,&
- 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00,&
- 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00,&
- 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00,&
- 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00,&
- 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00 /) &
- , (/ 11,16,3 /) )
-
- real*8, dimension(11,16,3), parameter :: GB = reshape ( (/                                                                     &
- 0.63499072E-02, 0.65566348E-02, 0.67849730E-02, 0.70481947E-02, 0.73585943E-02, 0.77242818E-02, 0.81472693E-02, 0.86227527E-02,&
- 0.91396814E-02, 0.96825438E-02, 0.10233955E-01, 0.77266491E-02, 0.81323287E-02, 0.86507620E-02, 0.92776391E-02, 0.99806312E-02,&
- 0.10709803E-01, 0.11414739E-01, 0.12058772E-01, 0.12623992E-01, 0.13108146E-01, 0.13518390E-01, 0.11644593E+01, 0.11747203E+01,&
- 0.11837872E+01, 0.11918561E+01, 0.11990757E+01, 0.12055643E+01, 0.12114186E+01, 0.12167192E+01, 0.12215344E+01, 0.12259226E+01,&
- 0.12299344E+01, 0.12006968E+01, 0.12108196E+01, 0.12196717E+01, 0.12274493E+01, 0.12343189E+01, 0.12404147E+01, 0.12458431E+01,&
- 0.12506907E+01, 0.12550299E+01, 0.12589256E+01, 0.12624402E+01, 0.15750172E+00, 0.16174076E+00, 0.16548628E+00, 0.16881124E+00,&
- 0.17177839E+00, 0.17443933E+00, 0.17683622E+00, 0.17900375E+00, 0.18097099E+00, 0.18276283E+00, 0.18440117E+00, 0.17770551E+00,&
- 0.18176757E+00, 0.18527967E+00, 0.18833348E+00, 0.19100108E+00, 0.19334122E+00, 0.19540288E+00, 0.19722732E+00, 0.19884918E+00,&
- 0.20029696E+00, 0.20159300E+00, 0.10192131E+02, 0.97258602E+01, 0.92992890E+01, 0.89154021E+01, 0.85730084E+01, 0.82685838E+01,&
- 0.79978921E+01, 0.77568055E+01, 0.75416266E+01, 0.73491694E+01, 0.71767400E+01, 0.92439050E+01, 0.87567422E+01, 0.83270144E+01,&
- 0.79528337E+01, 0.76286839E+01, 0.73477879E+01, 0.71035818E+01, 0.68903312E+01, 0.67032875E+01, 0.65386461E+01, 0.63934377E+01,&
- 0.24870635E+02, 0.24725591E+02, 0.24600320E+02, 0.24487300E+02, 0.24384935E+02, 0.24292341E+02, 0.24208572E+02, 0.24132642E+02,&
- 0.24063614E+02, 0.24000649E+02, 0.23943021E+02, 0.24586283E+02, 0.24441465E+02, 0.24311657E+02, 0.24196167E+02, 0.24093406E+02,&
- 0.24001597E+02, 0.23919098E+02, 0.23844511E+02, 0.23776708E+02, 0.23714816E+02, 0.23658197E+02, 0.11990218E+02, 0.10904073E+02,&
- 0.89126838E+01, 0.85622405E+01, 0.94892164E+01, 0.13580937E+02,-0.32050918E+03,-0.37133165E+01, 0.18890836E+00, 0.14209226E+01,&
- 0.19817679E+01, 0.79709806E+01, 0.75400737E+01, 0.81804377E+01, 0.10564339E+02, 0.46896789E+02,-0.30926524E+01, 0.85742941E+00,&
- 0.19164038E+01, 0.23513199E+01, 0.25566644E+01, 0.26555181E+01, 0.87668459E-01, 0.83754276E-01, 0.80460283E-01, 0.77659686E-01,&
- 0.75257056E-01, 0.73179175E-01, 0.71369063E-01, 0.69781812E-01, 0.68381606E-01, 0.67139539E-01, 0.66032012E-01, 0.74878820E-01,&
- 0.71650966E-01, 0.68979615E-01, 0.66745345E-01, 0.64857571E-01, 0.63248495E-01, 0.61866970E-01, 0.60673632E-01, 0.59637277E-01,&
- 0.58732178E-01, 0.57936092E-01, 0.13230067E+02, 0.13213564E+02, 0.13209140E+02, 0.13213894E+02, 0.13225963E+02, 0.13243806E+02,&
- 0.13266104E+02, 0.13291782E+02, 0.13319961E+02, 0.13349927E+02, 0.13381108E+02, 0.13183816E+02, 0.13189991E+02, 0.13209485E+02,&
- 0.13238789E+02, 0.13275017E+02, 0.13316096E+02, 0.13360555E+02, 0.13407324E+02, 0.13455544E+02, 0.13504450E+02, 0.13553282E+02,&
- 0.97222852E-01, 0.98862238E-01, 0.10061504E+00, 0.10256222E+00, 0.10475952E+00, 0.10720986E+00, 0.10985370E+00, 0.11257633E+00,&
- 0.11522980E+00, 0.11766343E+00, 0.11975320E+00, 0.10681591E+00, 0.10921298E+00, 0.11198225E+00, 0.11487826E+00, 0.11751113E+00,&
- 0.11951535E+00, 0.12069945E+00, 0.12108524E+00, 0.12084229E+00, 0.12019005E+00, 0.11932684E+00, 0.10346097E+01, 0.10433655E+01,&
- 0.10511933E+01, 0.10582150E+01, 0.10645317E+01, 0.10702313E+01, 0.10753907E+01, 0.10800762E+01, 0.10843446E+01, 0.10882439E+01,&
- 0.10918144E+01, 0.10626130E+01, 0.10716026E+01, 0.10795108E+01, 0.10865006E+01, 0.10927103E+01, 0.10982489E+01, 0.11032019E+01,&
- 0.11076379E+01, 0.11116160E+01, 0.11151910E+01, 0.11184188E+01, 0.38103212E+00, 0.38913800E+00, 0.39613651E+00, 0.40222421E+00,&
- 0.40756010E+00, 0.41226954E+00, 0.41645142E+00, 0.42018474E+00, 0.42353379E+00, 0.42655211E+00, 0.42928533E+00, 0.41646579E+00,&
- 0.42345095E+00, 0.42937476E+00, 0.43444062E+00, 0.43880316E+00, 0.44258354E+00, 0.44587882E+00, 0.44876776E+00, 0.45131451E+00,&
- 0.45357095E+00, 0.45557797E+00, 0.82623280E+01, 0.81072291E+01, 0.79523834E+01, 0.78012527E+01, 0.76561458E+01, 0.75182174E+01,&
- 0.73878952E+01, 0.72652133E+01, 0.71500151E+01, 0.70420667E+01, 0.69411177E+01, 0.79342219E+01, 0.77373458E+01, 0.75467334E+01,&
- 0.73661786E+01, 0.71974319E+01, 0.70408543E+01, 0.68960649E+01, 0.67623672E+01, 0.66389989E+01, 0.65252707E+01, 0.64206412E+01,&
- 0.10656640E+02, 0.10630910E+02, 0.10608399E+02, 0.10587891E+02, 0.10569156E+02, 0.10552075E+02, 0.10536510E+02, 0.10522307E+02,&
- 0.10509317E+02, 0.10497402E+02, 0.10486443E+02, 0.10605856E+02, 0.10579514E+02, 0.10555632E+02, 0.10534169E+02, 0.10514900E+02,&
- 0.10497547E+02, 0.10481842E+02, 0.10467553E+02, 0.10454488E+02, 0.10442501E+02, 0.10431483E+02, 0.26681588E+02, 0.24728346E+02,&
- 0.20551342E+02, 0.19955244E+02, 0.22227100E+02, 0.31770288E+02,-0.74061287E+03,-0.81329826E+01, 0.90279822E+00, 0.37532746E+01,&
- 0.50437916E+01, 0.18377807E+02, 0.17643148E+02, 0.19296161E+02, 0.24951120E+02, 0.10957372E+03,-0.67432659E+01, 0.24550746E+01,&
- 0.49089917E+01, 0.59008712E+01, 0.63532616E+01, 0.65558627E+01, 0.23203798E+01, 0.22288925E+01, 0.21515593E+01, 0.20855896E+01,&
- 0.20288489E+01, 0.19796791E+01, 0.19367778E+01, 0.18991112E+01, 0.18658501E+01, 0.18363226E+01, 0.18099779E+01, 0.20206726E+01,&
- 0.19441824E+01, 0.18807257E+01, 0.18275618E+01, 0.17825910E+01, 0.17442308E+01, 0.17112809E+01, 0.16828137E+01, 0.16580908E+01,&
- 0.16365014E+01, 0.16175164E+01, 0.22051750E+02, 0.22116850E+02, 0.22190410E+02, 0.22268925E+02, 0.22350445E+02, 0.22433617E+02,&
- 0.22517429E+02, 0.22601086E+02, 0.22683956E+02, 0.22765522E+02, 0.22845354E+02, 0.22178972E+02, 0.22279484E+02, 0.22388551E+02,&
- 0.22502309E+02, 0.22617792E+02, 0.22733099E+02, 0.22847071E+02, 0.22958967E+02, 0.23068234E+02, 0.23174336E+02, 0.23276638E+02,&
- 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01,&
- 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01,&
- 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01,&
- 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01,&
- 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01,&
- 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01,&
- 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01,&
- 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01,&
- 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01,&
- 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01,&
- 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01,&
- 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01,&
- 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01,&
- 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01,&
- 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01,&
- 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01,&
- 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01,&
- 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01,&
- 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01,&
- 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01,&
- 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01,&
- 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01 /) &
-  , (/ 11,16,3 /) )
-
-      real*8, dimension(6,6), parameter :: XP = reshape ( (/  &
-      0.46430621E+02,  0.12928299E+03,  0.20732648E+03,  0.31398411E+03,  0.18373177E+03, -0.11412303E+03, &
-      0.73604774E+02,  0.27887914E+03,  0.27076947E+03, -0.57322111E+02, -0.64742459E+02,  0.87238280E+02, &
-      0.37050866E+02,  0.20498759E+03,  0.37558029E+03,  0.17401171E+03, -0.13350302E+03, -0.37651795E+02, &
-      0.14930141E+02,  0.89161160E+02,  0.17793062E+03,  0.93433860E+02, -0.70646020E+02, -0.26373150E+02, &
-      0.40386780E+02,  0.10855270E+03,  0.50755010E+02, -0.31496190E+02,  0.12791300E+00,  0.18017770E+01, &
-      0.90811926E+01,  0.75073923E+02,  0.24654438E+03,  0.39332612E+03,  0.29385281E+03,  0.89107921E+02 /) , (/ 6,6 /) )
-
-! If running with Reporbus type_trac=repr, values of RSUN might be overritten in radiation_AR4
-      REAL*8, dimension(2) :: RSUN = (/ 0.441676 , 0.558324 /)
-      REAL*8, dimension(2,6), parameter :: RRAY = reshape ( &
-         (/ .428937E-01, .697200E-02,&
-            .890743E+00, .173297E-01,&
-           -.288555E+01,-.850903E-01,&
-            .522744E+01, .248261E+00,&
-           -.469173E+01,-.302031E+00,&
-            .161645E+01, .129662E+00 /) , (/2,6/) )
-
-      REAL*8, dimension(2,5), parameter :: TAUA = reshape ( &
-      (/ 0.730719, 0.730719, 0.912819, 0.912819, 0.725059, &
-         0.725059, 0.745405, 0.745405, 0.682188, 0.682188 /),(/2,5/) )
-      REAL*8, dimension(2,5), parameter :: RPIZA = reshape ( &
-      (/ 0.872212, 0.872212, 0.982545, 0.982545, 0.623143,   &
-         0.623143, 0.944887, 0.944887, 0.997975, 0.997975 /),(/2,5/) )
-      REAL*8, dimension(2,5), parameter :: RCGA = reshape (  &
-      (/ 0.647596, 0.647596, 0.739002, 0.739002, 0.580845,   &
-         0.580845, 0.662657, 0.662657, 0.624246, 0.624246 /),(/2,5/) )
-
-      REAL*8, dimension(2,3,7), parameter :: APAD = reshape (  &
-          (/ 0.912418292E+05, 0.376655383E-08, 0.000000000E-00,&
-             0.739646016E-08, 0.925887084E-04, 0.410177786E+03,&
-             0.723613782E+05, 0.978576773E-04, 0.000000000E-00,&
-             0.131849595E-03, 0.129353723E-01, 0.672595424E+02,&
-             0.596037057E+04, 0.387714006E+00, 0.000000000E-00,&
-             0.437772681E+00, 0.800821928E+00, 0.000000000E-00,&
-             0.000000000E-00, 0.118461660E+03, 0.000000000E-00,&
-             0.151345118E+03, 0.242715973E+02, 0.000000000E-00,&
-             0.000000000E-00, 0.119079797E+04, 0.000000000E-00,&
-             0.233628890E+04, 0.878331486E+02, 0.000000000E-00,&
-             0.000000000E-00, 0.293353397E+03, 0.000000000E-00,&
-             0.797219934E+03, 0.191559725E+02, 0.000000000E-00,&
-             0.000000000E-00, 0.000000000E+00, 0.000000000E-00,&
-             0.000000000E+00, 0.000000000E+00, 0.000000000E+00 /) , (/2,3,7/) )
-      REAL*8, dimension(2,3,7), parameter :: BPAD = reshape (  &
-          (/ 0.912418292E+05, 0.376655383E-08, 0.000000000E-00,&
-             0.739646016E-08, 0.925887084E-04, 0.410177786E+03,&
-             0.724555318E+05, 0.979023421E-04, 0.000000000E-00,&
-             0.131861712E-03, 0.131812683E-01, 0.731185438E+02,&
-             0.602593328E+04, 0.388611139E+00, 0.000000000E-00,&
-             0.437949001E+00, 0.812706117E+00, 0.100000000E+01,&
-             0.100000000E+01, 0.120291383E+03, 0.000000000E-00,&
-             0.151692730E+03, 0.249863591E+02, 0.000000000E+00,&
-             0.000000000E-00, 0.130531005E+04, 0.000000000E-00,&
-             0.237071130E+04, 0.931071925E+02, 0.000000000E+00,&
-             0.000000000E-00, 0.415049409E+03, 0.000000000E-00,&
-             0.867914360E+03, 0.252233437E+02, 0.000000000E+00,&
-             0.000000000E-00, 0.100000000E+01, 0.000000000E-00,&
-             0.100000000E+01, 0.100000000E+01, 0.000000000E+00 /) , (/2,3,7/) )
-      REAL*8, dimension(2,3), parameter :: D = reshape ( &
-       (/ 0.0, 0.0, 0.0, 0.0, 0.0, 0.8 /) , (/2,3/) )
-
-      REAL*8, parameter :: TREF = 250.0
-      REAL*8, dimension(2), parameter :: RT1 = (/ -0.577350269, +0.577350269 /)
-      REAL*8, dimension(5,5), parameter :: RAER= reshape ( &
-        (/ .038520, .037196, .040532, .054934, .038520 &
-         , .12613 , .18313 , .10357 , .064106, .126130 &
-         , .012579, .013649, .018652, .025181, .012579 &
-         , .011890, .016142, .021105, .028908, .011890 &
-         , .013792, .026810, .052203, .066338, .013792 /) , (/5,5/) )
-
-      REAL*8, dimension(8,3), parameter :: AT= reshape ( &
-       (/ 0.298199E-02,0.143676E-01,0.197861E-01,0.289560E-01,&
-          0.103800E-01,0.868859E-02,0.250073E-03,0.307423E-01,&
-          -.394023E-03,0.366501E-02,0.315541E-02,-.208807E-02,&
-          0.436296E-02,-.972752E-03,0.455875E-03,0.110879E-02,&
-          0.319566E-04,-.160822E-02,-.174547E-02,-.121943E-02,&
-          -.161431E-02,0.000000E-00,0.109242E-03,-.322172E-03 /) , (/8,3/) )
-
-      REAL*8, dimension(8,3), parameter :: BT= reshape ( &
-       (/ -0.106432E-04,-0.553979E-04,-0.877012E-04,-0.165960E-03,&
-          -0.276744E-04,-0.278412E-04, 0.199846E-05,-0.108482E-03,&
-           0.660324E-06,-0.101701E-04, 0.513302E-04, 0.157704E-03,&
-          -0.327381E-04,-0.713940E-06,-0.216313E-05, 0.258096E-05,&
-           0.174356E-06, 0.920868E-05, 0.523138E-06,-0.146427E-04,&
-           0.127646E-04 ,0.117469E-05, 0.175991E-06,-0.814575E-06 /) , (/8,3/) )
-
-      REAL*8, dimension(4), parameter :: OCT = (/ -.326E-03, -.102E-05, .137E-02, -.535E-05 /)
-
- end module radiation_AR4_param
Index: LMDZ5/branches/testing/libf/phylmd/radiation_ar4_param.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/radiation_ar4_param.F90	(revision 1707)
+++ LMDZ5/branches/testing/libf/phylmd/radiation_ar4_param.F90	(revision 1707)
@@ -0,0 +1,241 @@
+MODULE radiation_ar4_param
+
+ REAL*8, parameter :: ZPDH2O = 0.8
+ REAL*8, parameter :: ZPDUMG = 0.75
+ REAL*8, parameter :: ZPRH2O = 30000.0
+ REAL*8, parameter :: ZPRUMG = 30000.0
+ REAL*8, parameter :: RTDH2O = 0.40
+ REAL*8, parameter :: RTDUMG = 0.375
+ REAL*8, parameter :: RTH2O = 240.0
+ REAL*8, parameter :: RTUMG = 240.0
+
+ REAL*8, dimension(2), parameter :: WG1 = (/1.0, 1.0/)
+ REAL*8, dimension(11), parameter :: TINTP = (/ 187.5, 200., 212.5, 225., 237.5, 250., 262.5, 275., 287.5, 300., 312.5 /)
+
+ real*8, dimension(11,16,3), parameter :: GA = reshape ( (/                                                                &
+ 0.63499072E-02, 0.65566348E-02, 0.67849730E-02, 0.70481947E-02, 0.73585943E-02, 0.77242818E-02, 0.81472693E-02, 0.86227527E-02,&
+ 0.91396814E-02, 0.96825438E-02, 0.10233955E-01, 0.77266491E-02, 0.81323287E-02, 0.86507620E-02, 0.92776391E-02, 0.99806312E-02,&
+ 0.10709803E-01, 0.11414739E-01, 0.12058772E-01, 0.12623992E-01, 0.13108146E-01, 0.13518390E-01, 0.11644593E+01, 0.11747203E+01,&
+ 0.11837872E+01, 0.11918561E+01, 0.11990757E+01, 0.12055643E+01, 0.12114186E+01, 0.12167192E+01, 0.12215344E+01, 0.12259226E+01,&
+ 0.12299344E+01, 0.12006968E+01, 0.12108196E+01, 0.12196717E+01, 0.12274493E+01, 0.12343189E+01, 0.12404147E+01, 0.12458431E+01,&
+ 0.12506907E+01, 0.12550299E+01, 0.12589256E+01, 0.12624402E+01, 0.15750172E+00, 0.16174076E+00, 0.16548628E+00, 0.16881124E+00,&
+ 0.17177839E+00, 0.17443933E+00, 0.17683622E+00, 0.17900375E+00, 0.18097099E+00, 0.18276283E+00, 0.18440117E+00, 0.17770551E+00,&
+ 0.18176757E+00, 0.18527967E+00, 0.18833348E+00, 0.19100108E+00, 0.19334122E+00, 0.19540288E+00, 0.19722732E+00, 0.19884918E+00,&
+ 0.20029696E+00, 0.20159300E+00, 0.10192131E+02, 0.97258602E+01, 0.92992890E+01, 0.89154021E+01, 0.85730084E+01, 0.82685838E+01,&
+ 0.79978921E+01, 0.77568055E+01, 0.75416266E+01, 0.73491694E+01, 0.71767400E+01, 0.92439050E+01, 0.87567422E+01, 0.83270144E+01,&
+ 0.79528337E+01, 0.76286839E+01, 0.73477879E+01, 0.71035818E+01, 0.68903312E+01, 0.67032875E+01, 0.65386461E+01, 0.63934377E+01,&
+ 0.24870635E+02, 0.24725591E+02, 0.24600320E+02, 0.24487300E+02, 0.24384935E+02, 0.24292341E+02, 0.24208572E+02, 0.24132642E+02,&
+ 0.24063614E+02, 0.24000649E+02, 0.23943021E+02, 0.24586283E+02, 0.24441465E+02, 0.24311657E+02, 0.24196167E+02, 0.24093406E+02,&
+ 0.24001597E+02, 0.23919098E+02, 0.23844511E+02, 0.23776708E+02, 0.23714816E+02, 0.23658197E+02, 0.11990218E+02, 0.10904073E+02,&
+ 0.89126838E+01, 0.85622405E+01, 0.94892164E+01, 0.13580937E+02,-0.32050918E+03,-0.37133165E+01, 0.18890836E+00, 0.14209226E+01,&
+ 0.19817679E+01, 0.79709806E+01, 0.75400737E+01, 0.81804377E+01, 0.10564339E+02, 0.46896789E+02,-0.30926524E+01, 0.85742941E+00,&
+ 0.19164038E+01, 0.23513199E+01, 0.25566644E+01, 0.26555181E+01, 0.87668459E-01, 0.83754276E-01, 0.80460283E-01, 0.77659686E-01,&
+ 0.75257056E-01, 0.73179175E-01, 0.71369063E-01, 0.69781812E-01, 0.68381606E-01, 0.67139539E-01, 0.66032012E-01, 0.74878820E-01,&
+ 0.71650966E-01, 0.68979615E-01, 0.66745345E-01, 0.64857571E-01, 0.63248495E-01, 0.61866970E-01, 0.60673632E-01, 0.59637277E-01,&
+ 0.58732178E-01, 0.57936092E-01, 0.13230067E+02, 0.13213564E+02, 0.13209140E+02, 0.13213894E+02, 0.13225963E+02, 0.13243806E+02,&
+ 0.13266104E+02, 0.13291782E+02, 0.13319961E+02, 0.13349927E+02, 0.13381108E+02, 0.13183816E+02, 0.13189991E+02, 0.13209485E+02,&
+ 0.13238789E+02, 0.13275017E+02, 0.13316096E+02, 0.13360555E+02, 0.13407324E+02, 0.13455544E+02, 0.13504450E+02, 0.13553282E+02,&
+-0.99506586E-03,-0.10184169E-02,-0.10404730E-02,-0.10621792E-02,-0.10847662E-02,-0.11094726E-02,-0.11372949E-02,-0.11687683E-02,&
+-0.12038314E-02,-0.12418367E-02,-0.12817135E-02,-0.11661515E-02,-0.11886130E-02,-0.12139929E-02,-0.12445811E-02,-0.12807672E-02,&
+-0.13208251E-02,-0.13619034E-02,-0.14014165E-02,-0.14378639E-02,-0.14708488E-02,-0.15006791E-02, 0.41243390E+00, 0.43407282E+00,&
+ 0.45331413E+00, 0.47048604E+00, 0.48586286E+00, 0.49968044E+00, 0.51214132E+00, 0.52341830E+00, 0.53365803E+00, 0.54298448E+00,&
+ 0.55150227E+00, 0.48318936E+00, 0.50501827E+00, 0.52409502E+00, 0.54085277E+00, 0.55565422E+00, 0.56878618E+00, 0.58047395E+00,&
+ 0.59089894E+00, 0.60021475E+00, 0.60856112E+00, 0.61607594E+00,-0.22159303E-01,-0.22748917E-01,-0.23269898E-01,-0.23732392E-01,&
+-0.24145123E-01,-0.24515269E-01,-0.24848690E-01,-0.25150210E-01,-0.25423873E-01,-0.25673139E-01,-0.25901055E-01,-0.24972399E-01,&
+-0.25537247E-01,-0.26025624E-01,-0.26450280E-01,-0.26821236E-01,-0.27146657E-01,-0.27433354E-01,-0.27687065E-01,-0.27912608E-01,&
+-0.28113944E-01,-0.28294180E-01, 0.80737799E+01, 0.79171158E+01, 0.77609605E+01, 0.76087371E+01, 0.74627112E+01, 0.73239981E+01,&
+ 0.71929934E+01, 0.70697065E+01, 0.69539626E+01, 0.68455144E+01, 0.67441020E+01, 0.77425778E+01, 0.75443460E+01, 0.73526151E+01,&
+ 0.71711188E+01, 0.70015571E+01, 0.68442532E+01, 0.66987996E+01, 0.65644820E+01, 0.64405267E+01, 0.63262376E+01, 0.62210701E+01,&
+ 0.10542131E+02, 0.10515895E+02, 0.10492949E+02, 0.10472049E+02, 0.10452961E+02, 0.10435562E+02, 0.10419710E+02, 0.10405247E+02,&
+ 0.10392022E+02, 0.10379892E+02, 0.10368736E+02, 0.10490353E+02, 0.10463512E+02, 0.10439183E+02, 0.10417324E+02, 0.10397704E+02,&
+ 0.10380038E+02, 0.10364052E+02, 0.10349509E+02, 0.10336215E+02, 0.10324018E+02, 0.10312808E+02,-0.12823142E+01,-0.10571588E+01,&
+-0.74864953E+00,-0.58705980E+00,-0.49305772E+00,-0.51461431E+00, 0.12373350E+02, 0.44809588E+00, 0.46548918E+00, 0.59121475E+00,&
+ 0.74676119E+00,-0.74805226E+00,-0.56252739E+00,-0.46188072E+00,-0.40712065E+00,-0.15295996E+01, 0.43555255E+00, 0.50380874E+00,&
+ 0.68537352E+00, 0.89437630E+00, 0.11127003E+01, 0.13329782E+01, 0.13845511E+01, 0.13187042E+01, 0.12644396E+01, 0.12191543E+01,&
+ 0.11809511E+01, 0.11484154E+01, 0.11204723E+01, 0.10962918E+01, 0.10752229E+01, 0.10567474E+01, 0.10404465E+01, 0.11718758E+01,&
+ 0.11216131E+01, 0.10809473E+01, 0.10476396E+01, 0.10200373E+01, 0.99692726E+00, 0.97740923E+00, 0.96080188E+00, 0.94657562E+00,&
+ 0.93430511E+00, 0.92363528E+00, 0.22042132E+02, 0.22107298E+02, 0.22180915E+02, 0.22259478E+02, 0.22341039E+02, 0.22424247E+02,&
+ 0.22508089E+02, 0.22591771E+02, 0.22674661E+02, 0.22756246E+02, 0.22836093E+02, 0.22169501E+02, 0.22270075E+02, 0.22379193E+02,&
+ 0.22492992E+02, 0.22608508E+02, 0.22723843E+02, 0.22837837E+02, 0.22949751E+02, 0.23059032E+02, 0.23165146E+02, 0.23267456E+02,&
+ 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00,&
+ 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00,&
+ 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00,&
+ 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00,&
+ 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00,&
+ 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00,&
+ 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00,&
+ 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00,&
+ 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00,&
+ 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00,&
+ 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00,&
+ 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00,&
+ 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00,&
+ 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00,&
+ 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00,&
+ 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00,&
+ 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00,&
+ 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00,&
+ 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00,&
+ 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00,&
+ 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00,&
+ 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00, 0.00000000E+00 /) &
+ , (/ 11,16,3 /) )
+
+ real*8, dimension(11,16,3), parameter :: GB = reshape ( (/                                                                     &
+ 0.63499072E-02, 0.65566348E-02, 0.67849730E-02, 0.70481947E-02, 0.73585943E-02, 0.77242818E-02, 0.81472693E-02, 0.86227527E-02,&
+ 0.91396814E-02, 0.96825438E-02, 0.10233955E-01, 0.77266491E-02, 0.81323287E-02, 0.86507620E-02, 0.92776391E-02, 0.99806312E-02,&
+ 0.10709803E-01, 0.11414739E-01, 0.12058772E-01, 0.12623992E-01, 0.13108146E-01, 0.13518390E-01, 0.11644593E+01, 0.11747203E+01,&
+ 0.11837872E+01, 0.11918561E+01, 0.11990757E+01, 0.12055643E+01, 0.12114186E+01, 0.12167192E+01, 0.12215344E+01, 0.12259226E+01,&
+ 0.12299344E+01, 0.12006968E+01, 0.12108196E+01, 0.12196717E+01, 0.12274493E+01, 0.12343189E+01, 0.12404147E+01, 0.12458431E+01,&
+ 0.12506907E+01, 0.12550299E+01, 0.12589256E+01, 0.12624402E+01, 0.15750172E+00, 0.16174076E+00, 0.16548628E+00, 0.16881124E+00,&
+ 0.17177839E+00, 0.17443933E+00, 0.17683622E+00, 0.17900375E+00, 0.18097099E+00, 0.18276283E+00, 0.18440117E+00, 0.17770551E+00,&
+ 0.18176757E+00, 0.18527967E+00, 0.18833348E+00, 0.19100108E+00, 0.19334122E+00, 0.19540288E+00, 0.19722732E+00, 0.19884918E+00,&
+ 0.20029696E+00, 0.20159300E+00, 0.10192131E+02, 0.97258602E+01, 0.92992890E+01, 0.89154021E+01, 0.85730084E+01, 0.82685838E+01,&
+ 0.79978921E+01, 0.77568055E+01, 0.75416266E+01, 0.73491694E+01, 0.71767400E+01, 0.92439050E+01, 0.87567422E+01, 0.83270144E+01,&
+ 0.79528337E+01, 0.76286839E+01, 0.73477879E+01, 0.71035818E+01, 0.68903312E+01, 0.67032875E+01, 0.65386461E+01, 0.63934377E+01,&
+ 0.24870635E+02, 0.24725591E+02, 0.24600320E+02, 0.24487300E+02, 0.24384935E+02, 0.24292341E+02, 0.24208572E+02, 0.24132642E+02,&
+ 0.24063614E+02, 0.24000649E+02, 0.23943021E+02, 0.24586283E+02, 0.24441465E+02, 0.24311657E+02, 0.24196167E+02, 0.24093406E+02,&
+ 0.24001597E+02, 0.23919098E+02, 0.23844511E+02, 0.23776708E+02, 0.23714816E+02, 0.23658197E+02, 0.11990218E+02, 0.10904073E+02,&
+ 0.89126838E+01, 0.85622405E+01, 0.94892164E+01, 0.13580937E+02,-0.32050918E+03,-0.37133165E+01, 0.18890836E+00, 0.14209226E+01,&
+ 0.19817679E+01, 0.79709806E+01, 0.75400737E+01, 0.81804377E+01, 0.10564339E+02, 0.46896789E+02,-0.30926524E+01, 0.85742941E+00,&
+ 0.19164038E+01, 0.23513199E+01, 0.25566644E+01, 0.26555181E+01, 0.87668459E-01, 0.83754276E-01, 0.80460283E-01, 0.77659686E-01,&
+ 0.75257056E-01, 0.73179175E-01, 0.71369063E-01, 0.69781812E-01, 0.68381606E-01, 0.67139539E-01, 0.66032012E-01, 0.74878820E-01,&
+ 0.71650966E-01, 0.68979615E-01, 0.66745345E-01, 0.64857571E-01, 0.63248495E-01, 0.61866970E-01, 0.60673632E-01, 0.59637277E-01,&
+ 0.58732178E-01, 0.57936092E-01, 0.13230067E+02, 0.13213564E+02, 0.13209140E+02, 0.13213894E+02, 0.13225963E+02, 0.13243806E+02,&
+ 0.13266104E+02, 0.13291782E+02, 0.13319961E+02, 0.13349927E+02, 0.13381108E+02, 0.13183816E+02, 0.13189991E+02, 0.13209485E+02,&
+ 0.13238789E+02, 0.13275017E+02, 0.13316096E+02, 0.13360555E+02, 0.13407324E+02, 0.13455544E+02, 0.13504450E+02, 0.13553282E+02,&
+ 0.97222852E-01, 0.98862238E-01, 0.10061504E+00, 0.10256222E+00, 0.10475952E+00, 0.10720986E+00, 0.10985370E+00, 0.11257633E+00,&
+ 0.11522980E+00, 0.11766343E+00, 0.11975320E+00, 0.10681591E+00, 0.10921298E+00, 0.11198225E+00, 0.11487826E+00, 0.11751113E+00,&
+ 0.11951535E+00, 0.12069945E+00, 0.12108524E+00, 0.12084229E+00, 0.12019005E+00, 0.11932684E+00, 0.10346097E+01, 0.10433655E+01,&
+ 0.10511933E+01, 0.10582150E+01, 0.10645317E+01, 0.10702313E+01, 0.10753907E+01, 0.10800762E+01, 0.10843446E+01, 0.10882439E+01,&
+ 0.10918144E+01, 0.10626130E+01, 0.10716026E+01, 0.10795108E+01, 0.10865006E+01, 0.10927103E+01, 0.10982489E+01, 0.11032019E+01,&
+ 0.11076379E+01, 0.11116160E+01, 0.11151910E+01, 0.11184188E+01, 0.38103212E+00, 0.38913800E+00, 0.39613651E+00, 0.40222421E+00,&
+ 0.40756010E+00, 0.41226954E+00, 0.41645142E+00, 0.42018474E+00, 0.42353379E+00, 0.42655211E+00, 0.42928533E+00, 0.41646579E+00,&
+ 0.42345095E+00, 0.42937476E+00, 0.43444062E+00, 0.43880316E+00, 0.44258354E+00, 0.44587882E+00, 0.44876776E+00, 0.45131451E+00,&
+ 0.45357095E+00, 0.45557797E+00, 0.82623280E+01, 0.81072291E+01, 0.79523834E+01, 0.78012527E+01, 0.76561458E+01, 0.75182174E+01,&
+ 0.73878952E+01, 0.72652133E+01, 0.71500151E+01, 0.70420667E+01, 0.69411177E+01, 0.79342219E+01, 0.77373458E+01, 0.75467334E+01,&
+ 0.73661786E+01, 0.71974319E+01, 0.70408543E+01, 0.68960649E+01, 0.67623672E+01, 0.66389989E+01, 0.65252707E+01, 0.64206412E+01,&
+ 0.10656640E+02, 0.10630910E+02, 0.10608399E+02, 0.10587891E+02, 0.10569156E+02, 0.10552075E+02, 0.10536510E+02, 0.10522307E+02,&
+ 0.10509317E+02, 0.10497402E+02, 0.10486443E+02, 0.10605856E+02, 0.10579514E+02, 0.10555632E+02, 0.10534169E+02, 0.10514900E+02,&
+ 0.10497547E+02, 0.10481842E+02, 0.10467553E+02, 0.10454488E+02, 0.10442501E+02, 0.10431483E+02, 0.26681588E+02, 0.24728346E+02,&
+ 0.20551342E+02, 0.19955244E+02, 0.22227100E+02, 0.31770288E+02,-0.74061287E+03,-0.81329826E+01, 0.90279822E+00, 0.37532746E+01,&
+ 0.50437916E+01, 0.18377807E+02, 0.17643148E+02, 0.19296161E+02, 0.24951120E+02, 0.10957372E+03,-0.67432659E+01, 0.24550746E+01,&
+ 0.49089917E+01, 0.59008712E+01, 0.63532616E+01, 0.65558627E+01, 0.23203798E+01, 0.22288925E+01, 0.21515593E+01, 0.20855896E+01,&
+ 0.20288489E+01, 0.19796791E+01, 0.19367778E+01, 0.18991112E+01, 0.18658501E+01, 0.18363226E+01, 0.18099779E+01, 0.20206726E+01,&
+ 0.19441824E+01, 0.18807257E+01, 0.18275618E+01, 0.17825910E+01, 0.17442308E+01, 0.17112809E+01, 0.16828137E+01, 0.16580908E+01,&
+ 0.16365014E+01, 0.16175164E+01, 0.22051750E+02, 0.22116850E+02, 0.22190410E+02, 0.22268925E+02, 0.22350445E+02, 0.22433617E+02,&
+ 0.22517429E+02, 0.22601086E+02, 0.22683956E+02, 0.22765522E+02, 0.22845354E+02, 0.22178972E+02, 0.22279484E+02, 0.22388551E+02,&
+ 0.22502309E+02, 0.22617792E+02, 0.22733099E+02, 0.22847071E+02, 0.22958967E+02, 0.23068234E+02, 0.23174336E+02, 0.23276638E+02,&
+ 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01,&
+ 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01,&
+ 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01,&
+ 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01,&
+ 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01,&
+ 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01,&
+ 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01,&
+ 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01,&
+ 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01,&
+ 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01,&
+ 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01,&
+ 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01,&
+ 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01,&
+ 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01,&
+ 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01,&
+ 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01,&
+ 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01,&
+ 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01,&
+ 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01,&
+ 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01,&
+ 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01,&
+ 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01, 0.10000000E+01 /) &
+  , (/ 11,16,3 /) )
+
+      real*8, dimension(6,6), parameter :: XP = reshape ( (/  &
+      0.46430621E+02,  0.12928299E+03,  0.20732648E+03,  0.31398411E+03,  0.18373177E+03, -0.11412303E+03, &
+      0.73604774E+02,  0.27887914E+03,  0.27076947E+03, -0.57322111E+02, -0.64742459E+02,  0.87238280E+02, &
+      0.37050866E+02,  0.20498759E+03,  0.37558029E+03,  0.17401171E+03, -0.13350302E+03, -0.37651795E+02, &
+      0.14930141E+02,  0.89161160E+02,  0.17793062E+03,  0.93433860E+02, -0.70646020E+02, -0.26373150E+02, &
+      0.40386780E+02,  0.10855270E+03,  0.50755010E+02, -0.31496190E+02,  0.12791300E+00,  0.18017770E+01, &
+      0.90811926E+01,  0.75073923E+02,  0.24654438E+03,  0.39332612E+03,  0.29385281E+03,  0.89107921E+02 /) , (/ 6,6 /) )
+
+! If running with Reporbus type_trac=repr, values of RSUN might be overritten in radiation_AR4
+      REAL*8, dimension(2) :: RSUN = (/ 0.441676 , 0.558324 /)
+      REAL*8, dimension(2,6), parameter :: RRAY = reshape ( &
+         (/ .428937E-01, .697200E-02,&
+            .890743E+00, .173297E-01,&
+           -.288555E+01,-.850903E-01,&
+            .522744E+01, .248261E+00,&
+           -.469173E+01,-.302031E+00,&
+            .161645E+01, .129662E+00 /) , (/2,6/) )
+
+      REAL*8, dimension(2,5), parameter :: TAUA = reshape ( &
+      (/ 0.730719, 0.730719, 0.912819, 0.912819, 0.725059, &
+         0.725059, 0.745405, 0.745405, 0.682188, 0.682188 /),(/2,5/) )
+      REAL*8, dimension(2,5), parameter :: RPIZA = reshape ( &
+      (/ 0.872212, 0.872212, 0.982545, 0.982545, 0.623143,   &
+         0.623143, 0.944887, 0.944887, 0.997975, 0.997975 /),(/2,5/) )
+      REAL*8, dimension(2,5), parameter :: RCGA = reshape (  &
+      (/ 0.647596, 0.647596, 0.739002, 0.739002, 0.580845,   &
+         0.580845, 0.662657, 0.662657, 0.624246, 0.624246 /),(/2,5/) )
+
+      REAL*8, dimension(2,3,7), parameter :: APAD = reshape (  &
+          (/ 0.912418292E+05, 0.376655383E-08, 0.000000000E-00,&
+             0.739646016E-08, 0.925887084E-04, 0.410177786E+03,&
+             0.723613782E+05, 0.978576773E-04, 0.000000000E-00,&
+             0.131849595E-03, 0.129353723E-01, 0.672595424E+02,&
+             0.596037057E+04, 0.387714006E+00, 0.000000000E-00,&
+             0.437772681E+00, 0.800821928E+00, 0.000000000E-00,&
+             0.000000000E-00, 0.118461660E+03, 0.000000000E-00,&
+             0.151345118E+03, 0.242715973E+02, 0.000000000E-00,&
+             0.000000000E-00, 0.119079797E+04, 0.000000000E-00,&
+             0.233628890E+04, 0.878331486E+02, 0.000000000E-00,&
+             0.000000000E-00, 0.293353397E+03, 0.000000000E-00,&
+             0.797219934E+03, 0.191559725E+02, 0.000000000E-00,&
+             0.000000000E-00, 0.000000000E+00, 0.000000000E-00,&
+             0.000000000E+00, 0.000000000E+00, 0.000000000E+00 /) , (/2,3,7/) )
+      REAL*8, dimension(2,3,7), parameter :: BPAD = reshape (  &
+          (/ 0.912418292E+05, 0.376655383E-08, 0.000000000E-00,&
+             0.739646016E-08, 0.925887084E-04, 0.410177786E+03,&
+             0.724555318E+05, 0.979023421E-04, 0.000000000E-00,&
+             0.131861712E-03, 0.131812683E-01, 0.731185438E+02,&
+             0.602593328E+04, 0.388611139E+00, 0.000000000E-00,&
+             0.437949001E+00, 0.812706117E+00, 0.100000000E+01,&
+             0.100000000E+01, 0.120291383E+03, 0.000000000E-00,&
+             0.151692730E+03, 0.249863591E+02, 0.000000000E+00,&
+             0.000000000E-00, 0.130531005E+04, 0.000000000E-00,&
+             0.237071130E+04, 0.931071925E+02, 0.000000000E+00,&
+             0.000000000E-00, 0.415049409E+03, 0.000000000E-00,&
+             0.867914360E+03, 0.252233437E+02, 0.000000000E+00,&
+             0.000000000E-00, 0.100000000E+01, 0.000000000E-00,&
+             0.100000000E+01, 0.100000000E+01, 0.000000000E+00 /) , (/2,3,7/) )
+      REAL*8, dimension(2,3), parameter :: D = reshape ( &
+       (/ 0.0, 0.0, 0.0, 0.0, 0.0, 0.8 /) , (/2,3/) )
+
+      REAL*8, parameter :: TREF = 250.0
+      REAL*8, dimension(2), parameter :: RT1 = (/ -0.577350269, +0.577350269 /)
+      REAL*8, dimension(5,5), parameter :: RAER= reshape ( &
+        (/ .038520, .037196, .040532, .054934, .038520 &
+         , .12613 , .18313 , .10357 , .064106, .126130 &
+         , .012579, .013649, .018652, .025181, .012579 &
+         , .011890, .016142, .021105, .028908, .011890 &
+         , .013792, .026810, .052203, .066338, .013792 /) , (/5,5/) )
+
+      REAL*8, dimension(8,3), parameter :: AT= reshape ( &
+       (/ 0.298199E-02,0.143676E-01,0.197861E-01,0.289560E-01,&
+          0.103800E-01,0.868859E-02,0.250073E-03,0.307423E-01,&
+          -.394023E-03,0.366501E-02,0.315541E-02,-.208807E-02,&
+          0.436296E-02,-.972752E-03,0.455875E-03,0.110879E-02,&
+          0.319566E-04,-.160822E-02,-.174547E-02,-.121943E-02,&
+          -.161431E-02,0.000000E-00,0.109242E-03,-.322172E-03 /) , (/8,3/) )
+
+      REAL*8, dimension(8,3), parameter :: BT= reshape ( &
+       (/ -0.106432E-04,-0.553979E-04,-0.877012E-04,-0.165960E-03,&
+          -0.276744E-04,-0.278412E-04, 0.199846E-05,-0.108482E-03,&
+           0.660324E-06,-0.101701E-04, 0.513302E-04, 0.157704E-03,&
+          -0.327381E-04,-0.713940E-06,-0.216313E-05, 0.258096E-05,&
+           0.174356E-06, 0.920868E-05, 0.523138E-06,-0.146427E-04,&
+           0.127646E-04 ,0.117469E-05, 0.175991E-06,-0.814575E-06 /) , (/8,3/) )
+
+      REAL*8, dimension(4), parameter :: OCT = (/ -.326E-03, -.102E-05, .137E-02, -.535E-05 /)
+
+ end module radiation_AR4_param
Index: LMDZ5/branches/testing/libf/phylmd/radlwsw.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/radlwsw.F90	(revision 1669)
+++ 	(revision )
@@ -1,477 +1,0 @@
-module radlwsw_m
-
-  IMPLICIT NONE
-
-contains
-
-SUBROUTINE radlwsw( &
-   dist, rmu0, fract, &
-   paprs, pplay,tsol,alb1, alb2, &
-   t,q,wo,&
-   cldfra, cldemi, cldtaupd,&
-   ok_ade, ok_aie, flag_aerosol,&
-   tau_aero, piz_aero, cg_aero,&
-   cldtaupi, new_aod, &
-   qsat, flwc, fiwc, &
-   heat,heat0,cool,cool0,radsol,albpla,&
-   topsw,toplw,solsw,sollw,&
-   sollwdown,&
-   topsw0,toplw0,solsw0,sollw0,&
-   lwdn0, lwdn, lwup0, lwup,&
-   swdn0, swdn, swup0, swup,&
-   topswad_aero, solswad_aero,&
-   topswai_aero, solswai_aero, &
-   topswad0_aero, solswad0_aero,&
-   topsw_aero, topsw0_aero,&
-   solsw_aero, solsw0_aero, &
-   topswcf_aero, solswcf_aero)
-
-
-
-  USE DIMPHY
-  USE assert_m, ONLY : assert
-  USE infotrac, ONLY : type_trac
-#ifdef REPROBUS
-  USE CHEM_REP, ONLY : solaireTIME, ok_SUNTIME, ndimozon
-#endif
-
-  !======================================================================
-  ! Auteur(s): Z.X. Li (LMD/CNRS) date: 19960719
-  ! Objet: interface entre le modele et les rayonnements
-  ! Arguments:
-  ! dist-----input-R- distance astronomique terre-soleil
-  ! rmu0-----input-R- cosinus de l'angle zenithal
-  ! fract----input-R- duree d'ensoleillement normalisee
-  ! co2_ppm--input-R- concentration du gaz carbonique (en ppm)
-  ! paprs----input-R- pression a inter-couche (Pa)
-  ! pplay----input-R- pression au milieu de couche (Pa)
-  ! tsol-----input-R- temperature du sol (en K)
-  ! alb1-----input-R- albedo du sol(entre 0 et 1) dans l'interval visible 
-  ! alb2-----input-R- albedo du sol(entre 0 et 1) dans l'interval proche infra-rouge   
-  ! t--------input-R- temperature (K)
-  ! q--------input-R- vapeur d'eau (en kg/kg)
-  ! cldfra---input-R- fraction nuageuse (entre 0 et 1)
-  ! cldtaupd---input-R- epaisseur optique des nuages dans le visible (present-day value)
-  ! cldemi---input-R- emissivite des nuages dans l'IR (entre 0 et 1)
-  ! ok_ade---input-L- apply the Aerosol Direct Effect or not?
-  ! ok_aie---input-L- apply the Aerosol Indirect Effect or not?
-  ! flag_aerosol-input-I- aerosol flag from 0 to 6
-  ! tau_ae, piz_ae, cg_ae-input-R- aerosol optical properties (calculated in aeropt.F)
-  ! cldtaupi-input-R- epaisseur optique des nuages dans le visible
-  !                   calculated for pre-industrial (pi) aerosol concentrations, i.e. with smaller
-  !                   droplet concentration, thus larger droplets, thus generally cdltaupi cldtaupd
-  !                   it is needed for the diagnostics of the aerosol indirect radiative forcing      
-  !
-  ! heat-----output-R- echauffement atmospherique (visible) (K/jour)
-  ! cool-----output-R- refroidissement dans l'IR (K/jour)
-  ! radsol---output-R- bilan radiatif net au sol (W/m**2) (+ vers le bas)
-  ! albpla---output-R- albedo planetaire (entre 0 et 1)
-  ! topsw----output-R- flux solaire net au sommet de l'atm.
-  ! toplw----output-R- ray. IR montant au sommet de l'atmosphere
-  ! solsw----output-R- flux solaire net a la surface
-  ! sollw----output-R- ray. IR montant a la surface
-  ! solswad---output-R- ray. solaire net absorbe a la surface (aerosol dir)
-  ! topswad---output-R- ray. solaire absorbe au sommet de l'atm. (aerosol dir)
-  ! solswai---output-R- ray. solaire net absorbe a la surface (aerosol ind)
-  ! topswai---output-R- ray. solaire absorbe au sommet de l'atm. (aerosol ind)
-  !
-  ! ATTENTION: swai and swad have to be interpreted in the following manner:
-  ! ---------
-  ! ok_ade=F & ok_aie=F -both are zero
-  ! ok_ade=T & ok_aie=F -aerosol direct forcing is F_{AD} = topsw-topswad
-  !                        indirect is zero
-  ! ok_ade=F & ok_aie=T -aerosol indirect forcing is F_{AI} = topsw-topswai
-  !                        direct is zero
-  ! ok_ade=T & ok_aie=T -aerosol indirect forcing is F_{AI} = topsw-topswai
-  !                        aerosol direct forcing is F_{AD} = topswai-topswad
-  !
-  
-  !======================================================================
-  
-  ! ====================================================================
-  ! Adapte au modele de chimie INCA par Celine Deandreis & Anne Cozic -- 2009
-  ! 1 = ZERO    
-  ! 2 = AER total    
-  ! 3 = NAT    
-  ! 4 = BC    
-  ! 5 = SO4    
-  ! 6 = POM    
-  ! 7 = DUST    
-  ! 8 = SS    
-  ! 9 = NO3    
-  ! 
-  ! ====================================================================
-  include "YOETHF.h"
-  include "YOMCST.h"
-  include "clesphys.h"
-  include "iniprint.h"
-
-! Input arguments
-  REAL,    INTENT(in)  :: dist
-  REAL,    INTENT(in)  :: rmu0(KLON), fract(KLON)
-  REAL,    INTENT(in)  :: paprs(KLON,KLEV+1), pplay(KLON,KLEV)
-  REAL,    INTENT(in)  :: alb1(KLON), alb2(KLON), tsol(KLON)
-  REAL,    INTENT(in)  :: t(KLON,KLEV), q(KLON,KLEV)
-
-  REAL, INTENT(in):: wo(:, :, :) ! dimension(KLON,KLEV, 1 or 2)
-  ! column-density of ozone in a layer, in kilo-Dobsons
-  ! "wo(:, :, 1)" is for the average day-night field, 
-  ! "wo(:, :, 2)" is for daylight time.
-
-  LOGICAL, INTENT(in)  :: ok_ade, ok_aie                                 ! switches whether to use aerosol direct (indirect) effects or not
-  INTEGER, INTENT(in)  :: flag_aerosol                                   ! takes value 0 (no aerosol) or 1 to 6 (aerosols)
-  REAL,    INTENT(in)  :: cldfra(KLON,KLEV), cldemi(KLON,KLEV), cldtaupd(KLON,KLEV)
-  REAL,    INTENT(in)  :: tau_aero(KLON,KLEV,9,2)                        ! aerosol optical properties (see aeropt.F)
-  REAL,    INTENT(in)  :: piz_aero(KLON,KLEV,9,2)                        ! aerosol optical properties (see aeropt.F)
-  REAL,    INTENT(in)  :: cg_aero(KLON,KLEV,9,2)                         ! aerosol optical properties (see aeropt.F)
-  REAL,    INTENT(in)  :: cldtaupi(KLON,KLEV)                            ! cloud optical thickness for pre-industrial aerosol concentrations
-  LOGICAL, INTENT(in)  :: new_aod                                        ! flag pour retrouver les resultats exacts de l'AR4 dans le cas ou l'on ne travaille qu'avec les sulfates
-  REAL,    INTENT(in)  :: qsat(klon,klev) ! Variable pour iflag_rrtm=1
-  REAL,    INTENT(in)  :: flwc(klon,klev) ! Variable pour iflag_rrtm=1
-  REAL,    INTENT(in)  :: fiwc(klon,klev) ! Variable pour iflag_rrtm=1
-
-! Output arguments
-  REAL,    INTENT(out) :: heat(KLON,KLEV), cool(KLON,KLEV)
-  REAL,    INTENT(out) :: heat0(KLON,KLEV), cool0(KLON,KLEV)
-  REAL,    INTENT(out) :: radsol(KLON), topsw(KLON), toplw(KLON)
-  REAL,    INTENT(out) :: solsw(KLON), sollw(KLON), albpla(KLON)
-  REAL,    INTENT(out) :: topsw0(KLON), toplw0(KLON), solsw0(KLON), sollw0(KLON)
-  REAL,    INTENT(out) :: sollwdown(KLON)
-  REAL,    INTENT(out) :: swdn(KLON,kflev+1),swdn0(KLON,kflev+1)
-  REAL,    INTENT(out) :: swup(KLON,kflev+1),swup0(KLON,kflev+1)
-  REAL,    INTENT(out) :: lwdn(KLON,kflev+1),lwdn0(KLON,kflev+1)
-  REAL,    INTENT(out) :: lwup(KLON,kflev+1),lwup0(KLON,kflev+1)
-  REAL,    INTENT(out) :: topswad_aero(KLON), solswad_aero(KLON)         ! output: aerosol direct forcing at TOA and surface
-  REAL,    INTENT(out) :: topswai_aero(KLON), solswai_aero(KLON)         ! output: aerosol indirect forcing atTOA and surface
-  REAL, DIMENSION(klon), INTENT(out)    :: topswad0_aero 
-  REAL, DIMENSION(klon), INTENT(out)    :: solswad0_aero
-  REAL, DIMENSION(kdlon,9), INTENT(out) :: topsw_aero
-  REAL, DIMENSION(kdlon,9), INTENT(out) :: topsw0_aero
-  REAL, DIMENSION(kdlon,9), INTENT(out) :: solsw_aero
-  REAL, DIMENSION(kdlon,9), INTENT(out) :: solsw0_aero
-  REAL, DIMENSION(kdlon,3), INTENT(out) :: topswcf_aero
-  REAL, DIMENSION(kdlon,3), INTENT(out) :: solswcf_aero
-
-! Local variables
-  REAL(KIND=8) ZFSUP(KDLON,KFLEV+1)
-  REAL(KIND=8) ZFSDN(KDLON,KFLEV+1)
-  REAL(KIND=8) ZFSUP0(KDLON,KFLEV+1)
-  REAL(KIND=8) ZFSDN0(KDLON,KFLEV+1)
-  REAL(KIND=8) ZFLUP(KDLON,KFLEV+1)
-  REAL(KIND=8) ZFLDN(KDLON,KFLEV+1)
-  REAL(KIND=8) ZFLUP0(KDLON,KFLEV+1)
-  REAL(KIND=8) ZFLDN0(KDLON,KFLEV+1)
-  REAL(KIND=8) zx_alpha1, zx_alpha2
-  INTEGER k, kk, i, j, iof, nb_gr
-  REAL(KIND=8) PSCT
-  REAL(KIND=8) PALBD(kdlon,2), PALBP(kdlon,2)
-  REAL(KIND=8) PEMIS(kdlon), PDT0(kdlon), PVIEW(kdlon)
-  REAL(KIND=8) PPSOL(kdlon), PDP(kdlon,KLEV)
-  REAL(KIND=8) PTL(kdlon,kflev+1), PPMB(kdlon,kflev+1)
-  REAL(KIND=8) PTAVE(kdlon,kflev)
-  REAL(KIND=8) PWV(kdlon,kflev), PQS(kdlon,kflev)
-
-  real(kind=8) POZON(kdlon, kflev, size(wo, 3)) ! mass fraction of ozone
-  ! "POZON(:, :, 1)" is for the average day-night field, 
-  ! "POZON(:, :, 2)" is for daylight time.
-
-  REAL(KIND=8) PAER(kdlon,kflev,5)
-  REAL(KIND=8) PCLDLD(kdlon,kflev)
-  REAL(KIND=8) PCLDLU(kdlon,kflev)
-  REAL(KIND=8) PCLDSW(kdlon,kflev)
-  REAL(KIND=8) PTAU(kdlon,2,kflev)
-  REAL(KIND=8) POMEGA(kdlon,2,kflev)
-  REAL(KIND=8) PCG(kdlon,2,kflev)
-  REAL(KIND=8) zfract(kdlon), zrmu0(kdlon), zdist
-  REAL(KIND=8) zheat(kdlon,kflev), zcool(kdlon,kflev)
-  REAL(KIND=8) zheat0(kdlon,kflev), zcool0(kdlon,kflev)
-  REAL(KIND=8) ztopsw(kdlon), ztoplw(kdlon)
-  REAL(KIND=8) zsolsw(kdlon), zsollw(kdlon), zalbpla(kdlon)
-  REAL(KIND=8) zsollwdown(kdlon)
-  REAL(KIND=8) ztopsw0(kdlon), ztoplw0(kdlon)
-  REAL(KIND=8) zsolsw0(kdlon), zsollw0(kdlon)
-  REAL(KIND=8) zznormcp
-  REAL(KIND=8) tauaero(kdlon,kflev,9,2)                     ! aer opt properties
-  REAL(KIND=8) pizaero(kdlon,kflev,9,2)
-  REAL(KIND=8) cgaero(kdlon,kflev,9,2)
-  REAL(KIND=8) PTAUA(kdlon,2,kflev)                         ! present-day value of cloud opt thickness (PTAU is pre-industrial value), local use
-  REAL(KIND=8) POMEGAA(kdlon,2,kflev)                       ! dito for single scatt albedo
-  REAL(KIND=8) ztopswadaero(kdlon), zsolswadaero(kdlon)     ! Aerosol direct forcing at TOAand surface
-  REAL(KIND=8) ztopswad0aero(kdlon), zsolswad0aero(kdlon)   ! Aerosol direct forcing at TOAand surface
-  REAL(KIND=8) ztopswaiaero(kdlon), zsolswaiaero(kdlon)     ! dito, indirect
-  REAL(KIND=8) ztopsw_aero(kdlon,9), ztopsw0_aero(kdlon,9)
-  REAL(KIND=8) zsolsw_aero(kdlon,9), zsolsw0_aero(kdlon,9)
-  REAL(KIND=8) ztopswcf_aero(kdlon,3), zsolswcf_aero(kdlon,3)     
-  real, parameter:: dobson_u = 2.1415e-05 ! Dobson unit, in kg m-2
-
-  call assert(size(wo, 1) == klon, size(wo, 2) == klev, "radlwsw wo")
-  ! initialisation
-  tauaero(:,:,:,:)=0.
-  pizaero(:,:,:,:)=0.
-  cgaero(:,:,:,:)=0.
-  
-  !
-  !-------------------------------------------
-  nb_gr = KLON / kdlon
-  IF (nb_gr*kdlon .NE. KLON) THEN
-      PRINT*, "kdlon mauvais:", KLON, kdlon, nb_gr
-      CALL abort
-  ENDIF
-  IF (kflev .NE. KLEV) THEN
-      PRINT*, "kflev differe de KLEV, kflev, KLEV"
-      CALL abort
-  ENDIF
-  !-------------------------------------------
-  DO k = 1, KLEV
-    DO i = 1, KLON
-      heat(i,k)=0.
-      cool(i,k)=0.
-      heat0(i,k)=0.
-      cool0(i,k)=0.
-    ENDDO
-  ENDDO
-  !
-  zdist = dist
-  !
-  PSCT = solaire/zdist/zdist
-
-  IF (type_trac == 'repr') THEN
-#ifdef REPROBUS
-     if(ok_SUNTIME) PSCT = solaireTIME/zdist/zdist
-     print*,'Constante solaire: ',PSCT*zdist*zdist
-#endif
-  END IF
-
-  DO j = 1, nb_gr
-    iof = kdlon*(j-1)
-    DO i = 1, kdlon
-      zfract(i) = fract(iof+i)
-      zrmu0(i) = rmu0(iof+i)
-      PALBD(i,1) = alb1(iof+i)
-      PALBD(i,2) = alb2(iof+i)
-      PALBP(i,1) = alb1(iof+i)
-      PALBP(i,2) = alb2(iof+i)
-      PEMIS(i) = 1.0 
-      PVIEW(i) = 1.66
-      PPSOL(i) = paprs(iof+i,1)
-      zx_alpha1 = (paprs(iof+i,1)-pplay(iof+i,2))/(pplay(iof+i,1)-pplay(iof+i,2))
-      zx_alpha2 = 1.0 - zx_alpha1
-      PTL(i,1) = t(iof+i,1) * zx_alpha1 + t(iof+i,2) * zx_alpha2
-      PTL(i,KLEV+1) = t(iof+i,KLEV)
-      PDT0(i) = tsol(iof+i) - PTL(i,1)
-    ENDDO
-    DO k = 2, kflev
-      DO i = 1, kdlon
-        PTL(i,k) = (t(iof+i,k)+t(iof+i,k-1))*0.5
-      ENDDO
-    ENDDO
-    DO k = 1, kflev
-      DO i = 1, kdlon
-        PDP(i,k) = paprs(iof+i,k)-paprs(iof+i,k+1)
-        PTAVE(i,k) = t(iof+i,k)
-        PWV(i,k) = MAX (q(iof+i,k), 1.0e-12)
-        PQS(i,k) = PWV(i,k)
-        POZON(i,k, :) = wo(iof+i, k, :) * RG * dobson_u * 1e3 &
-             / (paprs(iof+i, k) - paprs(iof+i, k+1))
-        PCLDLD(i,k) = cldfra(iof+i,k)*cldemi(iof+i,k)
-        PCLDLU(i,k) = cldfra(iof+i,k)*cldemi(iof+i,k)
-        PCLDSW(i,k) = cldfra(iof+i,k)
-        PTAU(i,1,k) = MAX(cldtaupi(iof+i,k), 1.0e-05)! 1e-12 serait instable
-        PTAU(i,2,k) = MAX(cldtaupi(iof+i,k), 1.0e-05)! pour 32-bit machines
-        POMEGA(i,1,k) = 0.9999 - 5.0e-04 * EXP(-0.5 * PTAU(i,1,k))
-        POMEGA(i,2,k) = 0.9988 - 2.5e-03 * EXP(-0.05 * PTAU(i,2,k))
-        PCG(i,1,k) = 0.865
-        PCG(i,2,k) = 0.910
-        !-
-        ! Introduced for aerosol indirect forcings.
-        ! The following values use the cloud optical thickness calculated from
-        ! present-day aerosol concentrations whereas the quantities without the
-        ! "A" at the end are for pre-industial (natural-only) aerosol concentrations
-        !
-        PTAUA(i,1,k) = MAX(cldtaupd(iof+i,k), 1.0e-05)! 1e-12 serait instable
-        PTAUA(i,2,k) = MAX(cldtaupd(iof+i,k), 1.0e-05)! pour 32-bit machines
-        POMEGAA(i,1,k) = 0.9999 - 5.0e-04 * EXP(-0.5 * PTAUA(i,1,k))
-        POMEGAA(i,2,k) = 0.9988 - 2.5e-03 * EXP(-0.05 * PTAUA(i,2,k))
-      ENDDO
-    ENDDO
-
-    IF (type_trac == 'repr') THEN
-#ifdef REPROBUS
-       ndimozon = size(wo, 3)
-       CALL RAD_INTERACTIF(POZON,iof)
-#endif
-    END IF
-
-    !
-    DO k = 1, kflev+1
-      DO i = 1, kdlon
-        PPMB(i,k) = paprs(iof+i,k)/100.0
-      ENDDO
-    ENDDO
-    !
-    DO kk = 1, 5
-      DO k = 1, kflev
-        DO i = 1, kdlon
-          PAER(i,k,kk) = 1.0E-15
-        ENDDO
-      ENDDO
-    ENDDO
-    DO k = 1, kflev
-      DO i = 1, kdlon
-        tauaero(i,k,:,1)=tau_aero(iof+i,k,:,1)
-        pizaero(i,k,:,1)=piz_aero(iof+i,k,:,1)
-        cgaero(i,k,:,1) =cg_aero(iof+i,k,:,1)
-        tauaero(i,k,:,2)=tau_aero(iof+i,k,:,2)
-        pizaero(i,k,:,2)=piz_aero(iof+i,k,:,2)
-        cgaero(i,k,:,2) =cg_aero(iof+i,k,:,2)
-      ENDDO
-    ENDDO
-
-!
-!===== iflag_rrtm ================================================
-!      
-    IF (iflag_rrtm == 0) THEN
-       ! Old radiation scheme, used for AR4 runs
-       ! average day-night ozone for longwave
-       CALL LW_LMDAR4(&
-            PPMB, PDP,&
-            PPSOL,PDT0,PEMIS,&
-            PTL, PTAVE, PWV, POZON(:, :, 1), PAER,&
-            PCLDLD,PCLDLU,&
-            PVIEW,&
-            zcool, zcool0,&
-            ztoplw,zsollw,ztoplw0,zsollw0,&
-            zsollwdown,&
-            ZFLUP, ZFLDN, ZFLUP0,ZFLDN0)
-
-       ! daylight ozone, if we have it, for short wave
-       IF (.NOT. new_aod) THEN 
-          ! use old version
-          CALL SW_LMDAR4(PSCT, zrmu0, zfract,&
-               PPMB, PDP, &
-               PPSOL, PALBD, PALBP,&
-               PTAVE, PWV, PQS, POZON(:, :, size(wo, 3)), PAER,&
-               PCLDSW, PTAU, POMEGA, PCG,&
-               zheat, zheat0,&
-               zalbpla,ztopsw,zsolsw,ztopsw0,zsolsw0,&
-               ZFSUP,ZFSDN,ZFSUP0,ZFSDN0,&
-               tauaero(:,:,5,:), pizaero(:,:,5,:), cgaero(:,:,5,:),& 
-               PTAUA, POMEGAA,&
-               ztopswadaero,zsolswadaero,&
-               ztopswaiaero,zsolswaiaero,& 
-               ok_ade, ok_aie, flag_aerosol) 
-          
-       ELSE ! new_aod=T         
-          CALL SW_AEROAR4(PSCT, zrmu0, zfract,&
-               PPMB, PDP,&
-               PPSOL, PALBD, PALBP,&
-               PTAVE, PWV, PQS, POZON(:, :, size(wo, 3)), PAER,&
-               PCLDSW, PTAU, POMEGA, PCG,&
-               zheat, zheat0,&
-               zalbpla,ztopsw,zsolsw,ztopsw0,zsolsw0,&
-               ZFSUP,ZFSDN,ZFSUP0,ZFSDN0,&
-               tauaero, pizaero, cgaero, &
-               PTAUA, POMEGAA,&
-               ztopswadaero,zsolswadaero,&
-               ztopswad0aero,zsolswad0aero,&
-               ztopswaiaero,zsolswaiaero, & 
-               ztopsw_aero,ztopsw0_aero,&
-               zsolsw_aero,zsolsw0_aero,&
-               ztopswcf_aero,zsolswcf_aero, & 
-               ok_ade, ok_aie, flag_aerosol) 
-       ENDIF
-
-    ELSE  
-!===== iflag_rrtm=1, on passe dans SW via RECMWFL ===============
-       WRITE(lunout,*) "Option iflag_rrtm=T ne fonctionne pas encore !!!"
-       CALL abort_gcm('radlwsw','iflag_rrtm=T not valid',1) 
-
-    ENDIF ! iflag_rrtm
-!======================================================================
-
-    DO i = 1, kdlon
-      radsol(iof+i) = zsolsw(i) + zsollw(i)
-      topsw(iof+i) = ztopsw(i)
-      toplw(iof+i) = ztoplw(i)
-      solsw(iof+i) = zsolsw(i)
-      sollw(iof+i) = zsollw(i)
-      sollwdown(iof+i) = zsollwdown(i)
-      DO k = 1, kflev+1
-        lwdn0 ( iof+i,k)   = ZFLDN0 ( i,k)
-        lwdn  ( iof+i,k)   = ZFLDN  ( i,k)
-        lwup0 ( iof+i,k)   = ZFLUP0 ( i,k)
-        lwup  ( iof+i,k)   = ZFLUP  ( i,k)
-      ENDDO
-      topsw0(iof+i) = ztopsw0(i)
-      toplw0(iof+i) = ztoplw0(i)
-      solsw0(iof+i) = zsolsw0(i)
-      sollw0(iof+i) = zsollw0(i)
-      albpla(iof+i) = zalbpla(i)
-
-      DO k = 1, kflev+1
-        swdn0 ( iof+i,k)   = ZFSDN0 ( i,k)
-        swdn  ( iof+i,k)   = ZFSDN  ( i,k)
-        swup0 ( iof+i,k)   = ZFSUP0 ( i,k)
-        swup  ( iof+i,k)   = ZFSUP  ( i,k)
-      ENDDO
-    ENDDO
-    !-transform the aerosol forcings, if they have
-    ! to be calculated
-    IF (ok_ade) THEN
-        DO i = 1, kdlon
-          topswad_aero(iof+i) = ztopswadaero(i)
-          topswad0_aero(iof+i) = ztopswad0aero(i)
-          solswad_aero(iof+i) = zsolswadaero(i)
-          solswad0_aero(iof+i) = zsolswad0aero(i)
-! MS the following lines seem to be wrong, why is iof on right hand side???
-!          topsw_aero(iof+i,:) = ztopsw_aero(iof+i,:)
-!          topsw0_aero(iof+i,:) = ztopsw0_aero(iof+i,:)
-!          solsw_aero(iof+i,:) = zsolsw_aero(iof+i,:)
-!          solsw0_aero(iof+i,:) = zsolsw0_aero(iof+i,:)
-          topsw_aero(iof+i,:) = ztopsw_aero(i,:)
-          topsw0_aero(iof+i,:) = ztopsw0_aero(i,:)
-          solsw_aero(iof+i,:) = zsolsw_aero(i,:)
-          solsw0_aero(iof+i,:) = zsolsw0_aero(i,:)
-          topswcf_aero(iof+i,:) = ztopswcf_aero(i,:)
-          solswcf_aero(iof+i,:) = zsolswcf_aero(i,:)          
-        ENDDO
-    ELSE
-        DO i = 1, kdlon
-          topswad_aero(iof+i) = 0.0
-          solswad_aero(iof+i) = 0.0
-          topswad0_aero(iof+i) = 0.0
-          solswad0_aero(iof+i) = 0.0
-          topsw_aero(iof+i,:) = 0.
-          topsw0_aero(iof+i,:) =0.
-          solsw_aero(iof+i,:) = 0.
-          solsw0_aero(iof+i,:) = 0.
-        ENDDO
-    ENDIF
-    IF (ok_aie) THEN
-        DO i = 1, kdlon
-          topswai_aero(iof+i) = ztopswaiaero(i)
-          solswai_aero(iof+i) = zsolswaiaero(i)
-        ENDDO
-    ELSE
-        DO i = 1, kdlon
-          topswai_aero(iof+i) = 0.0
-          solswai_aero(iof+i) = 0.0
-        ENDDO
-    ENDIF
-    DO k = 1, kflev
-      DO i = 1, kdlon
-        !        scale factor to take into account the difference between
-        !        dry air and watter vapour scpecifi! heat capacity
-        zznormcp=1.0+RVTMP2*PWV(i,k)
-        heat(iof+i,k) = zheat(i,k)/zznormcp
-        cool(iof+i,k) = zcool(i,k)/zznormcp
-        heat0(iof+i,k) = zheat0(i,k)/zznormcp
-        cool0(iof+i,k) = zcool0(i,k)/zznormcp
-      ENDDO
-    ENDDO
-
- ENDDO ! j = 1, nb_gr
-
-END SUBROUTINE radlwsw
-
-end module radlwsw_m
Index: LMDZ5/branches/testing/libf/phylmd/radlwsw_m.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/radlwsw_m.F90	(revision 1707)
+++ LMDZ5/branches/testing/libf/phylmd/radlwsw_m.F90	(revision 1707)
@@ -0,0 +1,477 @@
+module radlwsw_m
+
+  IMPLICIT NONE
+
+contains
+
+SUBROUTINE radlwsw( &
+   dist, rmu0, fract, &
+   paprs, pplay,tsol,alb1, alb2, &
+   t,q,wo,&
+   cldfra, cldemi, cldtaupd,&
+   ok_ade, ok_aie, flag_aerosol,&
+   tau_aero, piz_aero, cg_aero,&
+   cldtaupi, new_aod, &
+   qsat, flwc, fiwc, &
+   heat,heat0,cool,cool0,radsol,albpla,&
+   topsw,toplw,solsw,sollw,&
+   sollwdown,&
+   topsw0,toplw0,solsw0,sollw0,&
+   lwdn0, lwdn, lwup0, lwup,&
+   swdn0, swdn, swup0, swup,&
+   topswad_aero, solswad_aero,&
+   topswai_aero, solswai_aero, &
+   topswad0_aero, solswad0_aero,&
+   topsw_aero, topsw0_aero,&
+   solsw_aero, solsw0_aero, &
+   topswcf_aero, solswcf_aero)
+
+
+
+  USE DIMPHY
+  USE assert_m, ONLY : assert
+  USE infotrac, ONLY : type_trac
+#ifdef REPROBUS
+  USE CHEM_REP, ONLY : solaireTIME, ok_SUNTIME, ndimozon
+#endif
+
+  !======================================================================
+  ! Auteur(s): Z.X. Li (LMD/CNRS) date: 19960719
+  ! Objet: interface entre le modele et les rayonnements
+  ! Arguments:
+  ! dist-----input-R- distance astronomique terre-soleil
+  ! rmu0-----input-R- cosinus de l'angle zenithal
+  ! fract----input-R- duree d'ensoleillement normalisee
+  ! co2_ppm--input-R- concentration du gaz carbonique (en ppm)
+  ! paprs----input-R- pression a inter-couche (Pa)
+  ! pplay----input-R- pression au milieu de couche (Pa)
+  ! tsol-----input-R- temperature du sol (en K)
+  ! alb1-----input-R- albedo du sol(entre 0 et 1) dans l'interval visible 
+  ! alb2-----input-R- albedo du sol(entre 0 et 1) dans l'interval proche infra-rouge   
+  ! t--------input-R- temperature (K)
+  ! q--------input-R- vapeur d'eau (en kg/kg)
+  ! cldfra---input-R- fraction nuageuse (entre 0 et 1)
+  ! cldtaupd---input-R- epaisseur optique des nuages dans le visible (present-day value)
+  ! cldemi---input-R- emissivite des nuages dans l'IR (entre 0 et 1)
+  ! ok_ade---input-L- apply the Aerosol Direct Effect or not?
+  ! ok_aie---input-L- apply the Aerosol Indirect Effect or not?
+  ! flag_aerosol-input-I- aerosol flag from 0 to 6
+  ! tau_ae, piz_ae, cg_ae-input-R- aerosol optical properties (calculated in aeropt.F)
+  ! cldtaupi-input-R- epaisseur optique des nuages dans le visible
+  !                   calculated for pre-industrial (pi) aerosol concentrations, i.e. with smaller
+  !                   droplet concentration, thus larger droplets, thus generally cdltaupi cldtaupd
+  !                   it is needed for the diagnostics of the aerosol indirect radiative forcing      
+  !
+  ! heat-----output-R- echauffement atmospherique (visible) (K/jour)
+  ! cool-----output-R- refroidissement dans l'IR (K/jour)
+  ! radsol---output-R- bilan radiatif net au sol (W/m**2) (+ vers le bas)
+  ! albpla---output-R- albedo planetaire (entre 0 et 1)
+  ! topsw----output-R- flux solaire net au sommet de l'atm.
+  ! toplw----output-R- ray. IR montant au sommet de l'atmosphere
+  ! solsw----output-R- flux solaire net a la surface
+  ! sollw----output-R- ray. IR montant a la surface
+  ! solswad---output-R- ray. solaire net absorbe a la surface (aerosol dir)
+  ! topswad---output-R- ray. solaire absorbe au sommet de l'atm. (aerosol dir)
+  ! solswai---output-R- ray. solaire net absorbe a la surface (aerosol ind)
+  ! topswai---output-R- ray. solaire absorbe au sommet de l'atm. (aerosol ind)
+  !
+  ! ATTENTION: swai and swad have to be interpreted in the following manner:
+  ! ---------
+  ! ok_ade=F & ok_aie=F -both are zero
+  ! ok_ade=T & ok_aie=F -aerosol direct forcing is F_{AD} = topsw-topswad
+  !                        indirect is zero
+  ! ok_ade=F & ok_aie=T -aerosol indirect forcing is F_{AI} = topsw-topswai
+  !                        direct is zero
+  ! ok_ade=T & ok_aie=T -aerosol indirect forcing is F_{AI} = topsw-topswai
+  !                        aerosol direct forcing is F_{AD} = topswai-topswad
+  !
+  
+  !======================================================================
+  
+  ! ====================================================================
+  ! Adapte au modele de chimie INCA par Celine Deandreis & Anne Cozic -- 2009
+  ! 1 = ZERO    
+  ! 2 = AER total    
+  ! 3 = NAT    
+  ! 4 = BC    
+  ! 5 = SO4    
+  ! 6 = POM    
+  ! 7 = DUST    
+  ! 8 = SS    
+  ! 9 = NO3    
+  ! 
+  ! ====================================================================
+  include "YOETHF.h"
+  include "YOMCST.h"
+  include "clesphys.h"
+  include "iniprint.h"
+
+! Input arguments
+  REAL,    INTENT(in)  :: dist
+  REAL,    INTENT(in)  :: rmu0(KLON), fract(KLON)
+  REAL,    INTENT(in)  :: paprs(KLON,KLEV+1), pplay(KLON,KLEV)
+  REAL,    INTENT(in)  :: alb1(KLON), alb2(KLON), tsol(KLON)
+  REAL,    INTENT(in)  :: t(KLON,KLEV), q(KLON,KLEV)
+
+  REAL, INTENT(in):: wo(:, :, :) ! dimension(KLON,KLEV, 1 or 2)
+  ! column-density of ozone in a layer, in kilo-Dobsons
+  ! "wo(:, :, 1)" is for the average day-night field, 
+  ! "wo(:, :, 2)" is for daylight time.
+
+  LOGICAL, INTENT(in)  :: ok_ade, ok_aie                                 ! switches whether to use aerosol direct (indirect) effects or not
+  INTEGER, INTENT(in)  :: flag_aerosol                                   ! takes value 0 (no aerosol) or 1 to 6 (aerosols)
+  REAL,    INTENT(in)  :: cldfra(KLON,KLEV), cldemi(KLON,KLEV), cldtaupd(KLON,KLEV)
+  REAL,    INTENT(in)  :: tau_aero(KLON,KLEV,9,2)                        ! aerosol optical properties (see aeropt.F)
+  REAL,    INTENT(in)  :: piz_aero(KLON,KLEV,9,2)                        ! aerosol optical properties (see aeropt.F)
+  REAL,    INTENT(in)  :: cg_aero(KLON,KLEV,9,2)                         ! aerosol optical properties (see aeropt.F)
+  REAL,    INTENT(in)  :: cldtaupi(KLON,KLEV)                            ! cloud optical thickness for pre-industrial aerosol concentrations
+  LOGICAL, INTENT(in)  :: new_aod                                        ! flag pour retrouver les resultats exacts de l'AR4 dans le cas ou l'on ne travaille qu'avec les sulfates
+  REAL,    INTENT(in)  :: qsat(klon,klev) ! Variable pour iflag_rrtm=1
+  REAL,    INTENT(in)  :: flwc(klon,klev) ! Variable pour iflag_rrtm=1
+  REAL,    INTENT(in)  :: fiwc(klon,klev) ! Variable pour iflag_rrtm=1
+
+! Output arguments
+  REAL,    INTENT(out) :: heat(KLON,KLEV), cool(KLON,KLEV)
+  REAL,    INTENT(out) :: heat0(KLON,KLEV), cool0(KLON,KLEV)
+  REAL,    INTENT(out) :: radsol(KLON), topsw(KLON), toplw(KLON)
+  REAL,    INTENT(out) :: solsw(KLON), sollw(KLON), albpla(KLON)
+  REAL,    INTENT(out) :: topsw0(KLON), toplw0(KLON), solsw0(KLON), sollw0(KLON)
+  REAL,    INTENT(out) :: sollwdown(KLON)
+  REAL,    INTENT(out) :: swdn(KLON,kflev+1),swdn0(KLON,kflev+1)
+  REAL,    INTENT(out) :: swup(KLON,kflev+1),swup0(KLON,kflev+1)
+  REAL,    INTENT(out) :: lwdn(KLON,kflev+1),lwdn0(KLON,kflev+1)
+  REAL,    INTENT(out) :: lwup(KLON,kflev+1),lwup0(KLON,kflev+1)
+  REAL,    INTENT(out) :: topswad_aero(KLON), solswad_aero(KLON)         ! output: aerosol direct forcing at TOA and surface
+  REAL,    INTENT(out) :: topswai_aero(KLON), solswai_aero(KLON)         ! output: aerosol indirect forcing atTOA and surface
+  REAL, DIMENSION(klon), INTENT(out)    :: topswad0_aero 
+  REAL, DIMENSION(klon), INTENT(out)    :: solswad0_aero
+  REAL, DIMENSION(kdlon,9), INTENT(out) :: topsw_aero
+  REAL, DIMENSION(kdlon,9), INTENT(out) :: topsw0_aero
+  REAL, DIMENSION(kdlon,9), INTENT(out) :: solsw_aero
+  REAL, DIMENSION(kdlon,9), INTENT(out) :: solsw0_aero
+  REAL, DIMENSION(kdlon,3), INTENT(out) :: topswcf_aero
+  REAL, DIMENSION(kdlon,3), INTENT(out) :: solswcf_aero
+
+! Local variables
+  REAL(KIND=8) ZFSUP(KDLON,KFLEV+1)
+  REAL(KIND=8) ZFSDN(KDLON,KFLEV+1)
+  REAL(KIND=8) ZFSUP0(KDLON,KFLEV+1)
+  REAL(KIND=8) ZFSDN0(KDLON,KFLEV+1)
+  REAL(KIND=8) ZFLUP(KDLON,KFLEV+1)
+  REAL(KIND=8) ZFLDN(KDLON,KFLEV+1)
+  REAL(KIND=8) ZFLUP0(KDLON,KFLEV+1)
+  REAL(KIND=8) ZFLDN0(KDLON,KFLEV+1)
+  REAL(KIND=8) zx_alpha1, zx_alpha2
+  INTEGER k, kk, i, j, iof, nb_gr
+  REAL(KIND=8) PSCT
+  REAL(KIND=8) PALBD(kdlon,2), PALBP(kdlon,2)
+  REAL(KIND=8) PEMIS(kdlon), PDT0(kdlon), PVIEW(kdlon)
+  REAL(KIND=8) PPSOL(kdlon), PDP(kdlon,KLEV)
+  REAL(KIND=8) PTL(kdlon,kflev+1), PPMB(kdlon,kflev+1)
+  REAL(KIND=8) PTAVE(kdlon,kflev)
+  REAL(KIND=8) PWV(kdlon,kflev), PQS(kdlon,kflev)
+
+  real(kind=8) POZON(kdlon, kflev, size(wo, 3)) ! mass fraction of ozone
+  ! "POZON(:, :, 1)" is for the average day-night field, 
+  ! "POZON(:, :, 2)" is for daylight time.
+
+  REAL(KIND=8) PAER(kdlon,kflev,5)
+  REAL(KIND=8) PCLDLD(kdlon,kflev)
+  REAL(KIND=8) PCLDLU(kdlon,kflev)
+  REAL(KIND=8) PCLDSW(kdlon,kflev)
+  REAL(KIND=8) PTAU(kdlon,2,kflev)
+  REAL(KIND=8) POMEGA(kdlon,2,kflev)
+  REAL(KIND=8) PCG(kdlon,2,kflev)
+  REAL(KIND=8) zfract(kdlon), zrmu0(kdlon), zdist
+  REAL(KIND=8) zheat(kdlon,kflev), zcool(kdlon,kflev)
+  REAL(KIND=8) zheat0(kdlon,kflev), zcool0(kdlon,kflev)
+  REAL(KIND=8) ztopsw(kdlon), ztoplw(kdlon)
+  REAL(KIND=8) zsolsw(kdlon), zsollw(kdlon), zalbpla(kdlon)
+  REAL(KIND=8) zsollwdown(kdlon)
+  REAL(KIND=8) ztopsw0(kdlon), ztoplw0(kdlon)
+  REAL(KIND=8) zsolsw0(kdlon), zsollw0(kdlon)
+  REAL(KIND=8) zznormcp
+  REAL(KIND=8) tauaero(kdlon,kflev,9,2)                     ! aer opt properties
+  REAL(KIND=8) pizaero(kdlon,kflev,9,2)
+  REAL(KIND=8) cgaero(kdlon,kflev,9,2)
+  REAL(KIND=8) PTAUA(kdlon,2,kflev)                         ! present-day value of cloud opt thickness (PTAU is pre-industrial value), local use
+  REAL(KIND=8) POMEGAA(kdlon,2,kflev)                       ! dito for single scatt albedo
+  REAL(KIND=8) ztopswadaero(kdlon), zsolswadaero(kdlon)     ! Aerosol direct forcing at TOAand surface
+  REAL(KIND=8) ztopswad0aero(kdlon), zsolswad0aero(kdlon)   ! Aerosol direct forcing at TOAand surface
+  REAL(KIND=8) ztopswaiaero(kdlon), zsolswaiaero(kdlon)     ! dito, indirect
+  REAL(KIND=8) ztopsw_aero(kdlon,9), ztopsw0_aero(kdlon,9)
+  REAL(KIND=8) zsolsw_aero(kdlon,9), zsolsw0_aero(kdlon,9)
+  REAL(KIND=8) ztopswcf_aero(kdlon,3), zsolswcf_aero(kdlon,3)     
+  real, parameter:: dobson_u = 2.1415e-05 ! Dobson unit, in kg m-2
+
+  call assert(size(wo, 1) == klon, size(wo, 2) == klev, "radlwsw wo")
+  ! initialisation
+  tauaero(:,:,:,:)=0.
+  pizaero(:,:,:,:)=0.
+  cgaero(:,:,:,:)=0.
+  
+  !
+  !-------------------------------------------
+  nb_gr = KLON / kdlon
+  IF (nb_gr*kdlon .NE. KLON) THEN
+      PRINT*, "kdlon mauvais:", KLON, kdlon, nb_gr
+      CALL abort
+  ENDIF
+  IF (kflev .NE. KLEV) THEN
+      PRINT*, "kflev differe de KLEV, kflev, KLEV"
+      CALL abort
+  ENDIF
+  !-------------------------------------------
+  DO k = 1, KLEV
+    DO i = 1, KLON
+      heat(i,k)=0.
+      cool(i,k)=0.
+      heat0(i,k)=0.
+      cool0(i,k)=0.
+    ENDDO
+  ENDDO
+  !
+  zdist = dist
+  !
+  PSCT = solaire/zdist/zdist
+
+  IF (type_trac == 'repr') THEN
+#ifdef REPROBUS
+     if(ok_SUNTIME) PSCT = solaireTIME/zdist/zdist
+     print*,'Constante solaire: ',PSCT*zdist*zdist
+#endif
+  END IF
+
+  DO j = 1, nb_gr
+    iof = kdlon*(j-1)
+    DO i = 1, kdlon
+      zfract(i) = fract(iof+i)
+      zrmu0(i) = rmu0(iof+i)
+      PALBD(i,1) = alb1(iof+i)
+      PALBD(i,2) = alb2(iof+i)
+      PALBP(i,1) = alb1(iof+i)
+      PALBP(i,2) = alb2(iof+i)
+      PEMIS(i) = 1.0 
+      PVIEW(i) = 1.66
+      PPSOL(i) = paprs(iof+i,1)
+      zx_alpha1 = (paprs(iof+i,1)-pplay(iof+i,2))/(pplay(iof+i,1)-pplay(iof+i,2))
+      zx_alpha2 = 1.0 - zx_alpha1
+      PTL(i,1) = t(iof+i,1) * zx_alpha1 + t(iof+i,2) * zx_alpha2
+      PTL(i,KLEV+1) = t(iof+i,KLEV)
+      PDT0(i) = tsol(iof+i) - PTL(i,1)
+    ENDDO
+    DO k = 2, kflev
+      DO i = 1, kdlon
+        PTL(i,k) = (t(iof+i,k)+t(iof+i,k-1))*0.5
+      ENDDO
+    ENDDO
+    DO k = 1, kflev
+      DO i = 1, kdlon
+        PDP(i,k) = paprs(iof+i,k)-paprs(iof+i,k+1)
+        PTAVE(i,k) = t(iof+i,k)
+        PWV(i,k) = MAX (q(iof+i,k), 1.0e-12)
+        PQS(i,k) = PWV(i,k)
+        POZON(i,k, :) = wo(iof+i, k, :) * RG * dobson_u * 1e3 &
+             / (paprs(iof+i, k) - paprs(iof+i, k+1))
+        PCLDLD(i,k) = cldfra(iof+i,k)*cldemi(iof+i,k)
+        PCLDLU(i,k) = cldfra(iof+i,k)*cldemi(iof+i,k)
+        PCLDSW(i,k) = cldfra(iof+i,k)
+        PTAU(i,1,k) = MAX(cldtaupi(iof+i,k), 1.0e-05)! 1e-12 serait instable
+        PTAU(i,2,k) = MAX(cldtaupi(iof+i,k), 1.0e-05)! pour 32-bit machines
+        POMEGA(i,1,k) = 0.9999 - 5.0e-04 * EXP(-0.5 * PTAU(i,1,k))
+        POMEGA(i,2,k) = 0.9988 - 2.5e-03 * EXP(-0.05 * PTAU(i,2,k))
+        PCG(i,1,k) = 0.865
+        PCG(i,2,k) = 0.910
+        !-
+        ! Introduced for aerosol indirect forcings.
+        ! The following values use the cloud optical thickness calculated from
+        ! present-day aerosol concentrations whereas the quantities without the
+        ! "A" at the end are for pre-industial (natural-only) aerosol concentrations
+        !
+        PTAUA(i,1,k) = MAX(cldtaupd(iof+i,k), 1.0e-05)! 1e-12 serait instable
+        PTAUA(i,2,k) = MAX(cldtaupd(iof+i,k), 1.0e-05)! pour 32-bit machines
+        POMEGAA(i,1,k) = 0.9999 - 5.0e-04 * EXP(-0.5 * PTAUA(i,1,k))
+        POMEGAA(i,2,k) = 0.9988 - 2.5e-03 * EXP(-0.05 * PTAUA(i,2,k))
+      ENDDO
+    ENDDO
+
+    IF (type_trac == 'repr') THEN
+#ifdef REPROBUS
+       ndimozon = size(wo, 3)
+       CALL RAD_INTERACTIF(POZON,iof)
+#endif
+    END IF
+
+    !
+    DO k = 1, kflev+1
+      DO i = 1, kdlon
+        PPMB(i,k) = paprs(iof+i,k)/100.0
+      ENDDO
+    ENDDO
+    !
+    DO kk = 1, 5
+      DO k = 1, kflev
+        DO i = 1, kdlon
+          PAER(i,k,kk) = 1.0E-15
+        ENDDO
+      ENDDO
+    ENDDO
+    DO k = 1, kflev
+      DO i = 1, kdlon
+        tauaero(i,k,:,1)=tau_aero(iof+i,k,:,1)
+        pizaero(i,k,:,1)=piz_aero(iof+i,k,:,1)
+        cgaero(i,k,:,1) =cg_aero(iof+i,k,:,1)
+        tauaero(i,k,:,2)=tau_aero(iof+i,k,:,2)
+        pizaero(i,k,:,2)=piz_aero(iof+i,k,:,2)
+        cgaero(i,k,:,2) =cg_aero(iof+i,k,:,2)
+      ENDDO
+    ENDDO
+
+!
+!===== iflag_rrtm ================================================
+!      
+    IF (iflag_rrtm == 0) THEN
+       ! Old radiation scheme, used for AR4 runs
+       ! average day-night ozone for longwave
+       CALL LW_LMDAR4(&
+            PPMB, PDP,&
+            PPSOL,PDT0,PEMIS,&
+            PTL, PTAVE, PWV, POZON(:, :, 1), PAER,&
+            PCLDLD,PCLDLU,&
+            PVIEW,&
+            zcool, zcool0,&
+            ztoplw,zsollw,ztoplw0,zsollw0,&
+            zsollwdown,&
+            ZFLUP, ZFLDN, ZFLUP0,ZFLDN0)
+
+       ! daylight ozone, if we have it, for short wave
+       IF (.NOT. new_aod) THEN 
+          ! use old version
+          CALL SW_LMDAR4(PSCT, zrmu0, zfract,&
+               PPMB, PDP, &
+               PPSOL, PALBD, PALBP,&
+               PTAVE, PWV, PQS, POZON(:, :, size(wo, 3)), PAER,&
+               PCLDSW, PTAU, POMEGA, PCG,&
+               zheat, zheat0,&
+               zalbpla,ztopsw,zsolsw,ztopsw0,zsolsw0,&
+               ZFSUP,ZFSDN,ZFSUP0,ZFSDN0,&
+               tauaero(:,:,5,:), pizaero(:,:,5,:), cgaero(:,:,5,:),& 
+               PTAUA, POMEGAA,&
+               ztopswadaero,zsolswadaero,&
+               ztopswaiaero,zsolswaiaero,& 
+               ok_ade, ok_aie, flag_aerosol) 
+          
+       ELSE ! new_aod=T         
+          CALL SW_AEROAR4(PSCT, zrmu0, zfract,&
+               PPMB, PDP,&
+               PPSOL, PALBD, PALBP,&
+               PTAVE, PWV, PQS, POZON(:, :, size(wo, 3)), PAER,&
+               PCLDSW, PTAU, POMEGA, PCG,&
+               zheat, zheat0,&
+               zalbpla,ztopsw,zsolsw,ztopsw0,zsolsw0,&
+               ZFSUP,ZFSDN,ZFSUP0,ZFSDN0,&
+               tauaero, pizaero, cgaero, &
+               PTAUA, POMEGAA,&
+               ztopswadaero,zsolswadaero,&
+               ztopswad0aero,zsolswad0aero,&
+               ztopswaiaero,zsolswaiaero, & 
+               ztopsw_aero,ztopsw0_aero,&
+               zsolsw_aero,zsolsw0_aero,&
+               ztopswcf_aero,zsolswcf_aero, & 
+               ok_ade, ok_aie, flag_aerosol) 
+       ENDIF
+
+    ELSE  
+!===== iflag_rrtm=1, on passe dans SW via RECMWFL ===============
+       WRITE(lunout,*) "Option iflag_rrtm=T ne fonctionne pas encore !!!"
+       CALL abort_gcm('radlwsw','iflag_rrtm=T not valid',1) 
+
+    ENDIF ! iflag_rrtm
+!======================================================================
+
+    DO i = 1, kdlon
+      radsol(iof+i) = zsolsw(i) + zsollw(i)
+      topsw(iof+i) = ztopsw(i)
+      toplw(iof+i) = ztoplw(i)
+      solsw(iof+i) = zsolsw(i)
+      sollw(iof+i) = zsollw(i)
+      sollwdown(iof+i) = zsollwdown(i)
+      DO k = 1, kflev+1
+        lwdn0 ( iof+i,k)   = ZFLDN0 ( i,k)
+        lwdn  ( iof+i,k)   = ZFLDN  ( i,k)
+        lwup0 ( iof+i,k)   = ZFLUP0 ( i,k)
+        lwup  ( iof+i,k)   = ZFLUP  ( i,k)
+      ENDDO
+      topsw0(iof+i) = ztopsw0(i)
+      toplw0(iof+i) = ztoplw0(i)
+      solsw0(iof+i) = zsolsw0(i)
+      sollw0(iof+i) = zsollw0(i)
+      albpla(iof+i) = zalbpla(i)
+
+      DO k = 1, kflev+1
+        swdn0 ( iof+i,k)   = ZFSDN0 ( i,k)
+        swdn  ( iof+i,k)   = ZFSDN  ( i,k)
+        swup0 ( iof+i,k)   = ZFSUP0 ( i,k)
+        swup  ( iof+i,k)   = ZFSUP  ( i,k)
+      ENDDO
+    ENDDO
+    !-transform the aerosol forcings, if they have
+    ! to be calculated
+    IF (ok_ade) THEN
+        DO i = 1, kdlon
+          topswad_aero(iof+i) = ztopswadaero(i)
+          topswad0_aero(iof+i) = ztopswad0aero(i)
+          solswad_aero(iof+i) = zsolswadaero(i)
+          solswad0_aero(iof+i) = zsolswad0aero(i)
+! MS the following lines seem to be wrong, why is iof on right hand side???
+!          topsw_aero(iof+i,:) = ztopsw_aero(iof+i,:)
+!          topsw0_aero(iof+i,:) = ztopsw0_aero(iof+i,:)
+!          solsw_aero(iof+i,:) = zsolsw_aero(iof+i,:)
+!          solsw0_aero(iof+i,:) = zsolsw0_aero(iof+i,:)
+          topsw_aero(iof+i,:) = ztopsw_aero(i,:)
+          topsw0_aero(iof+i,:) = ztopsw0_aero(i,:)
+          solsw_aero(iof+i,:) = zsolsw_aero(i,:)
+          solsw0_aero(iof+i,:) = zsolsw0_aero(i,:)
+          topswcf_aero(iof+i,:) = ztopswcf_aero(i,:)
+          solswcf_aero(iof+i,:) = zsolswcf_aero(i,:)          
+        ENDDO
+    ELSE
+        DO i = 1, kdlon
+          topswad_aero(iof+i) = 0.0
+          solswad_aero(iof+i) = 0.0
+          topswad0_aero(iof+i) = 0.0
+          solswad0_aero(iof+i) = 0.0
+          topsw_aero(iof+i,:) = 0.
+          topsw0_aero(iof+i,:) =0.
+          solsw_aero(iof+i,:) = 0.
+          solsw0_aero(iof+i,:) = 0.
+        ENDDO
+    ENDIF
+    IF (ok_aie) THEN
+        DO i = 1, kdlon
+          topswai_aero(iof+i) = ztopswaiaero(i)
+          solswai_aero(iof+i) = zsolswaiaero(i)
+        ENDDO
+    ELSE
+        DO i = 1, kdlon
+          topswai_aero(iof+i) = 0.0
+          solswai_aero(iof+i) = 0.0
+        ENDDO
+    ENDIF
+    DO k = 1, kflev
+      DO i = 1, kdlon
+        !        scale factor to take into account the difference between
+        !        dry air and watter vapour scpecifi! heat capacity
+        zznormcp=1.0+RVTMP2*PWV(i,k)
+        heat(iof+i,k) = zheat(i,k)/zznormcp
+        cool(iof+i,k) = zcool(i,k)/zznormcp
+        heat0(iof+i,k) = zheat0(i,k)/zznormcp
+        cool0(iof+i,k) = zcool0(i,k)/zznormcp
+      ENDDO
+    ENDDO
+
+ ENDDO ! j = 1, nb_gr
+
+END SUBROUTINE radlwsw
+
+end module radlwsw_m
Index: LMDZ5/branches/testing/libf/phylmd/traclmdz_mod.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/traclmdz_mod.F90	(revision 1669)
+++ LMDZ5/branches/testing/libf/phylmd/traclmdz_mod.F90	(revision 1707)
@@ -279,4 +279,5 @@
   SUBROUTINE traclmdz(nstep, julien, gmtime, pdtphys, t_seri, paprs, pplay, &
        cdragh,  coefh, yu1, yv1, ftsol, pctsrf, xlat, xlon, couchelimite, sh, &
+       rh, pphi, ustar, zu10m, zv10m, &
        tr_seri, source, solsym, d_tr_cl, zmasse)
     
@@ -315,10 +316,15 @@
 !--------------
 !
-    REAL,DIMENSION(klon),INTENT(IN)      :: cdragh     ! coeff drag pour T et Q
-    REAL,DIMENSION(klon,klev),INTENT(IN) :: coefh      ! coeff melange CL (m**2/s)
-    REAL,DIMENSION(klon),INTENT(IN)      :: yu1        ! vents au premier niveau
-    REAL,DIMENSION(klon),INTENT(IN)      :: yv1        ! vents au premier niveau
+    REAL,DIMENSION(klon),INTENT(IN)      :: cdragh  ! coeff drag pour T et Q
+    REAL,DIMENSION(klon,klev),INTENT(IN) :: coefh   ! diffusivite turb (m**2/s)
+    REAL,DIMENSION(klon),INTENT(IN)      :: yu1     ! vents au premier niveau
+    REAL,DIMENSION(klon),INTENT(IN)      :: yv1     ! vents au premier niveau
     LOGICAL,INTENT(IN)                   :: couchelimite
-    REAL,DIMENSION(klon,klev),INTENT(IN) :: sh         ! humidite specifique
+    REAL,DIMENSION(klon,klev),INTENT(IN) :: sh      ! humidite specifique
+    REAL,DIMENSION(klon,klev),INTENT(IN) :: rh      ! Humidite relative
+    REAL,DIMENSION(klon,klev),INTENT(IN) :: pphi    ! geopotentie
+    REAL,DIMENSION(klon),INTENT(IN)      :: ustar   ! ustar (m/s)
+    REAL,DIMENSION(klon),INTENT(IN)      :: zu10m   ! vent zonal 10m (m/s)
+    REAL,DIMENSION(klon),INTENT(IN)      :: zv10m   ! vent zonal 10m (m/s)
 
 ! Arguments necessaires pour les sources et puits de traceur:
Index: LMDZ5/branches/testing/makegcm
===================================================================
--- LMDZ5/branches/testing/makegcm	(revision 1669)
+++ LMDZ5/branches/testing/makegcm	(revision 1707)
@@ -52,8 +52,8 @@
 #
 #
-setenv IOIPSLDIR /d4/fairhead/LMDZ20100928.trunk/modipsl/lib
-setenv MODIPSLDIR /d4/fairhead/LMDZ20100928.trunk/modipsl/lib
-setenv NCDFINC /d3/idelkadi/MODELE_LMDZ/LMDZ20121005.trunk/netcdf-4.0.1/include
-setenv NCDFLIB /d3/idelkadi/MODELE_LMDZ/LMDZ20121005.trunk/netcdf-4.0.1/lib
+setenv IOIPSLDIR /tmpdir/fairhead/Aqua/LMDZ20120327.trunk/modipsl/lib
+setenv MODIPSLDIR /tmpdir/fairhead/Aqua/LMDZ20120327.trunk/modipsl/lib
+setenv NCDFINC /tmpdir/fairhead/Aqua/LMDZ20120327.trunk/netcdf-4.0.1/include
+setenv NCDFLIB /tmpdir/fairhead/Aqua/LMDZ20120327.trunk/netcdf-4.0.1/lib
 
 
@@ -149,5 +149,5 @@
    set machine=ALPHA
    set DEC=1
-else if ( `uname` == Linux && `hostname` != mercure  && `hostname` != brodie ) then
+else if ( `uname` == Linux || `uname` == Darwin && `hostname` != mercure  && `hostname` != brodie ) then
    set machine=LINUX
    set LINUX=1
@@ -843,7 +843,7 @@
    else if ($FC_LINUX == 'g95' || $FC_LINUX == 'gfortran' ) then
      if ( $io == "ioipsl" ) then
-       set opt_link="$opt_link -L$MODIPSLDIR $link_veget -lioipsl -L$NCDFLIB -lnetcdf -lioipsl -lnetcdf "
+       set opt_link="$opt_link -L$MODIPSLDIR $link_veget -lioipsl -L$NCDFLIB -lnetcdff -lnetcdf -lioipsl -lnetcdff -lnetcdf "
      else
-       set opt_link="$opt_link -L$MODIPSLDIR $link_veget -lioipsl -L$NCDFLIB -lnetcdf -lnetcdf "
+       set opt_link="$opt_link -L$MODIPSLDIR $link_veget -lioipsl -L$NCDFLIB -lnetcdff -lnetcdf "
      endif
    endif
@@ -963,5 +963,5 @@
 set make="make RANLIB=ls"
 else if $LINUX then
-set make="make -k RANLIB=ranlib"
+set make="make -S RANLIB=ranlib"
 else if $XNEC then
 set make="gmake RANLIB=ls"
Index: LMDZ5/branches/testing/makelmdz
===================================================================
--- LMDZ5/branches/testing/makelmdz	(revision 1669)
+++ LMDZ5/branches/testing/makelmdz	(revision 1707)
@@ -1,5 +1,5 @@
 #!/bin/bash
 #
-# $Id $
+# $Id$
 #
 #
@@ -19,4 +19,5 @@
 chimie=false
 parallel=none
+paramem="par"
 compil_mod=prod
 io=ioipsl
@@ -26,5 +27,5 @@
 
 # guess a default 'arch'
-arch="g95" # start with assuming we're on a Linux/Unix machine with g95
+arch="local" # start with assuming we're on a local machine with local arch file
 ## try to recognise machine and infer arch from it
 machine=`hostname`
@@ -113,4 +114,5 @@
 [-cpp CPP_KEY]             : cle cpp supplementaires
 [-adjnt]                   : adjoint, a remettre en route ...
+[-mem]                     : version memoire reduite (si en mode parallele)
 [-filtre NOMFILTRE]        : prend le filtre dans libf/NOMFILTRE (def: filtrez)
 [-link LINKS]              : liens optionels avec d autres librairies
@@ -170,4 +172,7 @@
       "-cosp")
           cosp="$2" ; shift ; shift ;;
+      
+      "-mem")
+          paramem="mem" ; shift ;;
 
       "-filtre")
@@ -273,6 +278,11 @@
 if [[ "$physique" != "nophys" ]]
 then
-   #Default planet type is Earth
+   #We'll use some physics
+   CPP_KEY="$CPP_KEY CPP_PHYS"
+   if [[ "${physique:0:3}" == "lmd" ]]
+   then
+   #For lmd physics, default planet type is Earth
    CPP_KEY="$CPP_KEY CPP_EARTH"
+   fi
 fi
 
@@ -387,4 +397,22 @@
 ########################################################################
 
+cd $LIBFGCM/grid
+if [[ -f dimensions.h ]]
+then
+  echo 'ATTENTION: vous etes sans doute en train de compiler le modele par ailleurs'
+  echo "Attendez que la premiere compilation soit terminee pour relancer la suivante."
+  echo "Si vous etes sur que vous ne compilez pas le modele par ailleurs,"
+  echo  vous pouvez continuer en repondant oui.
+  echo "Voulez-vous vraiment continuer?"
+  read reponse
+  if [[ $reponse == "oui" ]]
+  then
+    \rm -f $LIBFGCM/grid/dimensions.h
+  else
+    exit
+  fi
+fi
+
+
 cd $LIBFGCM/grid/dimension
 ./makdim $dim
@@ -435,5 +463,9 @@
 then
   SUFF_NAME=${SUFF_NAME}_para
-  DYN=dyn${dimc}dpar
+  DYN=dyn${dimc}d${paramem}
+  if [[ "$paramem" == "mem" ]]
+  then
+   SUFF_NAME=${SUFF_NAME}_${paramem}
+  fi
 else
   SUFF_NAME=${SUFF_NAME}_seq
@@ -600,7 +632,7 @@
 PROG=$code
 
-if [[ -r $libf/grid/dimensions.h ]]
+if [[ -r $LIBFGCM/grid/dimensions.h ]]
 then
   # Cleanup: remove dimension.h file
-  \rm -f $libf/grid/dimensions.h
-fi
+  \rm -f $LIBFGCM/grid/dimensions.h
+fi
Index: LMDZ5/branches/testing/makelmdz_fcm
===================================================================
--- LMDZ5/branches/testing/makelmdz_fcm	(revision 1669)
+++ LMDZ5/branches/testing/makelmdz_fcm	(revision 1707)
@@ -24,4 +24,5 @@
 chimie=false
 parallel=none
+paramem="par"
 compil_mod=prod
 io=ioipsl
@@ -72,4 +73,5 @@
 [-cpp CPP_KEY]             : cle cpp supplementaires
 [-adjnt]                   : adjoint, a remettre en route ...
+[-mem]                     : version memoire reduite (si en mode parallele)
 [-filtre NOMFILTRE]        : prend le filtre dans libf/NOMFILTRE (def: filtrez)
 [-link LINKS]              : liens optionels avec d'autres librairies
@@ -125,5 +127,5 @@
 
       "-adjnt")
-	  echo "otpion a reactiver ";exit
+	  echo "option a reactiver ";exit
 	  opt_dep="$opt_dep adjnt" ; adjnt="-ladjnt -ldyn3d "
 	  optim="$optim -Dadj" ; shift ;;
@@ -131,5 +133,7 @@
       "-cosp")
           cosp="$2" ; shift ; shift ;;
-
+      
+      "-mem")
+          paramem="mem" ; shift ;;
 
       "-filtre")
@@ -278,4 +282,22 @@
 # on cree ou remplace le fichier des dimensions
 ########################################################################
+
+cd $LIBFGCM/grid
+if [[ -f dimensions.h ]]
+then
+  echo 'ATTENTION: vous etes sans doute en train de compiler le modele par ailleurs'
+  echo "Attendez que la premiere compilation soit terminee pour relancer la suivante."
+  echo "Si vous etes sur que vous ne compilez pas le modele par ailleurs,"
+  echo  vous pouvez continuer en repondant oui.
+  echo "Voulez-vous vraiment continuer?"
+  read reponse
+  if [[ $reponse == "oui" ]]
+  then
+    \rm -f $LIBFGCM/grid/dimensions.h
+  else
+    exit
+  fi
+fi
+
 
 cd $LIBFGCM/grid/dimension
@@ -349,5 +371,9 @@
 then
   SUFF_NAME=${SUFF_NAME}_para
-  DYN=dyn${dimc}dpar
+  DYN=dyn${dimc}d${paramem}
+  if [[ "$paramem" == "mem" ]]
+  then
+   SUFF_NAME=${SUFF_NAME}_${paramem}
+  fi
 else
   SUFF_NAME=${SUFF_NAME}_seq
@@ -413,2 +439,8 @@
 ln -s $LIBOGCM/${arch}${SUFF_NAME}/.config config
 ln -s $LIBOGCM/${arch}${SUFF_NAME}/.config/tmp tmp_src
+
+if [[ -r $LIBFGCM/grid/dimensions.h ]]
+then
+  # Cleanup: remove dimension.h file
+  \rm -f $LIBFGCM/grid/dimensions.h
+fi
Index: LMDZ5/branches/testing/tools/install_1d_src.sh
===================================================================
--- LMDZ5/branches/testing/tools/install_1d_src.sh	(revision 1707)
+++ LMDZ5/branches/testing/tools/install_1d_src.sh	(revision 1707)
@@ -0,0 +1,63 @@
+# This is a script in Bash.
+
+# This script installs the source files of LMDZ 1D. Run this script
+# from "libf".
+
+set -xe
+
+# cp --no-clobber phylmd/* phy1d:
+cd phylmd
+set +x
+for my_file in *
+  do
+  if [[ ! -a ../phy1d/$my_file ]]
+      then
+      cp $my_file ../phy1d
+  fi
+done
+set -x
+
+cd ../phy1d
+if grep -iq "subroutine *writelim" *.F *.F90
+    then
+    mv 1DUTILS.h_no_writelim 1DUTILS.h
+else
+    mv 1DUTILS.h_with_writelim 1DUTILS.h
+    rm -f ttt
+    sed -e "s/^ *call *writelim *( *1 *,/      call writelim (/" lmdz1d.F >ttt
+    rm -f lmdz1d.F
+    mv ttt lmdz1d.F
+fi
+rm 1DUTILS.h*writelim
+rm wrgradsfi.F # already in 1DUTILS.h
+
+sed -i -e "/add_phys_tend.*_vdf/s/add_phys_tend/add_pbl_tend/" physiq.F
+
+sed -i -e "/SUBROUTINE *convers_timesteps/,/END SUBROUTINE convers_timesteps/{
+ /USE *phys_cal_mod/d
+ /use *ioipsl/a\\
+    USE phys_cal_mod
+ s/ioget_mon_len(annee_ref,day_ref)/mth_len/
+};/SUBROUTINE *phys_output_open/,/end *subroutine *phys_output_open/{
+ /USE *ioipsl/a\\
+  USE phys_cal_mod, only : hour
+ /ymds2ju.*annee_ref.*zjulian/c\\
+!!!      CALL ymds2ju(annee_ref, 1, idayref, 0.0, zjulian)       !jyg \\
+! correction pour l heure initiale                               !jyg \\
+!                                                                !jyg \\
+      CALL ymds2ju(annee_ref, 1, idayref, hour, zjulian)         !jyg
+}" phys_output_mod.F90
+
+sed -i -e "/^ *INCLUDE *\"temps.h\"/{
+ a\\
+!****************************************************************************************\\
+! Declarations specifiques pour le 1D. A reprendre \\
+    INCLUDE \"flux_arp.h\"
+ }; /^.*REAL *::.*fsens *, *flat/d; /^.*LOGICAL *::.*ok_flux_surf/d; /^.*COMMON.*flux_arp.*/d " pbl_surface_mod.F90
+
+ ln -s ../dyn3d/mod_const_mpi.F90 .
+ ln -s ../dyn3d/infotrac.F90 .
+ ln -s ../dyn3d/conf_gcm.F .
+ ln -s ../dyn3d/pres2lev.F90 .
+ ln -s ../dyn3d/control_mod.F90 .
+ ln -s ../dyn3d/q_sat.F .
