Index: /branches/ORCHIDEE_EXT/ORCHIDEE/AA_make
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/AA_make	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/AA_make	(revision 257)
@@ -1,4 +1,4 @@
-#- $Id: AA_make,v 1.4 2007/09/20 13:32:32 ssipsl Exp $
-all : libparameters libparallel liborglob libstomate libsechiba
+#- $Id: AA_make 41 2011-01-01 19:56:53Z mmaipsl $
+all : libparallel libparameters liborglob libstomate libsechiba
 
 libparameters :
Index: /branches/ORCHIDEE_EXT/ORCHIDEE/AA_make.ldef
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/AA_make.ldef	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/AA_make.ldef	(revision 257)
@@ -1,3 +1,3 @@
-#- $Id: AA_make.ldef,v 1.1 2007/06/21 09:11:58 ssipsl Exp $
+#- $Id: AA_make.ldef 12 2010-11-05 15:42:13Z mmaipsl $
 #---------------------------------------------------------------------
 #-
Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_global/AA_make
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_global/AA_make	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_global/AA_make	(revision 257)
@@ -1,4 +1,4 @@
 #-
-#- $Id: AA_make,v 1.5 2010/04/06 14:26:07 ssipsl Exp $
+#- $Id: AA_make 41 2011-01-01 19:56:53Z mmaipsl $
 #-
 PARAM_LIB = $(LIBDIR)/libparameters.a
@@ -21,4 +21,5 @@
 #-
 all:
+	$(M_K) libparallel
 	$(M_K) libparameters
 	$(M_K) m_all
@@ -26,4 +27,7 @@
 
 m_all: $(MODEL_LIB)($(OBJSMODS1))
+
+libparallel:
+	(cd ../src_parallel; $(M_K) -f Makefile)
 
 libparameters:
Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_global/AA_make.ldef
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_global/AA_make.ldef	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_global/AA_make.ldef	(revision 257)
@@ -1,4 +1,4 @@
 #-
-#- $Id: AA_make.ldef,v 1.2 2008/01/08 11:49:07 ssipsl Exp $
+#- $Id: AA_make.ldef 12 2010-11-05 15:42:13Z mmaipsl $
 #-
 #---------------------------------------------------------------------
Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_global/grid.f90
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_global/grid.f90	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_global/grid.f90	(revision 257)
@@ -4,6 +4,11 @@
 !! @call sechiba_main
 !! @Version : $Revision: 1.8 $, $Date: 2009/01/28 08:32:45 $
+!! @Version : $Revision: 42 $, $Date: 2011-01-01 21:15:03 +0100 (Sat, 01 Jan 2011) $
 !! 
 !! $Header: /home/ssipsl/CVSREP/ORCHIDEE/src_global/grid.f90,v 1.8 2009/01/28 08:32:45 ssipsl Exp $
+!< $HeadURL: http://forge.ipsl.jussieu.fr/orchidee/svn/trunk/ORCHIDEE/src_global/grid.f90 $
+!< $Date: 2011-01-01 21:15:03 +0100 (Sat, 01 Jan 2011) $
+!< $Author: mmaipsl $
+!< $Revision: 42 $
 !!
 !! @author Marie-Alice Foujols, Jan Polcher and Martial Mancip
@@ -23,5 +28,4 @@
   ! default resolution (m)
   REAL(r_std), PARAMETER :: default_resolution = 250000.
-  !
   !
   ! VARIABLES
@@ -189,6 +193,4 @@
     ! =========================================================================
     
-
-
     IF ( bavard .GE. 4 ) WRITE(numout,*) 'Entering grid_stuff'
 
@@ -239,7 +241,7 @@
        ! initialize output
        neighbours_g(:,:) = -1
-       resolution_g(:,:) = 0.
+       resolution_g(:,:) = zero
        min_resol(:) = 1.e6
-       max_resol(:) = -1.
+       max_resol(:) = moins_un
        
        correspondance(:,:) = -1
Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_global/interpol_help.f90
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_global/interpol_help.f90	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_global/interpol_help.f90	(revision 257)
@@ -8,4 +8,9 @@
 !
 !! $Header: /home/ssipsl/CVSREP/ORCHIDEE/src_global/interpol_help.f90,v 1.7 2010/04/06 14:30:23 ssipsl Exp $
+!
+!< $HeadURL: http://forge.ipsl.jussieu.fr/orchidee/svn/trunk/ORCHIDEE/src_global/interpol_help.f90 $
+!< $Date: 2011-01-01 20:56:53 +0100 (Sat, 01 Jan 2011) $
+!< $Author: mmaipsl $
+!< $Revision: 41 $
 !
 !
Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_global/solar.f90
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_global/solar.f90	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_global/solar.f90	(revision 257)
@@ -3,6 +3,12 @@
 !! @call sechiba_main
 !! @Version : $Revision: 1.1 $, $Date: 2010/04/06 14:26:07 $
+!! @Version : $Revision: 42 $, $Date: 2011-01-01 21:15:03 +0100 (Sat, 01 Jan 2011) $
 !! 
 !! $Header: /home/ssipsl/CVSREP/ORCHIDEE/src_global/solar.f90,v 1.1 2010/04/06 14:26:07 ssipsl Exp $
+!
+!< $HeadURL: http://forge.ipsl.jussieu.fr/orchidee/svn/trunk/ORCHIDEE/src_global/solar.f90 $
+!< $Date: 2011-01-01 21:15:03 +0100 (Sat, 01 Jan 2011) $
+!< $Author: mmaipsl $
+!< $Revision: 42 $
 !!
 !! @author Marie-Alice Foujols, Jan Polcher and Martial Mancip
@@ -54,5 +60,4 @@
     !---------------------------------------------------------------------
     !
-!    pi = 4.*ATAN(1.)
     IF (check) WRITE(numout,*) 'We get the right calendar information'
     !-
@@ -132,5 +137,5 @@
           llat  = llatd*pi/180.
           csang(ilon,ilat) = &
-               &  MAX(0.,SIN(dec)*SIN(llat)+COS(dec)*COS(llat)*COS(omega))
+               &  MAX(zero,SIN(dec)*SIN(llat)+COS(dec)*COS(llat)*COS(omega))
        ENDDO
     ENDDO
Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_parallel/AA_make
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_parallel/AA_make	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_parallel/AA_make	(revision 257)
@@ -1,7 +1,7 @@
 #-
-#- $Id: AA_make,v 1.6 2010/04/06 14:34:32 ssipsl Exp $
+#- $Id: AA_make 41 2011-01-01 19:56:53Z mmaipsl $
 #-
-MODS1 = timer.f90 \
-	data_para.f90 \
+MODS1 = data_para.f90 \
+        timer.f90 \
         transfert_para.f90 \
 	ioipsl_para.f90 \
Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_parallel/AA_make.ldef
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_parallel/AA_make.ldef	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_parallel/AA_make.ldef	(revision 257)
@@ -1,4 +1,4 @@
 #-
-#- $Id: AA_make.ldef,v 1.3 2008/01/08 11:49:07 ssipsl Exp $
+#- $Id: AA_make.ldef 12 2010-11-05 15:42:13Z mmaipsl $
 #-
 #---------------------------------------------------------------------
Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_parallel/data_para.f90
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_parallel/data_para.f90	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_parallel/data_para.f90	(revision 257)
@@ -11,9 +11,12 @@
 !-
   USE defprec
-  USE constantes
   USE ioipsl
 !-
 #include "src_parallel.h"
 !-
+!-
+! Unit for output messages
+  INTEGER(i_std), SAVE :: numout = 6
+
   INTEGER, SAVE :: mpi_size                                           !! Number of parallel processes
   INTEGER, SAVE :: mpi_rank                                           !! my rank num
@@ -203,5 +206,5 @@
  
   SUBROUTINE init_data_para(iim,jjm,nbpoints,index_x)
-    USE constantes
+
     IMPLICIT NONE
 #ifdef CPP_PARA
@@ -457,5 +460,5 @@
   SUBROUTINE Write_Load_balance(times)
     IMPLICIT NONE
-    REAL,INTENT(IN) :: times
+    REAL(r_std),INTENT(IN) :: times
   
 #ifdef CPP_PARA  
Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_parallel/ioipsl_para.f90
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_parallel/ioipsl_para.f90	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_parallel/ioipsl_para.f90	(revision 257)
@@ -9,5 +9,4 @@
   USE data_para
   USE transfert_para
-  USE constantes
 !-
   IMPLICIT NONE
Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_parallel/orch_write_field.f90
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_parallel/orch_write_field.f90	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_parallel/orch_write_field.f90	(revision 257)
@@ -7,5 +7,5 @@
 module orch_Write_Field
   
-  USE constantes
+  USE data_para
 
   IMPLICIT NONE
Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_parallel/timer.f90
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_parallel/timer.f90	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_parallel/timer.f90	(revision 257)
@@ -7,5 +7,5 @@
 MODULE timer
 
-  USE constantes
+  USE data_para
   
   INTEGER, PARAMETER :: nb_timer=2
Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_parallel/tools_para.f90
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_parallel/tools_para.f90	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_parallel/tools_para.f90	(revision 257)
@@ -11,5 +11,4 @@
   USE timer
   USE data_para
-  USE constantes
 !-
 #include "src_parallel.h"
Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_parallel/transfert_para.f90
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_parallel/transfert_para.f90	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_parallel/transfert_para.f90	(revision 257)
@@ -9,5 +9,4 @@
   USE data_para
   USE timer
-  USE constantes
 !-
   IMPLICIT NONE
@@ -552,5 +551,4 @@
     USE data_para
     USE timer
-    USE constantes
 
     IMPLICIT NONE
@@ -599,5 +597,4 @@
     USE data_para
     USE timer
-    USE constantes
 
     IMPLICIT NONE
@@ -647,5 +644,4 @@
     USE data_para
     USE timer
-    USE constantes
 
     IMPLICIT NONE
@@ -1953,5 +1949,4 @@
     USE data_para
     USE timer
-    USE constantes
 
     IMPLICIT NONE
@@ -1985,5 +1980,4 @@
     USE data_para
     USE timer
-    USE constantes
 
     IMPLICIT NONE
@@ -2018,5 +2012,4 @@
     USE data_para
     USE timer
-    USE constantes
 
     IMPLICIT NONE
@@ -2050,5 +2043,4 @@
     USE data_para
     USE timer
-    USE constantes
 
     IMPLICIT NONE
@@ -2084,5 +2076,4 @@
     USE data_para
     USE timer
-    USE constantes
 
     IMPLICIT NONE
@@ -2139,5 +2130,4 @@
     USE data_para
     USE timer
-    USE constantes
 
     IMPLICIT NONE
@@ -2195,5 +2185,4 @@
     USE data_para
     USE timer
-    USE constantes
 
     IMPLICIT NONE
@@ -2250,5 +2239,4 @@
     USE data_para
     USE timer
-    USE constantes
 
     IMPLICIT NONE
@@ -2319,5 +2307,4 @@
     USE data_para
     USE timer
-    USE constantes
 
     IMPLICIT NONE
@@ -2387,5 +2374,4 @@
     USE data_para
     USE timer
-    USE constantes
 
     IMPLICIT NONE
@@ -2456,5 +2442,4 @@
     USE data_para, iim=>iim_g,jjm=>jjm_g
     USE timer
-    USE constantes
 
     IMPLICIT NONE
@@ -2521,5 +2506,4 @@
     USE data_para, iim=>iim_g,jjm=>jjm_g
     USE timer
-    USE constantes
 
     IMPLICIT NONE
@@ -2590,5 +2574,4 @@
     USE data_para, iim=>iim_g,jjm=>jjm_g
     USE timer
-    USE constantes
 
     IMPLICIT NONE
@@ -2655,5 +2638,4 @@
     USE data_para, iim=>iim_g,jjm=>jjm_g
     USE timer
-    USE constantes
 
     IMPLICIT NONE
@@ -2733,5 +2715,4 @@
     USE data_para, iim=>iim_g,jjm=>jjm_g
     USE timer
-    USE constantes
 
     IMPLICIT NONE
@@ -2810,5 +2791,4 @@
     USE data_para, iim=>iim_g,jjm=>jjm_g
     USE timer
-    USE constantes
 
     IMPLICIT NONE
@@ -2887,5 +2867,4 @@
     USE data_para
     USE timer
-    USE constantes
 
     IMPLICIT NONE
@@ -2922,5 +2901,4 @@
     USE data_para
     USE timer
-    USE constantes
 
     IMPLICIT NONE
Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_parameters/AA_make
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_parameters/AA_make	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_parameters/AA_make	(revision 257)
@@ -1,4 +1,4 @@
 #-
-#- $Id: AA_make,v 1.17 2010/04/06 14:34:32 ssipsl Exp $
+#- $Id: AA_make 41 2011-01-01 19:56:53Z mmaipsl $
 #-
 IOIPSL_LIB = $(LIBDIR)/libioipsl.a
@@ -8,4 +8,11 @@
 #-Q- eshpux SXIOIPSL_LIB = $(LIBDIR)/libsxioipsl.a
 #-Q- sx8brodie SXIOIPSL_LIB = $(LIBDIR)/libsxioipsl.a
+#-
+PARALLEL_LIB = $(LIBDIR)/libparallel.a
+SXPARALLEL_LIB = $(PARALLEL_LIB)
+#-Q- sxnec  SXPARALLEL_LIB = $(LIBDIR)/libsxparallel.a
+#-Q- sx6nec SXPARALLEL_LIB = $(LIBDIR)/libsxparallel.a
+#-Q- eshpux SXPARALLEL_LIB = $(LIBDIR)/libsxparallel.a
+#-Q- sx8brodie SXPARALLEL_LIB = $(LIBDIR)/libsxparallel.a
 #-
 MODS1 = constantes.f90 \
@@ -23,4 +30,5 @@
 all:
 	$(M_K) libioipsl
+	$(M_K) libparallel
 	$(M_K) m_all
 	@echo parameter is OK
@@ -30,4 +38,7 @@
 libioipsl:
 	(cd ../../IOIPSL/src; $(M_K) -f Makefile)
+
+libparallel:
+	(cd ../src_parallel; $(M_K) -f Makefile)
 
 $(MODEL_LIB)(%.o): %.f90
@@ -57,4 +68,5 @@
   $(MODEL_LIB)(constantes_mtc.o)
 $(MODEL_LIB)(constantes.o): \
+  $(PARALLEL_LIB) \
   $(IOIPSL_LIB)
 
Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_parameters/AA_make.ldef
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_parameters/AA_make.ldef	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_parameters/AA_make.ldef	(revision 257)
@@ -1,4 +1,4 @@
 #-
-#- $Id: AA_make.ldef,v 1.7 2008/01/08 11:49:07 ssipsl Exp $
+#- $Id: AA_make.ldef 12 2010-11-05 15:42:13Z mmaipsl $
 #-
 #---------------------------------------------------------------------
Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_parameters/constantes.f90
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_parameters/constantes.f90	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_parameters/constantes.f90	(revision 257)
@@ -8,5 +8,5 @@
 !!--------------------------------------------------------------------
   USE defprec
-  USE ioipsl
+  USE parallel
 !-
   IMPLICIT NONE
@@ -21,6 +21,4 @@
   !----------------
 
-  ! Unit for output messages
-  INTEGER(i_std), SAVE :: numout = 6
   !-
   ! To set for more printing
@@ -185,4 +183,9 @@
   INTEGER(i_std),PARAMETER :: ipassive = 3
   INTEGER(i_std),PARAMETER :: ncarb = 3
+  !
+  ! transformation between types of surface (DS : not used in the code?)
+  INTEGER(i_std),PARAMETER :: ito_natagri = 1
+  INTEGER(i_std),PARAMETER :: ito_total = 2
+
 
 
@@ -197,5 +200,5 @@
   REAL(r_std), PARAMETER :: pi = 4.*ATAN(1.)
   ! e
-  REAL(r_std),PARAMETER :: euler = 2.71828182846
+  REAL(r_std),PARAMETER :: euler = 2.71828182846 !or euler = EXP(1.)
   !-
   ! Integer constant set to zero
@@ -230,5 +233,13 @@
   !
   ! radius of the Earth (m)
+  ! comment :
+  ! Earth radius ~= Equatorial radius
+  ! The Earth's equatorial radius a, or semi-major axis, is the distance from its center to the equator and equals 6,378.1370 km.
+  ! The equatorial radius is often used to compare Earth with other planets.
   REAL(r_std), PARAMETER :: R_Earth = 6378000.
+  !The meridional mean is well approximated by the semicubic mean of the two axe yielding 6367.4491 km
+  ! or less accurately by the quadratic mean of the two axes about 6,367.454 km
+  ! or even just the mean of the two axes about 6,367.445 km.
+  !-
   ! standard pressure
   REAL(r_std), PARAMETER :: pb_std = 1013. 
@@ -333,29 +344,184 @@
 
 
-!-----------------------------------------------
-!----------------------------------------------
-! SCALAR PARAMETERS EXTERNALIZED
-!----------------------------------------------
-!-----------------------------------------------
-!------------------------------------------
-!  SECHIBA, SOIL AND VEGETATION parameters
-!-----------------------------------------
-
-  !!---------------------------------------
-  !! Parameters for soil type distribution
-  !!---------------------------------------
-  !
-  ! Default soil texture distribution in the following order :
-  !    sand, loam and clay
-  REAL(r_std),SAVE, DIMENSION(nstm) :: soiltype_default = (/ 0.0, 1.0, 0.0 /)
-
-  !!----------------------------------------
-  !! Constantes from the Choisnel hydrology
-  !!----------------------------------------
+
+                           !------------------------!
+                           !  SECHIBA PARAMETERS    !
+                           !------------------------!
+
+! DS Maybe should I move these constants in the modules they belong
+!-
+! Specific parameters for the CWRR hydrology module
+!-
+!
+! CWRR linearisation
+INTEGER(i_std),PARAMETER :: imin = 1
+! number of interval for CWRR
+INTEGER(i_std),PARAMETER :: nbint = 100
+! number of points for CWRR
+INTEGER(i_std),PARAMETER :: imax = nbint+1
+
+!-
+! diffuco
+!-
+REAL(r_std),PARAMETER :: Tetens_1 = 0.622   
+REAL(r_std),PARAMETER :: Tetens_2 = 0.378
+REAL(r_std),PARAMETER :: std_ci_frac = 0.667
+REAL(r_std),PARAMETER :: alpha_j = 0.8855
+REAL(r_std),PARAMETER :: curve_assim = 0.7
+REAL(r_std),PARAMETER :: WJ_coeff1 = 4.5
+REAL(r_std),PARAMETER :: WJ_coeff2 = 10.5
+REAL(r_std),PARAMETER :: Vc_to_Rd_ratio = 0.011
+REAL(r_std),PARAMETER :: O2toCO2_stoechio = 1.6
+REAL(r_std),PARAMETER :: mmol_to_m_1 = 0.0244
+REAL(r_std),PARAMETER  :: RG_to_PAR = 0.5 
+REAL(r_std),PARAMETER  :: W_to_mmol = 4.6 ! W_to_mmol * RG_to_PAR = 2.3
+
+
+
+                               !-----------!
+                               ! Global    !
+                               !-----------!
+  ! The minimum wind
+  REAL(r_std),SAVE :: min_wind = 0.1
+  ! Sets the amount above which only sublimation occures [Kg/m^2]
+  REAL(r_std),SAVE :: snowcri=1.5
+  ! Transforms leaf area index into size of interception reservoir
+  REAL(r_std),SAVE      :: qsintcst = 0.1
+  ! Total depth of soil reservoir (for hydrolc)
+  REAL(r_std),SAVE :: dpu_cste =  deux
+  ! Total depth of soil reservoir (m)
+  REAL(r_std),SAVE,DIMENSION(nstm) :: dpu =  (/ 2.0_r_std, 2.0_r_std, 2.0_r_std /)
+
+  ! FLAGS
+
+  ! allow agricultural PFTs
+  LOGICAL,SAVE :: agriculture = .TRUE. !(read in slowproc)
+  ! Do we treat PFT expansion across a grid point after introduction?
+  ! default = .FALSE.
+  LOGICAL,SAVE :: treat_expansion = .FALSE.
+  ! herbivores?
+  LOGICAL,SAVE :: ok_herbivores = .FALSE.
+  ! harvesting ?
+  LOGICAL,SAVE :: harvest_agri = .TRUE.
+  ! constant moratlity
+  LOGICAL,SAVE :: lpj_gap_const_mort=.TRUE.
+
+  ! Parameters used by both hydrology models
+
+  ! Maximum period of snow aging
+  REAL(r_std),SAVE :: max_snow_age = 50._r_std
+  ! Transformation time constant for snow (m)
+  REAL(r_std),SAVE :: snow_trans = 0.3_r_std
+  ! Lower limit of snow amount
+  REAL(r_std),SAVE :: sneige
+  ! The maximum mass (kg/m^2) of a glacier.
+  REAL(r_std),SAVE :: maxmass_glacier = 3000.
+  ! Maximum quantity of water (Kg/M3)
+  REAL(r_std),SAVE :: mx_eau_eau = 150.
+
+  ! UNKNOW
+
+  ! Is veget_ori array stored in restart file
+!!$! DS: Where is it used ?
+  !  LOGICAL,PARAMETER :: ldveget_ori_on_restart = .TRUE.
+  !-
+!!$! DS not used in the code ? 
+  ! Limit of air temperature for snow
+  REAL(r_std),SAVE :: tsnow=273.
+
+
+
+
+                               !-------------!
+                               ! condveg.f90 !
+                               !-------------!
+
+  ! 1. Scalar
+
+  ! to get z0 from height
+  REAL(r_std), SAVE  :: z0_over_height = un/16.
+  ! Magic number which relates the height to the displacement height.
+  REAL(r_std), SAVE  :: height_displacement = 0.75
+  ! bare soil roughness length (m)
+  REAL(r_std),SAVE :: z0_bare = 0.01
+  ! ice roughness length (m)
+  REAL(r_std),SAVE :: z0_ice = 0.001
+  ! Time constant of the albedo decay of snow
+  REAL(r_std),SAVE :: tcst_snowa = 5.0
+  ! Critical value for computation of snow albedo [Kg/m^2]
+  REAL(r_std),SAVE :: snowcri_alb=10.
+
+  ! 2. Arrays
+
+  ! albedo of dead leaves, VIS+NIR
+  REAL(r_std),DIMENSION(2),SAVE :: alb_deadleaf = (/ .12, .35/)
+  ! albedo of ice, VIS+NIR
+  REAL(r_std),DIMENSION(2),SAVE :: alb_ice = (/ .60, .20/)
+  !   The correspondance table for the soil color numbers and their albedo
+  !
+  REAL(r_std), DIMENSION(classnb) :: vis_dry = (/0.24, 0.22, 0.20, 0.18, 0.16, 0.14, 0.12, 0.10, 0.27/)
+  REAL(r_std), DIMENSION(classnb) :: nir_dry = (/0.48, 0.44, 0.40, 0.36, 0.32, 0.28, 0.24, 0.20, 0.55/)  
+  REAL(r_std), DIMENSION(classnb) :: vis_wet = (/0.12, 0.11, 0.10, 0.09, 0.08, 0.07, 0.06, 0.05, 0.15/)  
+  REAL(r_std), DIMENSION(classnb) :: nir_wet = (/0.24, 0.22, 0.20, 0.18, 0.16, 0.14, 0.12, 0.10, 0.31/)
+  !   
+  ! Nathalie, introduction d'un albedo moyen, VIS+NIR
+  ! Les valeurs suivantes correspondent a la moyenne des valeurs initiales
+  !  REAL(stnd), DIMENSION(classnb) :: albsoil_vis = (/0.18, 0.165, 0.15, 0.135, 0.12, 0.105, 0.09, 0.075, 0.21/)
+  !  REAL(stnd), DIMENSION(classnb) :: albsoil_nir = (/0.36, 0.33, 0.30, 0.27, 0.24, 0.21, 0.18, 0.15, 0.43/)
+  ! les valeurs retenues accentuent le contraste entre equateur et Sahara. 
+  ! On diminue aussi l'albedo des deserts (tous sauf Sahara)
+  REAL(r_std), DIMENSION(classnb) :: albsoil_vis = (/0.18, 0.16, 0.16, 0.15, 0.12, 0.105, 0.09, 0.075, 0.25/)
+  REAL(r_std), DIMENSION(classnb) :: albsoil_nir = (/0.36, 0.34, 0.34, 0.33, 0.30, 0.25, 0.20, 0.15, 0.45/) 
+
+
+                               !-------------!
+                               ! diffuco.f90 !
+                               !-------------!
+
+  ! 1. Scalar
+
+  INTEGER(i_std), SAVE        :: nlai = 20 ! dimension de tableau
+  ! used in diffuco_trans
+  REAL(r_std), SAVE                :: laimax = 12.
+  REAL(r_std), SAVE                :: xc4_1 = .83
+  REAL(r_std), SAVE                :: xc4_2 = .93
+  ! Set to .TRUE. if you want q_cdrag coming from GCM
+  LOGICAL,SAVE :: ldq_cdrag_from_gcm = .FALSE.
+
+  ! 2; Arrays
+
+  ! 3. Coefficients of equations
+
+  REAL(r_std), SAVE      :: lai_level_depth = .15
+  REAL(r_std), SAVE      :: x1_coef =  0.177
+  REAL(r_std), SAVE      :: x1_Q10 =  0.069
+  REAL(r_std), SAVE      :: quantum_yield =  0.092
+  REAL(r_std), SAVE      :: kt_coef = 0.7     
+  REAL(r_std), SAVE      :: kc_coef = 39.09
+  REAL(r_std), SAVE      :: Ko_Q10 = .085
+  REAL(r_std), SAVE      :: Oa = 210000.
+  REAL(r_std), SAVE      :: Ko_coef =  2.412
+  REAL(r_std), SAVE      :: CP_0 = 42.
+  REAL(r_std), SAVE      :: CP_temp_coef = 9.46 
+  REAL(r_std), SAVE      :: CP_temp_ref = 25.
+  !
+  REAL(r_std), SAVE, DIMENSION(2)  :: rt_coef = (/ 0.8, 1.3 /) 
+  REAL(r_std), SAVE, DIMENSION(2)  :: vc_coef = (/ 0.39, 0.3 /)
+  !
+  ! coefficients of the polynome of degree 5 used inthe equation of coeff_dew_veg
+  REAL(r_std), SAVE, DIMENSION(6)     :: dew_veg_poly_coeff = &
+  & (/ 0.887773, 0.205673, 0.110112, 0.014843,  0.000824,  0.000017 /) 
+
+
+
+                              !-------------!
+                              ! hydrolc.f90 !
+                              !-------------!
+
+  ! 1. Scalar
+
   !
   ! Wilting point (Has a numerical role for the moment)
   REAL(r_std),SAVE :: qwilt = 5.0
-  ! Total depth of soil reservoir (for hydrolc)
-  REAL(r_std),SAVE :: dpu_cste =  deux
   ! The minimal size we allow for the upper reservoir (m)
   REAL(r_std),SAVE :: min_resdis = 2.e-5
@@ -369,9 +535,4 @@
   REAL(r_std),SAVE :: exp_drain = 1.5
   !-
-  ! Transforms leaf area index into size of interception reservoir
-  REAL(r_std),SAVE      :: qsintcst = 0.1
-  ! Maximum quantity of water (Kg/M3)
-  REAL(r_std),SAVE :: mx_eau_eau = 150.
-  !-
   ! Constant in the computation of resistance for bare  soil evaporation
   REAL(r_std),SAVE :: rsol_cste = 33.E3
@@ -380,16 +541,21 @@
   REAL(r_std),SAVE :: hcrit_litter=0.08_r_std
 
-  !!---------------------------------------------------
-  !! Specific parameters for the CWRR hydrology module
-  !!--------------------------------------------------- 
-  !
-!!$ DS To externalise ? 
-!!$ advice of MM : to put in hydrol
-  ! CWRR linearisation
-  INTEGER(i_std),PARAMETER :: imin = 1
-  ! number of interval for CWRR
-  INTEGER(i_std),PARAMETER :: nbint = 100
-  ! number of points for CWRR
-  INTEGER(i_std),PARAMETER :: imax = nbint+1
+
+
+
+                              !-------------!
+                              ! hydrol.f90  !
+                              !-------------!
+
+
+  ! 1. Scalar
+
+  ! Allowed moisture above mcs (boundary conditions)
+  REAL(r_std), SAVE                :: dmcs = 0.002     
+  ! Allowed moisture below mcr (boundary conditions)
+  REAL(r_std), SAVE                :: dmcr = 0.002  
+
+  ! 2. Arrays
+ 
   !-
   ! externalise w_time (some bug in hydrol)
@@ -406,6 +572,4 @@
   ! Saturated soil water content
   REAL(r_std),SAVE,DIMENSION(nstm) :: mcs = (/ 0.41_r_std, 0.43_r_std, 0.41_r_std /)
-  ! Total depth of soil reservoir (m)
-  REAL(r_std),SAVE,DIMENSION(nstm) :: dpu =  (/ 2.0_r_std, 2.0_r_std, 2.0_r_std /)
   !-
   ! dpu must be constant over the different soil types
@@ -427,117 +591,133 @@
 
 
-  !!-----------------------------------------------------
-  !! Vegetation parameters (previously in constantes_veg)
-  !!----------------------------------------------------- 
-  !
-  ! Value for frac_nobio for tests in 0-dim simulations
+  
+                              !-------------!
+                              ! routing.f90 !
+                              !-------------!
+
+  ! 1. Scalar
+
+  ! Parameter for the Kassel irrigation parametrization linked to the crops
+  REAL(r_std), SAVE          :: crop_coef = 1.5
+
+
+
+                              !--------------!
+                              ! slowproc.f90 !
+                              !--------------!
+
+
+  ! 1. Scalar
+
+  REAL(r_std), SAVE          :: clayfraction_default = 0.2
+  ! Minimal fraction of mesh a vegetation type can occupy
+  REAL(r_std),SAVE :: min_vegfrac=0.001
+ ! Value for frac_nobio for tests in 0-dim simulations
   ! laisser ca tant qu'il n'y a que de la glace (pas de lacs)
   !DS : used in slowproc
   REAL(r_std),SAVE :: frac_nobio_fixed_test_1 = 0.0
-  !-
-  ! Is veget_ori array stored in restart file
-!!$ DS: Where is it used ?
-  !  LOGICAL,PARAMETER :: ldveget_ori_on_restart = .TRUE.
-  !-
-  ! Set to .TRUE. if you want q_cdrag coming from GCM
-  ! used in diffuco
-  LOGICAL,SAVE :: ldq_cdrag_from_gcm = .FALSE.
-  !-
-  ! allow agricultural PFTs
-  LOGICAL,SAVE :: agriculture = .TRUE.
-  !-
-  ! The maximum mass (kg/m^2) of a glacier.
-  REAL(r_std),SAVE :: maxmass_glacier = 3000.
-  !-
-  ! Minimal fraction of mesh a vegetation type can occupy
-  REAL(r_std),SAVE :: min_vegfrac=0.001
-  !-
-!!$ DS not used in the code ? 
-  ! Limit of air temperature for snow
-  REAL(r_std),SAVE :: tsnow=273.
-  !-
-  ! Sets the amount above which only sublimation occures [Kg/m^2]
-  REAL(r_std),SAVE :: snowcri=1.5
-  ! Critical value for computation of snow albedo [Kg/m^2]
-  REAL(r_std),SAVE :: snowcri_alb=10.
-  ! Lower limit of snow amount
-  REAL(r_std),SAVE :: sneige
-  !-
-  ! The minimum wind
-  REAL(r_std),SAVE :: min_wind = 0.1
-  ! bare soil roughness length (m)
-  REAL(r_std),SAVE :: z0_bare = 0.01
-  ! ice roughness length (m)
-  REAL(r_std),SAVE :: z0_ice = 0.001
-  !-
-  ! Time constant of the albedo decay of snow
-  REAL(r_std),SAVE :: tcst_snowa = cinq
-  ! Maximum period of snow aging
-  REAL(r_std),SAVE :: max_snow_age = 50._r_std
-  ! Transformation time constant for snow (m)
-  REAL(r_std),SAVE :: snow_trans = 0.3_r_std
-  !-
-  ! albedo of dead leaves, VIS+NIR
-  REAL(r_std),DIMENSION(2),SAVE :: alb_deadleaf = (/ .12, .35/)
-  ! albedo of ice, VIS+NIR
-  REAL(r_std),DIMENSION(2),SAVE :: alb_ice = (/ .60, .20/)
-
-  !!--------------------------------
-  !!  SECHIBA specific parameters
-  !!--------------------------------
-  !
-  !-
-  ! condveg
+
+  ! 2. Arrays
+
+  ! Default soil texture distribution in the following order :
+  !    sand, loam and clay
+  REAL(r_std),SAVE, DIMENSION(nstm) :: soiltype_default = (/ 0.0, 1.0, 0.0 /)
+
+
+
+
+                           !-----------------------------!
+                           !  STOMATE AND LPJ PARAMETERS !
+                           !-----------------------------!
+
+  !-
+  ! stomate_alloc
   !- 
-  ! to get z0 from height
-  REAL(r_std), SAVE  :: z0_over_height = un/16.
-  ! Magic number which relates the height to the displacement height.
-  REAL(r_std), SAVE  :: height_displacement = 0.75
-  !-
-  ! diffuco
-  !-
-  INTEGER(i_std), SAVE        :: nlai = 20 ! dimension de tableau
-  ! used in diffuco_trans
-  REAL(r_std), SAVE                :: laimax = 12.
-  REAL(r_std), SAVE                :: xc4_1 = .83
-  REAL(r_std), SAVE                :: xc4_2 = .93
-  !-
-  ! hydrol.
-  !-
-  ! Allowed moisture above mcs (boundary conditions)
-  REAL(r_std), SAVE                :: dmcs = 0.002     
-  ! Allowed moisture below mcr (boundary conditions)
-  REAL(r_std), SAVE                :: dmcr = 0.002  
-  !-
-  ! routing
-  !- 
-  ! Parameter for the Kassel irrigation parametrization linked to the crops
-  REAL(r_std), SAVE          :: crop_coef = 1.5
-  !-
-  ! slowproc
-  !- 
-  REAL(r_std), SAVE          :: clayfraction_default = 0.2
+  REAL(r_std), PARAMETER  ::  max_possible_lai = 10. 
+  REAL(r_std), PARAMETER  ::  Nlim_Q10 = 10. 
+  !-
+  ! stomate_litter
+  !-
+  REAL(r_std), PARAMETER    :: Q10 = 10.
+  !
+
+! DS 31/03/2011 test new organization
+! List of Externalized Parameters by modules
+
+
+                              !----------------------!
+                              ! lpj_constraints.f90  !
+                              !----------------------!
+
   
-!-----------------------------
-!  STOMATE AND LPJ PARAMETERS
-!-----------------------------
-  !
-  !-
-  ! lpj_constraints
-  !-
+  ! 1. Scalar
+
   ! longest sustainable time without regeneration (vernalization)
   REAL(r_std), SAVE  :: too_long = 5.
-  !
-  !-
-  ! lpj_fire
-  !-
+
+
+                              !--------------------!
+                              ! lpj_establish.f90  !
+                              !--------------------!
+
+  ! 1. Scalar
+  ! Maximum tree establishment rate
+  REAL(r_std),SAVE :: estab_max_tree = 0.12
+  ! Maximum grass establishment rate
+  REAL(r_std),SAVE :: estab_max_grass = 0.12 
+  
+  ! 3. Coefficients of equations
+
+  REAL(r_std), SAVE      :: establish_scal_fact = 15.
+  REAL(r_std), SAVE      :: fpc_crit_max = .075
+  REAL(r_std), SAVE      :: fpc_crit_min= .05 
+
+
+                              !---------------!
+                              ! lpj_fire.f90  !
+                              !---------------!
+
+  ! 1. Scalar
+
   ! Time scale for memory of the fire index (days). Validated for one year in the DGVM.
   REAL(r_std), SAVE  :: tau_fire = 30. 
   ! Critical litter quantity for fire
   REAL(r_std), SAVE  :: litter_crit = 200.
-  !
-  !-
-  ! lpj_light
-  !-
+
+  ! 2. Arrays
+
+  ! What fraction of a burned plant compartment goes into the atmosphere
+  !   (rest into litter)
+  REAL(r_std), SAVE, DIMENSION(nparts) :: co2frac = (/ .95, .95, 0., 0.3, 0., 0., .95, .95 /)
+
+
+  ! 3. Coefficients of equations
+
+  REAL(r_std), SAVE, DIMENSION(3) :: bcfrac_coeff = (/ .3,  1.3,  88.2 /) 
+  REAL(r_std), SAVE, DIMENSION(4)  :: firefrac_coeff = (/ 0.45, 0.8, 0.6, 0.13 /)
+
+
+                              !--------------!
+                              ! lpj_gap.f90  !
+                              !--------------!
+
+  ! 1. Scalar
+! DS 15/06/2011 : the name of the parameter constant_mortality was replaced by its keyword  
+!!$  ! which kind of mortality
+!!$  LOGICAL, SAVE          :: constant_mortality = .TRUE.
+
+  ! 3. Coefficients of equations
+
+  REAL(r_std), SAVE      ::  availability_fact = 0.02
+  REAL(r_std), SAVE      ::  vigour_ref = 0.17
+  REAL(r_std), SAVE      ::  vigour_coeff = 70.
+
+
+                              !----------------!
+                              ! lpj_light.f90  !
+                              !----------------!
+
+  ! 1. Scalar
+  
   ! maximum total number of grass individuals in a closed canopy
   REAL(r_std), SAVE  :: grass_mercy = 0.01
@@ -547,14 +727,38 @@
   ! to fpc of last time step (F)?
   LOGICAL, SAVE     :: annual_increase = .TRUE.
-  !
-  !-
-  ! lpj_pftinout
-  !-
+  ! For trees, minimum fraction of crown area occupied
+  ! (due to its branches etc.)
+  ! This means that only a small fraction of its crown area
+  ! can be invaded by other trees.
+  REAL(r_std),SAVE :: min_cover = 0.05  
+
+
+                              !------------------!
+                              ! lpj_pftinout.f90 !
+                              !------------------!
+
+  ! 1. Scalar
+
   ! minimum availability
   REAL(r_std), SAVE  :: min_avail = 0.01
-  !
-  !-
-  ! stomate_alloc
-  !-
+  ! initial density of individuals
+  REAL(r_std),SAVE :: ind_0 = 0.02
+
+  ! 2. Arrays
+
+  ! 3. Coefficients of equations
+  
+  REAL(r_std), SAVE      :: RIP_time_min = 1.25
+  REAL(r_std), SAVE      :: npp_longterm_init = 10. 
+  REAL(r_std), SAVE      :: everywhere_init = 0.05
+
+
+
+                              !-------------------!
+                              ! stomate_alloc.f90 !
+                              !-------------------!
+
+  ! 1. Scalar
+
   ! Do we try to reach a minimum reservoir even if we are severely stressed?
   LOGICAL, SAVE                                        :: ok_minres = .TRUE.
@@ -582,12 +786,23 @@
   ! scaling depth for nitrogen limitation (m)
   REAL(r_std), SAVE                                     :: z_nitrogen = 0.2
-  !
-  !-
-  ! stomate_data
-  !-
-  !!-------------------------------
-  !! Parameters for the pipe model
-  !!------------------------------
-  !-
+
+
+  ! 2. Arrays
+  
+
+  ! 3. Coefficients of equations
+
+  REAL(r_std), SAVE  :: lai_max_to_happy = 0.5  
+  REAL(r_std), SAVE  ::  Nlim_tref = 25.
+
+
+                              !------------------!
+                              ! stomate_data.f90 !
+                              !------------------!
+  ! 1. Scalar 
+
+  !
+  ! 1.1 Parameters for the pipe model
+  !
   ! crown area = pipe_tune1. stem diameter**(1.6) (Reinicke's theory)
   REAL(r_std),SAVE :: pipe_tune1 = 100.0
@@ -601,41 +816,9 @@
   ! one more SAVE
   REAL(r_std),SAVE :: pipe_k1 = 8.e3
-  !
-  !-
-  ! Maximum tree establishment rate
-  REAL(r_std),SAVE :: estab_max_tree = 0.12
-  ! Maximum grass establishment rate
-  REAL(r_std),SAVE :: estab_max_grass = 0.12
-  ! initial density of individuals
-  REAL(r_std),SAVE :: ind_0 = 0.02
-  ! For trees, minimum fraction of crown area occupied
-  ! (due to its branches etc.)
-  ! This means that only a small fraction of its crown area
-  ! can be invaded by other trees.
-  REAL(r_std),SAVE :: min_cover = 0.05  
-  !-
-  ! alpha's : ?
-  REAL(r_std),SAVE :: alpha_grass = .5
-  REAL(r_std),SAVE :: alpha_tree = 1.
-  !-
-  ! maximum reference long term temperature (K)
-  REAL(r_std),SAVE :: tlong_ref_max = 303.1
-  ! minimum reference long term temperature (K)
-  REAL(r_std),SAVE :: tlong_ref_min = 253.1
-  !
-  !! LOGICAL
-  !-
-  ! Do we treat PFT expansion across a grid point after introduction?
-  ! default = .FALSE.
-  LOGICAL,SAVE :: treat_expansion = .FALSE.
-  !
-  ! herbivores?
-  LOGICAL,SAVE :: ok_herbivores = .FALSE.
-  !
-  ! harvesting ?
-  LOGICAL,SAVE :: harvest_agri = .TRUE.
-  !!----------------------
-  !! climatic parameters 
-  !!---------------------
+  ! pipe tune exponential coeff
+  REAL(r_std), SAVE      :: pipe_tune_exp_coeff = 1.6 
+
+  !
+  !  1.2 climatic parameters 
   !
   ! minimum precip, in mm/year
@@ -645,15 +828,18 @@
   ! critical fpc, needed for light competition and establishment
   REAL(r_std),SAVE :: fpc_crit = 0.95
-  !-
-  ! fraction of GPP which is lost as growth respiration
-  REAL(r_std),SAVE :: frac_growthresp = 0.28
-  !
-  !-
+
+  !
+  ! 1.3 sapling characteristics
+  !
+  ! alpha's : ?
+  REAL(r_std),SAVE :: alpha_grass = .5
+  REAL(r_std),SAVE :: alpha_tree = 1.
   ! mass ratio (heartwood+sapwood)/sapwood
   REAL(r_std), SAVE  :: mass_ratio_heart_sap = 3.
-  !
-  !!---------------------------------------------------------
-  ! time scales for phenology and other processes (in days)
-  !!---------------------------------------------------------
+  ! fraction of GPP which is lost as growth respiration
+  REAL(r_std),SAVE :: frac_growthresp = 0.28  
+
+  !
+  ! 1.4  time scales for phenology and other processes (in days)
   !
   REAL(r_std), SAVE    ::  tau_hum_month = 20.            
@@ -667,240 +853,8 @@
   REAL(r_std), SAVE    ::  tau_ngd = 50.
   REAL(r_std), SAVE    ::  coeff_tau_longterm = 3.
-  ! used in stomate_data and in stomate_season
   REAL(r_std), SAVE    ::  tau_longterm 
-  !
-  !-
-  ! stomate_litter
-  !-
-  ! scaling depth for soil activity (m)
-  REAL(r_std), SAVE    :: z_decomp = 0.2
-  !
-  !-
-  ! stomate_lpj
-  !-
-  REAL(r_std), SAVE    :: frac_turnover_daily = 0.55
-  !
-  !-
-  ! stomate_npp
-  !-
-  ! maximum fraction of allocatable biomass used for maintenance respiration
-  REAL(r_std), SAVE   :: tax_max = 0.8
-  !
-  !-
-  ! stomate_phenology
-  !- 
-  ! take carbon from atmosphere if carbohydrate reserve too small?
-  LOGICAL, SAVE                                         :: always_init = .FALSE.
-  ! minimum time (d) since last beginning of a growing season
-  REAL(r_std), SAVE                                      :: min_growthinit_time = 300.
-  ! moisture availability above which moisture tendency doesn't matter
-  REAL(r_std), SAVE                                   :: moiavail_always_tree = 1.0
-  REAL(r_std), SAVE                                   :: moiavail_always_grass = 0.6
-  ! monthly temp. above which temp. tendency doesn't matter
-  REAL(r_std), SAVE                                   ::  t_always
-  REAL(r_std), SAVE                                   ::  t_always_add = 10.
-  !
-  !-
-  ! stomate_season
-  !-
-  ! rapport maximal GPP/GGP_max pour dormance
-  REAL(r_std), SAVE                                  :: gppfrac_dormance = 0.2
-  ! minimum gpp considered as not "lowgpp"
-  REAL(r_std), SAVE                                  :: min_gpp_allowed = 0.3
-  ! tau (year) for "climatologic variables
-  REAL(r_std), SAVE                                  :: tau_climatology = 20
-  ! parameters for herbivore activity
-  REAL(r_std), SAVE                                  :: hvc1 = 0.019
-  REAL(r_std), SAVE                                  :: hvc2 = 1.38
-  REAL(r_std), SAVE                                  :: leaf_frac_hvc =.33
-  !
-  !-
-  ! stomate_vmax
-  !-
-  ! offset (minimum relative vcmax)
-  REAL(r_std), SAVE                                      :: vmax_offset = 0.3
-  ! leaf age at which vmax attains vcmax_opt (in fraction of critical leaf age)
-  REAL(r_std), SAVE                                      :: leafage_firstmax = 0.03
-  ! leaf age at which vmax falls below vcmax_opt (in fraction of critical leaf age)
-  REAL(r_std), SAVE                                      :: leafage_lastmax = 0.5
-  ! leaf age at which vmax attains its minimum (in fraction of critical leaf age)
-  REAL(r_std), SAVE                                      :: leafage_old = 1.
-
-
-!--------------------------
-!--------------------------
-! ARRAYS-PARAMETERS
-!--------------------------
-!--------------------------
-  !-
-  ! condveg
-  !-
-  !   The correspondance table for the soil color numbers and their albedo
-  !
-  REAL(r_std), DIMENSION(classnb) :: vis_dry = (/0.24, 0.22, 0.20, 0.18, 0.16, 0.14, 0.12, 0.10, 0.27/)
-  REAL(r_std), DIMENSION(classnb) :: nir_dry = (/0.48, 0.44, 0.40, 0.36, 0.32, 0.28, 0.24, 0.20, 0.55/)  
-  REAL(r_std), DIMENSION(classnb) :: vis_wet = (/0.12, 0.11, 0.10, 0.09, 0.08, 0.07, 0.06, 0.05, 0.15/)  
-  REAL(r_std), DIMENSION(classnb) :: nir_wet = (/0.24, 0.22, 0.20, 0.18, 0.16, 0.14, 0.12, 0.10, 0.31/)
-  !   
-  ! Nathalie, introduction d'un albedo moyen, VIS+NIR
-  ! Les valeurs suivantes correspondent a la moyenne des valeurs initiales
-  !  REAL(stnd), DIMENSION(classnb) :: albsoil_vis = (/0.18, 0.165, 0.15, 0.135, 0.12, 0.105, 0.09, 0.075, 0.21/)
-  !  REAL(stnd), DIMENSION(classnb) :: albsoil_nir = (/0.36, 0.33, 0.30, 0.27, 0.24, 0.21, 0.18, 0.15, 0.43/)
-  ! les valeurs retenues accentuent le contraste entre equateur et Sahara. 
-  ! On diminue aussi l'albedo des deserts (tous sauf Sahara)
-  REAL(r_std), DIMENSION(classnb) :: albsoil_vis = (/0.18, 0.16, 0.16, 0.15, 0.12, 0.105, 0.09, 0.075, 0.25/)
-  REAL(r_std), DIMENSION(classnb) :: albsoil_nir = (/0.36, 0.34, 0.34, 0.33, 0.30, 0.25, 0.20, 0.15, 0.45/)
-
-  !-
-  ! lpj_fire
-  !-
-
-  ! What fraction of a burned plant compartment goes into the atmosphere
-  !   (rest into litter)
-  REAL(r_std), SAVE, DIMENSION(nparts) :: co2frac = (/ .95, .95, 0., 0.3, 0., 0., .95, .95 /)
-
-  !-
-  ! stomate_litter 
-  !-
-
-  ! C/N ratio
-  REAL(r_std), SAVE, DIMENSION(nparts) :: CN = 40.0 
-  ! Lignine/C ratio of the different plant parts
-  REAL(r_std), SAVE, DIMENSION(nparts) :: LC = (/ 0.22, 0.35, 0.35, 0.35, 0.35, 0.22, 0.22, 0.22 /)
-  ! corresponding to frac_soil(istructural,iactive,iabove) 
-  REAL(r_std), SAVE      ::  frac_soil_struct_aa = .55
-  ! corresponding to frac_soil(istructural,iactive,ibelow)
-  REAL(r_std), SAVE      :: frac_soil_struct_ab = .45
-  ! corresponding to frac_soil(istructural,islow,iabove)
-  REAL(r_std), SAVE      ::  frac_soil_struct_sa = .7
-  ! corresponding to frac_soil(istructural,islow,ibelow) 
-  REAL(r_std), SAVE      ::  frac_soil_struct_sb = .7
-  ! corresponding to frac_soil(imetabolic,iactive,iabove)
-  REAL(r_std), SAVE      ::  frac_soil_metab_aa = .45
-  ! corresponding to frac_soil(imetabolic,iactive,ibelow)
-  REAL(r_std), SAVE      ::  frac_soil_metab_ab = .45
-  !-
-  ! stomate_soilcarbon
-  !-
-  ! frac_carb_coefficients
-  ! from active pool: depends on clay content
-  ! correspnding to  frac_carb(:,iactive,iactive)
-  REAL(r_std), SAVE      :: frac_carb_aa = 0.0
-  ! correspnding to  frac_carb(:,iactive,ipassive)
-  REAL(r_std), SAVE      :: frac_carb_ap = 0.004
-  !frac_carb(;;iactive,islow) is computed in stomate_soilcarbon.f90
-  !-
-  ! from slow pool
-  ! correspnding to  frac_carb(:,islow,islow)
-  REAL(r_std), SAVE      :: frac_carb_ss = 0.0  
-  ! correspnding to  frac_carb(:,islow,iactive)
-  REAL(r_std), SAVE      :: frac_carb_sa = .42
-  ! correspnding to  frac_carb(:,islow,ipassive)
-  REAL(r_std), SAVE      :: frac_carb_sp = .03
-  !-
-  ! from passive pool
-  ! correspnding to  frac_carb(:,ipassive,ipassive)
-  REAL(r_std), SAVE      :: frac_carb_pp = .0
-  ! correspnding to  frac_carb(:,ipassive,iactive)
-  REAL(r_std), SAVE      :: frac_carb_pa = .45
-  ! correspnding to  frac_carb(:,ipassive,islow)
-  REAL(r_std), SAVE      :: frac_carb_ps = .0
- 
-
-!----------------------------------------
-!---------------------------------------
-! COEFFICIENTS OF EQUATIONS
-!-------------------------------------
-!---------------------------------------
-
-  !---------
-  ! SECHIBA
-  !---------
-  !-
-  ! diffuco
-  !-
-  REAL(r_std),PARAMETER :: Tetens_1 = 0.622   
-  REAL(r_std),PARAMETER :: Tetens_2 = 0.378
-  REAL(r_std),PARAMETER :: std_ci_frac = 0.667
-  REAL(r_std),PARAMETER :: alpha_j = 0.8855
-  REAL(r_std),PARAMETER :: curve_assim = 0.7
-  REAL(r_std),PARAMETER :: WJ_coeff1 = 4.5
-  REAL(r_std),PARAMETER :: WJ_coeff2 = 10.5
-  REAL(r_std),PARAMETER :: Vc_to_Rd_ratio = 0.011
-  REAL(r_std),PARAMETER :: O2toCO2_stoechio = 1.6
-  REAL(r_std),PARAMETER :: mmol_to_m_1 = 0.0244
-  REAL(r_std),PARAMETER  :: RG_to_PAR = 0.5 
-  REAL(r_std),PARAMETER  :: W_to_mmol = 4.6 ! W_to_mmol * RG_to_PAR = 2.3
-  !
-  REAL(r_std), SAVE      :: lai_level_depth = .15
-  REAL(r_std), SAVE      :: x1_coef =  0.177
-  REAL(r_std), SAVE      :: x1_Q10 =  0.069
-  REAL(r_std), SAVE      :: quantum_yield =  0.092
-  REAL(r_std), SAVE      :: kt_coef = 0.7     
-  REAL(r_std), SAVE      :: kc_coef = 39.09
-  REAL(r_std), SAVE      :: Ko_Q10 = .085
-  REAL(r_std), SAVE      :: Oa = 210000.
-  REAL(r_std), SAVE      :: Ko_coef =  2.412
-  REAL(r_std), SAVE      :: CP_0 = 42.
-  REAL(r_std), SAVE      :: CP_temp_coef = 9.46 
-  REAL(r_std), SAVE      :: CP_temp_ref = 25.
-  !
-  REAL(r_std), SAVE, DIMENSION(2)  :: rt_coef = (/ 0.8, 1.3 /) 
-  REAL(r_std), SAVE, DIMENSION(2)  :: vc_coef = (/ 0.39, 0.3 /)
-  !
-  ! coefficients of the polynome of degree 5 used inthe equation of coeff_dew_veg
-  REAL(r_std), SAVE, DIMENSION(6)     :: dew_veg_poly_coeff = &
-  & (/ 0.887773, 0.205673, 0.110112, 0.014843,  0.000824,  0.000017 /) 
- 
-  !---------
-  ! LPJ
-  !---------
-  !-
-  ! lpj_crown
-  !-
-  REAL(r_std), SAVE      :: pipe_tune_exp_coeff = 1.6 
-  !
-  !-
-  ! lpj_establish
-  !-
-  REAL(r_std), SAVE      :: establish_scal_fact = 15.
-  REAL(r_std), SAVE      :: fpc_crit_max = .075
-  REAL(r_std), SAVE      :: fpc_crit_min= .05 
-  !
-  !-
-  ! lpj_fire
-  !-
-  REAL(r_std), SAVE, DIMENSION(3) :: bcfrac_coeff = (/ .3,  1.3,  88.2 /) 
-  REAL(r_std), SAVE, DIMENSION(4)  :: firefrac_coeff = (/ 0.45, 0.8, 0.6, 0.13 /)
-  !
-  !-
-  ! lpj_gap
-  !- 
-  REAL(r_std), SAVE      ::  availability_fact = 0.02
-  REAL(r_std), SAVE      ::  vigour_ref = 0.17
-  REAL(r_std), SAVE      ::  vigour_coeff = 70. 
-  !-
-  ! lpj_pftinout
-  !-
-  REAL(r_std), SAVE      :: RIP_time_min = 1.25
-  REAL(r_std), SAVE      :: npp_longterm_init = 10. 
-  REAL(r_std), SAVE      :: everywhere_init = 0.05
-  !
-
-  !---------
-  ! STOMATE
-  !---------
-  !-
-  ! stomate_alloc
-  !- 
-  REAL(r_std), PARAMETER  ::  max_possible_lai = 10. 
-  REAL(r_std), PARAMETER  ::  Nlim_Q10 = 10. 
-  !
-  REAL(r_std), SAVE      :: lai_max_to_happy = 0.5  
-  REAL(r_std), SAVE  ::  Nlim_tref = 25.
-  !
-  !-
-  ! stomate_data
-  !-
+
+  ! 3. Coefficients of equations
+
   REAL(r_std), SAVE  :: bm_sapl_carbres = 5.
   REAL(r_std), SAVE  :: bm_sapl_sapabove = 0.5
@@ -920,11 +874,39 @@
   REAL(r_std), SAVE, DIMENSION(2)  :: maxdia_coeff =(/ 100., 0.01/)
   REAL(r_std), SAVE, DIMENSION(4)  :: bm_sapl_leaf = (/ 4., 4., .8, 5./)
-  !
-  !-
-  ! stomate_litter
-  !-
-  REAL(r_std), PARAMETER    :: Q10 = 10.
-  !
-  REAL(r_std), SAVE      :: metabolic_ref_frac = 0.85
+
+
+
+                              !--------------------!
+                              ! stomate_litter.f90 !
+                              !--------------------!
+
+
+  ! 1. Scalar
+
+  ! scaling depth for soil activity (m)
+  REAL(r_std), SAVE    :: z_decomp = 0.2
+
+  ! 2. Arrays
+
+  ! C/N ratio
+  REAL(r_std), SAVE, DIMENSION(nparts) :: CN = 40.0 
+  ! Lignine/C ratio of the different plant parts
+  REAL(r_std), SAVE, DIMENSION(nparts) :: LC = (/ 0.22, 0.35, 0.35, 0.35, 0.35, 0.22, 0.22, 0.22 /)
+  ! corresponding to frac_soil(istructural,iactive,iabove) 
+  REAL(r_std), SAVE      ::  frac_soil_struct_aa = .55
+  ! corresponding to frac_soil(istructural,iactive,ibelow)
+  REAL(r_std), SAVE      :: frac_soil_struct_ab = .45
+  ! corresponding to frac_soil(istructural,islow,iabove)
+  REAL(r_std), SAVE      ::  frac_soil_struct_sa = .7
+  ! corresponding to frac_soil(istructural,islow,ibelow) 
+  REAL(r_std), SAVE      ::  frac_soil_struct_sb = .7
+  ! corresponding to frac_soil(imetabolic,iactive,iabove)
+  REAL(r_std), SAVE      ::  frac_soil_metab_aa = .45
+  ! corresponding to frac_soil(imetabolic,iactive,ibelow)
+  REAL(r_std), SAVE      ::  frac_soil_metab_ab = .45
+
+  ! 3. Coefficients of equations
+
+  REAL(r_std), SAVE      :: metabolic_ref_frac = 0.85  ! used by litter and soilcarbon
   REAL(r_std), SAVE      :: metabolic_LN_ratio = 0.018    
   REAL(r_std), SAVE      :: tau_metabolic = .066
@@ -934,34 +916,109 @@
   REAL(r_std), SAVE      :: litter_struct_coef = 3.
   REAL(r_std), SAVE, DIMENSION(3)   :: moist_coeff = (/ 1.1,  2.4,  0.29 /)
-  !
-  !-
-  ! stomate_phenology
-  !-
+
+
+
+                             !-----------------!
+                             ! stomate_lpj.f90 !
+                             !-----------------!
+
+  ! 1. Scalar
+
+  REAL(r_std), SAVE    :: frac_turnover_daily = 0.55
+
+
+                             !-----------------!
+                             ! stomate_npp.f90 !
+                             !-----------------!
+
+  ! 1. Scalar
+
+  ! maximum fraction of allocatable biomass used for maintenance respiration
+  REAL(r_std), SAVE   :: tax_max = 0.8
+
+
+                             !-----------------------!
+                             ! stomate_phenology.f90 !
+                             !-----------------------!
+
+
+
+  ! 1. Scalar
+
+  ! take carbon from atmosphere if carbohydrate reserve too small?
+  LOGICAL, SAVE                                         :: always_init = .FALSE.
+  ! minimum time (d) since last beginning of a growing season
+  REAL(r_std), SAVE                                      :: min_growthinit_time = 300.
+  ! moisture availability above which moisture tendency doesn't matter
+  REAL(r_std), SAVE                                   :: moiavail_always_tree = 1.0
+  REAL(r_std), SAVE                                   :: moiavail_always_grass = 0.6
+  ! monthly temp. above which temp. tendency doesn't matter
+  REAL(r_std), SAVE                                   ::  t_always
+  REAL(r_std), SAVE                                   ::  t_always_add = 10.
+
+  ! 3. Coefficients of equations
+  
   REAL(r_std), SAVE      :: gddncd_ref = 603.
   REAL(r_std), SAVE      :: gddncd_curve = 0.0091
   REAL(r_std), SAVE      :: gddncd_offset = 64.
-  !
-  !-
-  ! stomate_prescribe
-  !-
+
+
+
+
+                             !-----------------------!
+                             ! stomate_prescribe.f90 !
+                             !-----------------------!
+
+  ! 3. Coefficients of equations
+
   REAL(r_std), SAVE      :: cn_tree = 4.
   REAL(r_std), SAVE      :: bm_sapl_rescale = 40.
-  !
-  !-
-  ! stomate_resp
-  !-
+
+
+
+                             !------------------!
+                             ! stomate_resp.f90 !
+                             !------------------!
+
+  ! 3. Coefficients of equations
+
   REAL(r_std), SAVE      :: maint_resp_min_vmax = 0.3  
   REAL(r_std), SAVE      :: maint_resp_coeff = 1.4
-  !
-  !-
-  ! stomate_season
-  !-
-  REAL(r_std), SAVE  :: ncd_max_year = 3.
-  REAL(r_std), SAVE  :: gdd_threshold = 5.
-  REAL(r_std), SAVE  :: green_age_ever = 2.
-  REAL(r_std), SAVE  :: green_age_dec = 0.5
-  !-
-  ! stomate_soilcarbon
-  !-
+
+
+
+                             !------------------------!
+                             ! stomate_soilcarbon.f90 !
+                             !------------------------!
+
+  ! 2. Arrays 
+
+  ! frac_carb_coefficients
+  ! from active pool: depends on clay content
+  ! correspnding to  frac_carb(:,iactive,iactive)
+  REAL(r_std), SAVE      :: frac_carb_aa = 0.0
+  ! correspnding to  frac_carb(:,iactive,ipassive)
+  REAL(r_std), SAVE      :: frac_carb_ap = 0.004
+  !frac_carb(;;iactive,islow) is computed in stomate_soilcarbon.f90
+  !-
+  ! from slow pool
+  ! correspnding to  frac_carb(:,islow,islow)
+  REAL(r_std), SAVE      :: frac_carb_ss = 0.0  
+  ! correspnding to  frac_carb(:,islow,iactive)
+  REAL(r_std), SAVE      :: frac_carb_sa = .42
+  ! correspnding to  frac_carb(:,islow,ipassive)
+  REAL(r_std), SAVE      :: frac_carb_sp = .03
+  !-
+  ! from passive pool
+  ! correspnding to  frac_carb(:,ipassive,ipassive)
+  REAL(r_std), SAVE      :: frac_carb_pp = .0
+  ! correspnding to  frac_carb(:,ipassive,iactive)
+  REAL(r_std), SAVE      :: frac_carb_pa = .45
+  ! correspnding to  frac_carb(:,ipassive,islow)
+  REAL(r_std), SAVE      :: frac_carb_ps = .0
+
+
+  ! 3. Coefficients of equations
+
   REAL(r_std), SAVE      :: active_to_pass_clay_frac = .68  
   !residence times in carbon pools (days)
@@ -971,8 +1028,13 @@
   !
   REAL(r_std), SAVE, DIMENSION(3) :: flux_tot_coeff = (/ 1.2, 1.4, .75/)
-  !
-  !-
-  ! stomate_turnover
-  !-
+
+
+
+                             !----------------------!
+                             ! stomate_turnover.f90 !
+                             !----------------------!
+
+  ! 3.Coefficients of equations
+
   REAL(r_std), SAVE      ::  new_turnover_time_ref = 20.
   REAL(r_std), SAVE      ::  dt_turnover_time = 10. 
@@ -980,372 +1042,442 @@
   REAL(r_std), SAVE, DIMENSION(3)   :: leaf_age_crit_coeff = (/ 1.5, 0.75, 10./)
 
-!**************************************************************
+
+
+
+                             !------------------!
+                             ! stomate_vmax.f90 !
+                             !------------------!
+
+  ! 1. Scalar
+
+  ! offset (minimum relative vcmax)
+  REAL(r_std), SAVE                                      :: vmax_offset = 0.3
+  ! leaf age at which vmax attains vcmax_opt (in fraction of critical leaf age)
+  REAL(r_std), SAVE                                      :: leafage_firstmax = 0.03
+  ! leaf age at which vmax falls below vcmax_opt (in fraction of critical leaf age)
+  REAL(r_std), SAVE                                      :: leafage_lastmax = 0.5
+  ! leaf age at which vmax attains its minimum (in fraction of critical leaf age)
+  REAL(r_std), SAVE                                      :: leafage_old = 1.
+
+
+
+                             !--------------------!
+                             ! stomate_season.f90 !
+                             !--------------------!
+
+
+  ! 1. Scalar
+
+  ! rapport maximal GPP/GGP_max pour dormance
+  REAL(r_std), SAVE                                  :: gppfrac_dormance = 0.2
+  ! minimum gpp considered as not "lowgpp"
+  REAL(r_std), SAVE                                  :: min_gpp_allowed = 0.3
+  ! tau (year) for "climatologic variables
+  REAL(r_std), SAVE                                  :: tau_climatology = 20
+  ! parameters for herbivore activity
+  REAL(r_std), SAVE                                  :: hvc1 = 0.019
+  REAL(r_std), SAVE                                  :: hvc2 = 1.38
+  REAL(r_std), SAVE                                  :: leaf_frac_hvc =.33
+  ! maximum reference long term temperature (K)
+  REAL(r_std),SAVE :: tlong_ref_max = 303.1
+  ! minimum reference long term temperature (K)
+  REAL(r_std),SAVE :: tlong_ref_min = 253.1
+
+  ! 3. Coefficients of equations
+
+  REAL(r_std), SAVE  :: ncd_max_year = 3.
+  REAL(r_std), SAVE  :: gdd_threshold = 5.
+  REAL(r_std), SAVE  :: green_age_ever = 2.
+  REAL(r_std), SAVE  :: green_age_dec = 0.5
+
+
 
  CONTAINS
 
- ! Subroutine called for getin the new parameters values used in sechiba
- !
- SUBROUTINE getin_sechiba_parameters
-
-  IMPLICIT NONE
-  ! first call
-  LOGICAL, SAVE ::  first_call = .TRUE.
-
-  IF(first_call) THEN 
-
-!!$   CALL getin('DIAG_QSAT',diag_qsat)
-   !  
-   CALL getin('QWILT',qwilt)
-   CALL getin('MIN_RESDIS',min_resdis)
-   CALL getin('MIN_DRAIN',min_drain)
-   CALL getin('MAX_DRAIN',max_drain)
-   CALL getin('EXP_DRAIN',exp_drain)
-   CALL getin('MX_EAU_EAU',mx_eau_eau)
-   CALL getin('RSOL_CSTE',rsol_cste)
-   CALL getin('HCRIT_LITTER',hcrit_litter)
-   !-
-   CALL getin('SOILTYPE_DEFAULT',soiltype_default)
-   !-
-   CALL getin('MAXMASS_GLACIER',maxmass_glacier)
-   CALL getin('MIN_VEGFRAC',min_vegfrac)
-   !-
-   CALL getin('SNOWCRI',snowcri)
-   !-
-   CALL getin('SNOWCRI_ALB',snowcri_alb)
-   CALL getin('MIN_WIND',min_wind)
-   CALL getin('Z0_BARE',z0_bare)
-   CALL getin('Z0_ICE',z0_ice)
-   CALL getin('TCST_SNOWA',tcst_snowa)
-   CALL getin('MAX_SNOW_AGE',max_snow_age)
-   CALL getin('SNOW_TRANS',snow_trans)
-   CALL getin('ALB_DEADLEAF',alb_deadleaf)
-   CALL getin('ALB_ICE',alb_ice)
-   !-
-   CALL getin('Z0_OVER_HEIGHT',z0_over_height)
-   CALL getin('HEIGHT_DISPLACEMENT',height_displacement)
-   !-
-   CALL getin('NLAI',nlai)
-   CALL getin('LAIMAX',laimax)
-   CALL getin('XC4_1',xc4_1)
-   CALL getin('XC4_2',xc4_2)
-   !-
-   CALL getin('DMCS',dmcs)
-   CALL getin('DMCR',dmcr)
-   !-
-   CALL getin('VIS_DRY',vis_dry)
-   CALL getin('NIR_DRY',nir_dry)
-   CALL getin('VIS_WET',vis_wet)
-   CALL getin('NIR_WET',nir_wet)
-   CALL getin('ALBSOIL_VIS',albsoil_vis)
-   CALL getin('ALBSOIL_NIR',albsoil_nir)
-   !-
-   CALL getin('CLAYFRACTION_DEFAULT',clayfraction_default)
-   !
-   CALL getin('DEW_VEG_POLY_COEFF',dew_veg_poly_coeff)
-
-   first_call =.FALSE.
-
-  ENDIF
-
-  END SUBROUTINE getin_sechiba_parameters
-
-!*********************************************************
-
-  ! Subroutine called only if river_routing is activated
-
-  SUBROUTINE getin_routing_parameters
-
-  IMPLICIT NONE
-
-  LOGICAL, SAVE ::  first_call = .TRUE.
-
-  IF(first_call) THEN
-
-     CALL getin('CROP_COEF',crop_coef)
-
-     first_call =.FALSE.
-
-  ENDIF   
-
-  END SUBROUTINE getin_routing_parameters  
-
-!*******************************************************
-
-  ! Subroutine called only if hydrol_cwrr is activated
-
-  SUBROUTINE getin_hydrol_cwrr_parameters
-
-  IMPLICIT NONE
-
-  LOGICAL, SAVE ::  first_call = .TRUE.
-
+   SUBROUTINE getin_sechiba_parameters
+
+     IMPLICIT NONE
+     ! first call
+     LOGICAL, SAVE ::  first_call = .TRUE.
+     
+     IF(first_call) THEN 
+        
+        ! Global
+        ! DS by global I mean the parameters used by two or more modules
+        ! Example : the common parameters for both hydrology models
+        CALL getin_p('MAXMASS_GLACIER',maxmass_glacier)
+        CALL getin_p('SNOWCRI',snowcri)
+        CALL getin_p('SECHIBA_QSINT', qsintcst)
+        WRITE(numout, *)' SECHIBA_QSINT, qsintcst = ', qsintcst
+        CALL getin_p("HYDROL_SOIL_DEPTH", dpu_cste)
+        !
+        CALL getin_p('MIN_WIND',min_wind)
+        CALL getin_p('MAX_SNOW_AGE',max_snow_age)
+        CALL getin_p('SNOW_TRANS',snow_trans)
+        CALL getin_p('MX_EAU_EAU',mx_eau_eau)
+        !-
+        ! condveg
+        CALL getin_p('Z0_OVER_HEIGHT',z0_over_height)
+        CALL getin_p('HEIGHT_DISPLACEMENT',height_displacement)
+        CALL getin_p('Z0_BARE',z0_bare)
+        CALL getin_p('Z0_ICE',z0_ice)
+        CALL getin_p('TCST_SNOWA',tcst_snowa)
+        CALL getin_p('SNOWCRI_ALB',snowcri_alb)
+        !
+        CALL getin_p('VIS_DRY',vis_dry)
+        CALL getin_p('NIR_DRY',nir_dry)
+        CALL getin_p('VIS_WET',vis_wet)
+        CALL getin_p('NIR_WET',nir_wet)
+        CALL getin_p('ALBSOIL_VIS',albsoil_vis)
+        CALL getin_p('ALBSOIL_NIR',albsoil_nir)
+        !-
+        CALL getin_p('ALB_DEADLEAF',alb_deadleaf)
+        CALL getin_p('ALB_ICE',alb_ice)
+        !-
+        ! diffuco 
+        ! DS the rest of diffuco parameters are only read when ok_co2 is set to TRUE
+        CALL getin_p('NLAI',nlai)
+        CALL getin_p('LAIMAX',laimax)
+        CALL getin_p('XC4_1',xc4_1)
+        CALL getin_p('XC4_2',xc4_2)
+        CALL getin_p('DEW_VEG_POLY_COEFF',dew_veg_poly_coeff)
+        !-
+        ! slowproc
+        CALL getin_p('CLAYFRACTION_DEFAULT',clayfraction_default)
+        CALL getin_p('MIN_VEGFRAC',min_vegfrac)
+        CALL getin_p('SOILTYPE_DEFAULT',soiltype_default)
+        
+        
+        first_call =.FALSE.
+        
+     ENDIF
+     
+   END SUBROUTINE getin_sechiba_parameters
+!
+!=
+!
+   ! Subroutine called only if ok_co2 is activated
+   ! only for diffuco_trans_co2
+   
+   SUBROUTINE getin_co2_parameters
+     
+     IMPLICIT NONE
+     
+     LOGICAL, SAVE ::  first_call = .TRUE.
+     
+     IF(first_call) THEN
+        
+        CALL getin_p('LAI_LEVEL_DEPTH',lai_level_depth)
+        CALL getin_p('X1_COEF',x1_coef)
+        CALL getin_p('X1_Q10',x1_Q10)
+        CALL getin_p('QUANTUM_YIELD',quantum_yield)
+        CALL getin_p('KT_COEF',kt_coef)
+        CALL getin_p('KC_COEF',kc_coef)
+        CALL getin_p('KO_Q10',Ko_Q10)
+        CALL getin_p('OA',Oa)
+        CALL getin_p('KO_COEF',Ko_coef)
+        CALL getin_p('CP_0',CP_0)
+        CALL getin_p('CP_TEMP_COEF',cp_temp_coef)
+        CALL getin_p('CP_TEMP_REF',cp_temp_ref)
+        CALL getin_p('RT_COEF',rt_coef)
+        CALL getin_p('VC_COEF',vc_coef)
+        
+        first_call =.FALSE.
+        
+     ENDIF
+     
+   END SUBROUTINE getin_co2_parameters
+!
+!=
+!
+   SUBROUTINE getin_hydrolc_parameters
+     
+     LOGICAL, SAVE ::  first_call = .TRUE.
+     
+     IF(first_call) THEN 
+        
+        CALL getin_p('QWILT',qwilt)
+        CALL getin_p('MIN_RESDIS',min_resdis)
+        CALL getin_p('MIN_DRAIN',min_drain)
+        CALL getin_p('MAX_DRAIN',max_drain)
+        CALL getin_p('EXP_DRAIN',exp_drain)
+        CALL getin_p('RSOL_CSTE',rsol_cste)
+        CALL getin_p('HCRIT_LITTER',hcrit_litter)
+        
+        first_call =.FALSE.
+        
+     ENDIF
+     
+   END SUBROUTINE getin_hydrolc_parameters
+   
+!
+!=
+!
+   ! Subroutine called only if hydrol_cwrr is activated
+   
+   SUBROUTINE getin_hydrol_cwrr_parameters
+     
+     IMPLICIT NONE
+     
+     LOGICAL, SAVE ::  first_call = .TRUE.
+     
+     IF(first_call) THEN
+        
+        CALL getin_p('W_TIME',w_time)
+        CALL getin_p('NVAN',nvan)   
+        CALL getin_p('AVAN',avan)
+        CALL getin_p('MCR',mcr)
+        CALL getin_p('MCS',mcs)
+        CALL getin_p('KS',ks)
+        CALL getin_p('PCENT',pcent)
+        CALL getin_p('FREE_DRAIN_MAX',free_drain_max)
+        CALL getin_p('MCF',mcf)
+        CALL getin_p('MCW',mcw)
+        CALL getin_p('MC_AWET',mc_awet)
+        
+        first_call =.FALSE.
+        
+     ENDIF
+
+   END SUBROUTINE getin_hydrol_cwrr_parameters
+!
+!=
+!
+   SUBROUTINE getin_routing_parameters
+     
+     IMPLICIT NONE
+     
+     LOGICAL, SAVE ::  first_call = .TRUE.
+     
+     IF(first_call) THEN
+        
+        CALL getin_p('CROP_COEF',crop_coef)
+        
+        first_call =.FALSE.
+        
+     ENDIF
+     
+   END SUBROUTINE getin_routing_parameters
+!
+!=
+!
+   SUBROUTINE getin_stomate_parameters
+     
+    IMPLICIT NONE
+    
+    LOGICAL, SAVE ::  first_call = .TRUE.
+    
     IF(first_call) THEN
-
-       CALL getin('W_TIME',w_time)
-       CALL getin('NVAN',nvan)   
-       CALL getin('AVAN',avan)
-       CALL getin('MCR',mcr)
-       CALL getin('MCS',mcs)
-       CALL getin('KS',ks)
-       CALL getin('PCENT',pcent)
-       CALL getin('FREE_DRAIN_MAX',free_drain_max)
-       CALL getin('MCF',mcf)
-       CALL getin('MCW',mcw)
-       CALL getin('MC_AWET',mc_awet)
-
-       first_call =.FALSE.
-  
+       
+       ! constraints_parameters
+       CALL getin_p('TOO_LONG',too_long)
+       !-
+       ! fire parameters
+       CALL getin_p('TAU_FIRE',tau_fire)
+       CALL getin_p('LITTER_CRIT',litter_crit)
+       CALL getin_p('CO2FRAC',co2frac)
+       CALL getin_p('BCFRAC_COEFF',bcfrac_coeff)
+       CALL getin_p('FIREFRAC_COEFF',firefrac_coeff)
+       !-
+       ! gap parameters (+ lpj_const_mort)
+       CALL getin_p('AVAILABILITY_FACT', availability_fact)  
+       CALL getin_p('VIGOUR_REF',vigour_ref)
+       CALL getin_p('VIGOUR_COEFF',vigour_coeff) 
+       !-
+       ! allocation parameters
+       CALL getin_p('OK_MINRES',ok_minres)
+       CALL getin_p('TAU_LEAFINIT', tau_leafinit)
+       CALL getin_p('RESERVE_TIME_TREE',reserve_time_tree)
+       CALL getin_p('RESERVE_TIME_GRASS',reserve_time_grass)
+       CALL getin_p('R0',R0)
+       CALL getin_p('S0',S0)
+       CALL getin_p('F_FRUIT',f_fruit)
+       CALL getin_p('ALLOC_SAP_ABOVE_TREE',alloc_sap_above_tree)
+       CALL getin_p('ALLOC_SAP_ABOVE_GRASS',alloc_sap_above_grass)
+       CALL getin_p('MIN_LTOLSR',min_LtoLSR)
+       CALL getin_p('MAX_LTOLSR',max_LtoLSR)
+       CALL getin_p('Z_NITROGEN',z_nitrogen)
+       CALL getin_p('LAI_MAX_TO_HAPPY',lai_max_to_happy)
+       CALL getin_p('NLIM_TREF',Nlim_tref)   
+       !-
+       ! data parameters
+       CALL getin_p('PIPE_TUNE1',pipe_tune1)
+       CALL getin_p('PIPE_TUNE2',pipe_tune2)   
+       CALL getin_p('PIPE_TUNE3',pipe_tune3)
+       CALL getin_p('PIPE_TUNE4',pipe_tune4)
+       CALL getin_p('PIPE_DENSITY',pipe_density)
+       CALL getin_p('PIPE_K1',pipe_k1)
+       CALL getin_p('PIPE_TUNE_EXP_COEFF',pipe_tune_exp_coeff)
+       !
+       CALL getin_p('PRECIP_CRIT',precip_crit)
+       CALL getin_p('GDD_CRIT_ESTAB',gdd_crit_estab) 
+       CALL getin_p('FPC_CRIT',fpc_crit)
+       CALL getin_p('ALPHA_GRASS',alpha_grass)
+       CALL getin_p('ALPHA_TREE',alpha_tree)
+       !-
+       CALL getin_p('MASS_RATIO_HEART_SAP',mass_ratio_heart_sap)
+       CALL getin_p('FRAC_GROWTHRESP',frac_growthresp)
+       CALL getin_p('TAU_HUM_MONTH',tau_hum_month)
+       CALL getin_p('TAU_HUM_WEEK',tau_hum_week)
+       CALL getin_p('TAU_T2M_MONTH',tau_t2m_month)
+       CALL getin_p('TAU_T2M_WEEK',tau_t2m_week)
+       CALL getin_p('TAU_TSOIL_MONTH',tau_tsoil_month)
+       CALL getin_p('TAU_SOILHUM_MONTH',tau_soilhum_month)
+       CALL getin_p('TAU_GPP_WEEK',tau_gpp_week)
+       CALL getin_p('TAU_GDD',tau_gdd)
+       CALL getin_p('TAU_NGD',tau_ngd)
+       CALL getin_p('COEFF_TAU_LONGTERM',coeff_tau_longterm)
+       !-
+       CALL getin_p('BM_SAPL_CARBRES',bm_sapl_carbres)
+       CALL getin_p('BM_SAPL_SAPABOVE',bm_sapl_sapabove)
+       CALL getin_p('BM_SAPL_HEARTABOVE',bm_sapl_heartabove)
+       CALL getin_p('BM_SAPL_HEARTBELOW',bm_sapl_heartbelow)
+       CALL getin_p('INIT_SAPL_MASS_LEAF_NAT',init_sapl_mass_leaf_nat)
+       CALL getin_p('INIT_SAPL_MASS_LEAF_AGRI',init_sapl_mass_leaf_agri)
+       CALL getin_p('INIT_SAPL_MASS_CARBRES',init_sapl_mass_carbres)
+       CALL getin_p('INIT_SAPL_MASS_ROOT',init_sapl_mass_root)
+       CALL getin_p('INIT_SAPL_MASS_FRUIT',init_sapl_mass_fruit)
+       CALL getin_p('CN_SAPL_INIT',cn_sapl_init)
+       CALL getin_p('MIGRATE_TREE',migrate_tree)
+       CALL getin_p('MIGRATE_GRASS',migrate_grass)
+       CALL getin_p('MAXDIA_COEFF',maxdia_coeff)
+       CALL getin_p('LAI_INITMIN_TREE',lai_initmin_tree)
+       CALL getin_p('LAI_INITMIN_GRASS',lai_initmin_grass)
+       CALL getin_p('DIA_COEFF',dia_coeff)
+       CALL getin_p('MAXDIA_COEFF',maxdia_coeff)
+       CALL getin_p('BM_SAPL_LEAF',bm_sapl_leaf)
+       !-
+       ! litter parameters
+       CALL getin_p('METABOLIC_REF_FRAC',metabolic_ref_frac)
+       CALL getin_p('Z_DECOMP',z_decomp)
+       CALL getin_p('CN',CN)
+       CALL getin_p('LC',LC)
+       CALL getin_p('FRAC_SOIL_STRUCT_AA',frac_soil_struct_aa)
+       CALL getin_p('FRAC_SOIL_STRUCT_AB',frac_soil_struct_ab)
+       CALL getin_p('FRAC_SOIL_STRUCT_SA',frac_soil_struct_sa)
+       CALL getin_p('FRAC_SOIL_STRUCT_SB',frac_soil_struct_sb)
+       CALL getin_p('FRAC_SOIL_METAB_AA',frac_soil_metab_aa)
+       CALL getin_p('FRAC_SOIL_METAB_AB',frac_soil_metab_ab)
+       !
+       CALL getin_p('METABOLIC_LN_RATIO',metabolic_LN_ratio)   
+       CALL getin_p('TAU_METABOLIC',tau_metabolic)
+       CALL getin_p('TAU_STRUCT',tau_struct)
+       CALL getin_p('SOIL_Q10',soil_Q10)
+       CALL getin_p('TSOIL_REF',tsoil_ref)
+       CALL getin_p('LITTER_STRUCT_COEF',litter_struct_coef)
+       CALL getin_p('MOIST_COEFF',moist_coeff)
+       !-
+       ! lpj parameters
+       CALL getin_p('FRAC_TURNOVER_DAILY',frac_turnover_daily)   
+       !-
+       ! npp parameters
+       CALL getin_p('TAX_MAX',tax_max) 
+       !-
+       ! phenology parameters
+       CALL getin_p('ALWAYS_INIT',always_init)
+       CALL getin_p('MIN_GROWTHINIT_TIME',min_growthinit_time)
+       CALL getin_p('MOIAVAIL_ALWAYS_TREE',moiavail_always_tree)
+       CALL getin_p('MOIAVAIL_ALWAYS_GRASS',moiavail_always_grass)
+       CALL getin_p('T_ALWAYS_ADD',t_always_add)
+       !
+       CALL getin_p('GDDNCD_REF',gddncd_ref)
+       CALL getin_p('GDDNCD_CURVE',gddncd_curve)
+       CALL getin_p('GDDNCD_OFFSET',gddncd_offset)
+       !-
+       ! prescribe parameters
+       CALL getin_p('CN_TREE',cn_tree)
+       CALL getin_p('BM_SAPL_RESCALE',bm_sapl_rescale)
+       !-
+       ! respiration parameters
+       CALL getin_p('MAINT_RESP_MIN_VMAX',maint_resp_min_vmax)  
+       CALL getin_p('MAINT_RESP_COEFF',maint_resp_coeff)
+       !-
+       ! soilcarbon parameters
+       CALL getin_p('FRAC_CARB_AA',frac_carb_aa)
+       CALL getin_p('FRAC_CARB_AP',frac_carb_ap)   
+       CALL getin_p('FRAC_CARB_SS',frac_carb_ss)
+       CALL getin_p('FRAC_CARB_SA',frac_carb_sa)
+       CALL getin_p('FRAC_CARB_SP',frac_carb_sp)
+       CALL getin_p('FRAC_CARB_PP',frac_carb_pp)
+       CALL getin_p('FRAC_CARB_PA',frac_carb_pa)
+       CALL getin_p('FRAC_CARB_PS',frac_carb_ps)
+       !
+       CALL getin_p('ACTIVE_TO_PASS_CLAY_FRAC',active_to_pass_clay_frac)
+       CALL getin_p('CARBON_TAU_IACTIVE',carbon_tau_iactive)
+       CALL getin_p('CARBON_TAU_ISLOW',carbon_tau_islow)
+       CALL getin_p('CARBON_TAU_IPASSIVE',carbon_tau_ipassive)
+       CALL getin_p('FLUX_TOT_COEFF',flux_tot_coeff)
+       !-
+       ! turnover parameters
+       CALL getin_p('NEW_TURNOVER_TIME_REF',new_turnover_time_ref)
+       CALL getin_p('DT_TURNOVER_TIME',dt_turnover_time)
+       CALL getin_p('LEAF_AGE_CRIT_TREF',leaf_age_crit_tref)
+       CALL getin_p('LEAF_AGE_CRIT_COEFF',leaf_age_crit_coeff)
+       !-
+       ! vmax parameters
+       CALL getin_p('VMAX_OFFSET',vmax_offset)
+       CALL getin_p('LEAFAGE_FIRSTMAX',leafage_firstmax)
+       CALL getin_p('LEAFAGE_LASTMAX',leafage_lastmax)
+       CALL getin_p('LEAFAGE_OLD',leafage_old)
+       !-
+       ! season parameters
+       CALL getin_p('GPPFRAC_DORMANCE',gppfrac_dormance)
+       CALL getin_p('MIN_GPP_ALLOWED',min_gpp_allowed)
+       CALL getin_p('TAU_CLIMATOLOGY',tau_climatology)
+       CALL getin_p('HVC1',hvc1)
+       CALL getin_p('HVC2',hvc2)
+       CALL getin_p('LEAF_FRAC_HVC',leaf_frac_hvc)
+       !
+       CALL getin_p('TLONG_REF_MAX',tlong_ref_max)
+       CALL getin_p('TLONG_REF_MIN',tlong_ref_min)
+       !
+       CALL getin_p('NCD_MAX_YEAR',ncd_max_year)
+       CALL getin_p('GDD_THRESHOLD',gdd_threshold)
+       CALL getin_p('GREEN_AGE_EVER',green_age_ever)
+       CALL getin_p('GREEN_AGE_DEC',green_age_dec)
+       
+       first_call = .FALSE.
+       
     ENDIF
-
-  END SUBROUTINE getin_hydrol_cwrr_parameters
-!--------------------------------------------
-
-  ! Subroutine called only if ok_co2 is activated
-  ! only for diffuco_trans_co2
-
-  SUBROUTINE getin_co2_parameters
-
-  IMPLICIT NONE
-
-  LOGICAL, SAVE ::  first_call = .TRUE.
-
+    
+  END SUBROUTINE getin_stomate_parameters
+!
+!=
+!
+  SUBROUTINE getin_dgvm_parameters   
+    
+    IMPLICIT NONE
+    
+    LOGICAL, SAVE ::  first_call = .TRUE.
+    
     IF(first_call) THEN
-
-       CALL getin('LAI_LEVEL_DEPTH',lai_level_depth)
-       CALL getin('X1_COEF',x1_coef)
-       CALL getin('X1_Q10',x1_Q10)
-       CALL getin('QUANTUM_YIELD',quantum_yield)
-       CALL getin('KT_COEF',kt_coef)
-       CALL getin('KC_COEF',kc_coef)
-       CALL getin('KO_Q10',Ko_Q10)
-       CALL getin('OA',Oa)
-       CALL getin('KO_COEF',Ko_coef)
-       CALL getin('CP_0',CP_0)
-       CALL getin('CP_TEMP_COEF',cp_temp_coef)
-       CALL getin('CP_TEMP_REF',cp_temp_ref)
-       CALL getin('RT_COEF',rt_coef)
-       CALL getin('VC_COEF',vc_coef)
-
-       first_call =.FALSE.
-
-   ENDIF
-
-  END SUBROUTINE getin_co2_parameters
-
-!**********************************************************
-
-  ! Subroutine called only if stomate is activated
-
-  SUBROUTINE getin_stomate_parameters
-
-    IMPLICIT NONE
-
-    LOGICAL, SAVE ::  first_call = .TRUE.
-
-    IF(first_call) THEN
+       
+       ! establish parameters
+       CALL getin_p('ESTAB_MAX_TREE',estab_max_tree)
+       CALL getin_p('ESTAB_MAX_GRASS',estab_max_grass)
+       CALL getin_p('ESTABLISH_SCAL_FACT',establish_scal_fact)
+       CALL getin_p('FPC_CRIT_MAX',fpc_crit_max)
+       CALL getin_p('FPC_CRIT_MIN',fpc_crit_min)
+       !-
+       ! light parameters
+       CALL getin_p('GRASS_MERCY',grass_mercy)
+       CALL getin_p('TREE_MERCY',tree_mercy)
+       CALL getin_p('ANNUAL_INCREASE',annual_increase)
+       CALL getin_p('MIN_COVER',min_cover)
+       !-
+       ! pftinout parameters
+       CALL getin_p('IND_0',ind_0)
+       CALL getin_p('MIN_AVAIL',min_avail)
+       CALL getin_p('RIP_TIME_MIN',RIP_time_min)
+       CALL getin_p('NPP_LONGTERM_INIT',npp_longterm_init)
+       CALL getin_p('EVERYWHERE_INIT',everywhere_init)
+       
+       first_call = .FALSE.
+       
+    ENDIF
     
-       CALL getin('TOO_LONG',too_long)
-       !-
-       CALL getin('TAU_FIRE',tau_fire)
-       CALL getin('LITTER_CRIT',litter_crit)
-       !-
-       CALL getin('OK_MINRES',ok_minres)
-       CALL getin('TAU_LEAFINIT', tau_leafinit)
-       CALL getin('RESERVE_TIME_TREE',reserve_time_tree)
-       CALL getin('RESERVE_TIME_GRASS',reserve_time_grass)
-       CALL getin('R0',R0)
-       CALL getin('S0',S0)
-       CALL getin('F_FRUIT',f_fruit)
-       CALL getin('ALLOC_SAP_ABOVE_TREE',alloc_sap_above_tree)
-       CALL getin('ALLOC_SAP_ABOVE_GRASS',alloc_sap_above_grass)
-       CALL getin('MIN_LTOLSR',min_LtoLSR)
-       CALL getin('MAX_LTOLSR',max_LtoLSR)
-       CALL getin('Z_NITROGEN',z_nitrogen)
-       !-
-       CALL getin('PIPE_TUNE_EXP_COEFF',pipe_tune_exp_coeff)
-       CALL getin('PIPE_TUNE1',pipe_tune1)
-       CALL getin('PIPE_TUNE2',pipe_tune2)   
-       CALL getin('PIPE_TUNE3',pipe_tune3)
-       CALL getin('PIPE_TUNE4',pipe_tune4)
-       CALL getin('PIPE_DENSITY',pipe_density)
-       CALL getin('PIPE_K1',pipe_k1)
-       CALL getin('ESTAB_MAX_TREE',estab_max_tree)
-       CALL getin('ESTAB_MAX_GRASS',estab_max_grass)
-       CALL getin('IND_0',ind_0)
-       CALL getin('MIN_COVER',min_cover)
-       CALL getin('PRECIP_CRIT',precip_crit)
-       CALL getin('GDD_CRIT_ESTAB',gdd_crit_estab) 
-       CALL getin('FPC_CRIT',fpc_crit)
-       CALL getin('FRAC_GROWTHRESP',frac_growthresp)
-       CALL getin('ALPHA_GRASS',alpha_grass)
-       CALL getin('ALPHA_TREE',alpha_tree)
-       CALL getin('TLONG_REF_MAX',tlong_ref_max)
-       CALL getin('TLONG_REF_MIN',tlong_ref_min)
-       !-
-       CALL getin('MASS_RATIO_HEART_SAP',mass_ratio_heart_sap)
-       CALL getin('TAU_HUM_MONTH',tau_hum_month)
-       CALL getin('TAU_HUM_WEEK',tau_hum_week)
-       CALL getin('TAU_T2M_MONTH',tau_t2m_month)
-       CALL getin('TAU_T2M_WEEK',tau_t2m_week)
-       CALL getin('TAU_TSOIL_MONTH',tau_tsoil_month)
-       CALL getin('TAU_SOILHUM_MONTH',tau_soilhum_month)
-       CALL getin('TAU_GPP_WEEK',tau_gpp_week)
-       CALL getin('TAU_GDD',tau_gdd)
-       CALL getin('TAU_NGD',tau_ngd)
-       CALL getin('COEFF_TAU_LONGTERM',coeff_tau_longterm)
-       !
-       CALL getin('FRAC_TURNOVER_DAILY',frac_turnover_daily)
-       !-
-       CALL getin('Z_DECOMP',z_decomp)
-       !-
-       CALL getin('TAX_MAX',tax_max)
-       !-
-       CALL getin('ALWAYS_INIT',always_init)
-       CALL getin('MIN_GROWTHINIT_TIME',min_growthinit_time)
-       CALL getin('MOIAVAIL_ALWAYS_TREE',moiavail_always_tree)
-       CALL getin('MOIAVAIL_ALWAYS_GRASS',moiavail_always_grass)
-       CALL getin('T_ALWAYS_ADD',t_always_add)
-       !-
-       CALL getin('VMAX_OFFSET',vmax_offset)
-       CALL getin('LEAFAGE_FIRSTMAX',leafage_firstmax)
-       CALL getin('LEAFAGE_LASTMAX',leafage_lastmax)
-       CALL getin('LEAFAGE_OLD',leafage_old)
-       !-
-       CALL getin('GPPFRAC_DORMANCE',gppfrac_dormance)
-       CALL getin('MIN_GPP_ALLOWED',min_gpp_allowed)
-       CALL getin('TAU_CLIMATOLOGY',tau_climatology)
-       CALL getin('HVC1',hvc1)
-       CALL getin('HVC2',hvc2)
-       CALL getin('LEAF_FRAC_HVC',leaf_frac_hvc)
-       !-
-       CALL getin('CO2FRAC',co2frac)
-       CALL getin('CN',CN)
-       CALL getin('LC',LC)
-       !-
-       CALL getin('FRAC_SOIL_STRUCT_AA',frac_soil_struct_aa)
-       CALL getin('FRAC_SOIL_STRUCT_AB',frac_soil_struct_ab)
-       CALL getin('FRAC_SOIL_STRUCT_SA',frac_soil_struct_sa)
-       CALL getin('FRAC_SOIL_STRUCT_SB',frac_soil_struct_sb)
-       CALL getin('FRAC_SOIL_METAB_AA',frac_soil_metab_aa)
-       CALL getin('FRAC_SOIL_METAB_AB',frac_soil_metab_ab)
-       !-
-       CALL getin('FRAC_CARB_AA',frac_carb_aa)
-       CALL getin('FRAC_CARB_AP',frac_carb_ap)   
-       CALL getin('FRAC_CARB_SS',frac_carb_ss)
-       CALL getin('FRAC_CARB_SA',frac_carb_sa)
-       CALL getin('FRAC_CARB_SP',frac_carb_sp)
-       CALL getin('FRAC_CARB_PP',frac_carb_pp)
-       CALL getin('FRAC_CARB_PA',frac_carb_pa)
-       CALL getin('FRAC_CARB_PS',frac_carb_ps)
-
-       !---------------------------------------
-       ! COEFFICIENTS OF EQUATIONS
-       !-------------------------------------
-       !
-       !-
-       CALL getin('BCFRAC_COEFF',bcfrac_coeff)
-       CALL getin('FIREFRAC_COEFF',firefrac_coeff)
-       !-
-       CALL getin('AVAILABILITY_FACT', availability_fact)  
-       CALL getin('VIGOUR_REF',vigour_ref)
-       CALL getin('VIGOUR_COEFF',vigour_coeff)
-       !-
-       CALL getin('RIP_TIME_MIN',RIP_time_min)
-       CALL getin('NPP_LONGTERM_INIT',npp_longterm_init)
-       CALL getin('EVERYWHERE_INIT',everywhere_init)
-       !
-       !-
-       CALL getin('LAI_MAX_TO_HAPPY',lai_max_to_happy)
-       CALL getin('NLIM_TREF',Nlim_tref)   
-       !-
-       CALL getin('BM_SAPL_CARBRES',bm_sapl_carbres)
-       CALL getin('BM_SAPL_SAPABOVE',bm_sapl_sapabove)
-       CALL getin('BM_SAPL_HEARTABOVE',bm_sapl_heartabove)
-       CALL getin('BM_SAPL_HEARTBELOW',bm_sapl_heartbelow)
-       CALL getin('INIT_SAPL_MASS_LEAF_NAT',init_sapl_mass_leaf_nat)
-       CALL getin('INIT_SAPL_MASS_LEAF_AGRI',init_sapl_mass_leaf_agri)
-       CALL getin('INIT_SAPL_MASS_CARBRES',init_sapl_mass_carbres)
-       CALL getin('INIT_SAPL_MASS_ROOT',init_sapl_mass_root)
-       CALL getin('INIT_SAPL_MASS_FRUIT',init_sapl_mass_fruit)
-       CALL getin('CN_SAPL_INIT',cn_sapl_init)
-       CALL getin('MIGRATE_TREE',migrate_tree)
-       CALL getin('MIGRATE_GRASS',migrate_grass)
-       CALL getin('MAXDIA_COEFF',maxdia_coeff)
-       CALL getin('LAI_INITMIN_TREE',lai_initmin_tree)
-       CALL getin('LAI_INITMIN_GRASS',lai_initmin_grass)
-       CALL getin('DIA_COEFF',dia_coeff)
-       CALL getin('MAXDIA_COEFF',maxdia_coeff)
-       CALL getin('BM_SAPL_LEAF',bm_sapl_leaf)
-       !-
-       CALL getin('METABOLIC_REF_FRAC',metabolic_ref_frac)
-       CALL getin('METABOLIC_LN_RATIO',metabolic_LN_ratio)   
-       CALL getin('TAU_METABOLIC',tau_metabolic)
-       CALL getin('TAU_STRUCT',tau_struct)
-       CALL getin('SOIL_Q10',soil_Q10)
-       CALL getin('TSOIL_REF',tsoil_ref)
-       CALL getin('LITTER_STRUCT_COEF',litter_struct_coef)
-       CALL getin('MOIST_COEFF',moist_coeff)
-       !-
-       CALL getin('GDDNCD_REF',gddncd_ref)
-       CALL getin('GDDNCD_CURVE',gddncd_curve)
-       CALL getin('GDDNCD_OFFSET',gddncd_offset)
-       !-
-       CALL getin('CN_TREE',cn_tree)
-       CALL getin('BM_SAPL_RESCALE',bm_sapl_rescale)
-       !-
-       CALL getin('MAINT_RESP_MIN_VMAX',maint_resp_min_vmax)  
-       CALL getin('MAINT_RESP_COEFF',maint_resp_coeff)
-       !-
-       CALL getin('NCD_MAX_YEAR',ncd_max_year)
-       CALL getin('GDD_THRESHOLD',gdd_threshold)
-       CALL getin('GREEN_AGE_EVER',green_age_ever)
-       CALL getin('GREEN_AGE_DEC',green_age_dec)
-       !-
-       CALL getin('ACTIVE_TO_PASS_CLAY_FRAC',active_to_pass_clay_frac)
-       CALL getin('CARBON_TAU_IACTIVE',carbon_tau_iactive)
-       CALL getin('CARBON_TAU_ISLOW',carbon_tau_islow)
-       CALL getin('CARBON_TAU_IPASSIVE',carbon_tau_ipassive)
-       CALL getin('FLUX_TOT_COEFF',flux_tot_coeff)
-       !-
-       CALL getin('NEW_TURNOVER_TIME_REF',new_turnover_time_ref)
-       CALL getin('DT_TURNOVER_TIME',dt_turnover_time)
-       CALL getin('LEAF_AGE_CRIT_TREF',leaf_age_crit_tref)
-       CALL getin('LEAF_AGE_CRIT_COEFF',leaf_age_crit_coeff)
-
-       first_call = .FALSE.
-
-    ENDIF
-
- END SUBROUTINE getin_stomate_parameters
-
-!******************************************
-
- SUBROUTINE getin_dgvm_parameters   
-   
-   IMPLICIT NONE
-
-    LOGICAL, SAVE ::  first_call = .TRUE.
-
-    IF(first_call) THEN
-
-          CALL getin('ESTABLISH_SCAL_FACT',establish_scal_fact)
-          CALL getin('FPC_CRIT_MAX',fpc_crit_max)
-          CALL getin('FPC_CRIT_MIN',fpc_crit_min)
-          !
-          CALL getin('GRASS_MERCY',grass_mercy)
-          CALL getin('TREE_MERCY',tree_mercy)
-          CALL getin('ANNUAL_INCREASE',annual_increase)
-          !
-          CALL getin('MIN_AVAIL',min_avail)
-          CALL getin('RIP_TIME_MIN',RIP_time_min)
-          CALL getin('NPP_LONGTERM_INIT',npp_longterm_init)
-          CALL getin('EVERYWHERE_INIT',everywhere_init)
-
-          first_call = .FALSE.
-       
-     ENDIF
-
-
-   END SUBROUTINE getin_dgvm_parameters
+    
+  END SUBROUTINE getin_dgvm_parameters
+
 
 !--------------------
Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_parameters/constantes_mtc.f90
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_parameters/constantes_mtc.f90	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_parameters/constantes_mtc.f90	(revision 257)
@@ -75,5 +75,8 @@
   &    .TRUE.,  .TRUE.,  .TRUE., .TRUE., .FALSE., &
   &    .FALSE., .FALSE., .FALSE. /)
-  !-
+  ! used in diffuco
+  REAL(r_std), PARAMETER, DIMENSION(nvmc)        :: rveg_mtc = &  
+  & (/ 1., 1., 1., 1., 1., 1. ,1. ,1. ,1. ,1. ,1. ,1., 1. /)
+  !
   !-
   ! 2 .Stomate
@@ -95,4 +98,108 @@
   &              .TRUE.,  .TRUE.,  .TRUE.,  .TRUE., .FALSE., .FALSE. /)
 
+  !>> DS new for merge in the trunk   ! 15/06/2011 
+  ! Add for writing history files in stomate_lpj.f90 'treeFracPrimDec' and 'treeFracPrimEver'
+  ! is PFT deciduous ?
+  LOGICAL, PARAMETER, DIMENSION(nvmc)    :: is_deciduous_mtc  = &
+  & (/  .FALSE.,  .FALSE.,  .TRUE.,  .FALSE.,  .FALSE.,  .TRUE.,  .FALSE.,   &
+  &              .TRUE.,  .TRUE.,  .FALSE.,  .FALSE., .FALSE., .FALSE. /)
+  ! is PFT evergreen ?
+  LOGICAL, PARAMETER, DIMENSION(nvmc)    :: is_evergreen_mtc  = &
+  & (/  .FALSE.,  .TRUE.,  .FALSE.,  .TRUE.,  .TRUE.,  .FALSE.,  .TRUE.,   &
+  &              .FALSE.,  .FALSE.,  .FALSE.,  .FALSE., .FALSE., .FALSE. /)        
+  ! is PFT C3 ?
+  LOGICAL, PARAMETER, DIMENSION(nvmc)    :: is_c3_mtc = &  
+  & (/.FALSE.,.FALSE.,.FALSE.,.FALSE.,.FALSE.,.FALSE.,         &
+  &   .FALSE.,.FALSE.,.FALSE.,.TRUE.,.FALSE.,.TRUE.,.FALSE. /)
+
+  !-------------------------------
+  ! Evapotranspiration -  sechiba
+  !-------------------------------
+  !
+  ! Structural resistance.
+  ! Value for rstruct_const : one for each vegetation type
+  REAL(r_std), PARAMETER, DIMENSION(nvmc)     :: rstruct_const_mtc = &
+  & (/ 0.0, 25.0, 25.0, 25.0, 25.0, 25.0, 25.0,   &
+  &   25.0, 25.0,  2.5,  2.0,  2.0,  2.0 /)
+  !-
+  ! A vegetation dependent constant used in the calculation
+  ! of the surface resistance.
+  ! Value for kzero one for each vegetation type
+  REAL(r_std), PARAMETER, DIMENSION(nvmc)     ::  kzero_mtc  =  &
+  & (/0.0, 12.E-5, 12.E-5, 12.e-5, 12.e-5, 25.e-5, 12.e-5,&
+  &    25.e-5, 25.e-5, 30.e-5, 30.e-5, 30.e-5, 30.e-5     /)
+
+
+  !-------------------
+  ! Water - sechiba
+  !-------------------
+  !
+  ! Maximum field capacity for each of the vegetations (Temporary).
+  ! Value of wmax_veg : max quantity of water :
+  ! one for each vegetation type en Kg/M3
+  REAL(r_std), PARAMETER, DIMENSION(nvmc)     :: wmax_veg_mtc  = &
+  & (/ 150., 150., 150., 150., 150., 150., 150., &
+  &    150., 150., 150., 150., 150., 150. /)
+  !-
+  ! Root profile description for the different vegetation types.
+  ! These are the factor in the exponential which gets
+  ! the root density as a function of depth
+  REAL(r_std), PARAMETER, DIMENSION(nvmc)     :: humcste_mtc  = &
+  & (/5., .8, .8, 1., .8, .8, 1., 1., .8, 4., 4., 4., 4./)
+  ! used in both hydrology modules
+   REAL(r_std), PARAMETER, DIMENSION(nvmc)              :: throughfall_by_mtc = &
+  & (/ 30., 30., 30., 30., 30., 30., 30., 30., 30., 30., 30., 30., 30. /)
+
+  !------------------
+  ! Albedo - sechiba
+  !------------------
+  !
+  ! Initial snow albedo value for each vegetation type
+  ! as it will be used in condveg_snow
+  ! Values are from the Thesis of S. Chalita (1992)
+  REAL(r_std), PARAMETER, DIMENSION(nvmc)     :: snowa_ini_mtc = &
+  & (/ 0.35, 0.,   0.,   0.14, 0.14, &
+  &    0.14, 0.14, 0.14, 0.14, 0.18, &
+  &    0.18, 0.18, 0.18 /)
+  !-
+  ! Decay rate of snow albedo value for each vegetation type
+  ! as it will be used in condveg_snow
+  ! Values are from the Thesis of S. Chalita (1992)
+  REAL(r_std), PARAMETER, DIMENSION(nvmc)     :: snowa_dec_mtc = &
+  & (/ 0.45, 0.,   0.,   0.06, 0.06, &
+  &    0.11, 0.06, 0.11, 0.11, 0.52, &
+  &    0.52, 0.52, 0.52 /)
+  !-
+  ! leaf albedo of vegetation type, visible albedo
+  REAL(r_std), PARAMETER, DIMENSION(nvmc)     :: alb_leaf_vis_mtc = &
+  & (/ .00, .04, .06, .06, .06, &
+  &    .06, .06, .06, .06, .10, &
+  &    .10, .10, .10 /) 
+  ! leaf albedo of vegetation type, near infrared albedo
+  REAL(r_std), PARAMETER, DIMENSION(nvmc)     :: alb_leaf_nir_mtc = &
+  & (/   .00, .20, .22, .22, .22, &
+  &      .22, .22, .22, .22, .30, &
+  &      .30, .30, .30   /)
+
+
+  !------------------------
+  !   Soil - vegetation
+  !------------------------
+  !
+  ! Table which contains the correlation between the soil types
+  ! and vegetation type. Two modes exist :
+  !  1) pref_soil_veg = 0 then we have an equidistribution
+  !     of vegetation on soil types
+  !  2) Else for each pft the prefered soil type is given :
+  !     1=sand, 2=loan, 3=clay
+  ! The variable is initialized in slowproc.
+  INTEGER(i_std), PARAMETER, DIMENSION(nvmc)     :: pref_soil_veg_sand_mtc = &
+  & (/ 1, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 /)
+
+  INTEGER(i_std), PARAMETER, DIMENSION(nvmc)     :: pref_soil_veg_loan_mtc = &
+  & (/ 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 /)
+
+  INTEGER(i_std), PARAMETER, DIMENSION(nvmc)     :: pref_soil_veg_clay_mtc = &
+  & (/ 3, 1, 1, 1, 1, 1 ,1 ,1 ,1 ,1 ,1 ,1, 1 /)
 
   !----------------
@@ -104,6 +211,6 @@
   ! flag for C4 vegetation types
   LOGICAL,PARAMETER, DIMENSION(nvmc) ::    is_c4_mtc  =        &  
-  & (/.false.,.false.,.false.,.false.,.false.,.false.,         &
-  &   .false.,.false.,.false.,.false.,.true.,.false.,.true. /)
+  & (/.FALSE.,.FALSE.,.FALSE.,.FALSE.,.FALSE.,.FALSE.,         &
+  &   .FALSE.,.FALSE.,.FALSE.,.FALSE.,.TRUE.,.FALSE.,.TRUE. /)
   !-
   ! Slope of the gs/A relation (Ball & al.)
@@ -409,4 +516,11 @@
   & (/ undef,    5.,        5.,       5.,        5.,       5.,      5.,   &
   &              5.,        5.,    undef,     undef,    undef,   undef   /)
+
+  !>> DS new for merge in the trunk
+  ! 15/06/2011 : add leaflife_mtc for the new formalism used for calculate sla
+  REAL(r_std) ,PARAMETER , DIMENSION(nvmc)   ::   leaflife_mtc = &
+  & (/  undef,      .5,      2.,     .33,      1.,     2.,      .33,   &
+  &            2.,      2.,      2.,      2.,     2.,        2. /)
+
   !-
   ! 3. Senescence
@@ -493,107 +607,4 @@
 
 
-  !-------------------------------
-  ! Evapotranspiration -  sechiba
-  !-------------------------------
-  !
-  ! Structural resistance.
-  ! Value for rstruct_const : one for each vegetation type
-  REAL(r_std), PARAMETER, DIMENSION(nvmc)     :: rstruct_const_mtc = &
-  & (/ 0.0, 25.0, 25.0, 25.0, 25.0, 25.0, 25.0,   &
-  &   25.0, 25.0,  2.5,  2.0,  2.0,  2.0 /)
-  !-
-  ! A vegetation dependent constant used in the calculation
-  ! of the surface resistance.
-  ! Value for kzero one for each vegetation type
-  REAL(r_std), PARAMETER, DIMENSION(nvmc)     ::  kzero_mtc  =  &
-  & (/0.0, 12.E-5, 12.E-5, 12.e-5, 12.e-5, 25.e-5, 12.e-5,&
-  &    25.e-5, 25.e-5, 30.e-5, 30.e-5, 30.e-5, 30.e-5     /)
-
-
-  !-------------------
-  ! Water - sechiba
-  !-------------------
-  !
-  ! Maximum field capacity for each of the vegetations (Temporary).
-  ! Value of wmax_veg : max quantity of water :
-  ! one for each vegetation type en Kg/M3
-  REAL(r_std), PARAMETER, DIMENSION(nvmc)     :: wmax_veg_mtc  = &
-  & (/ 150., 150., 150., 150., 150., 150., 150., &
-  &    150., 150., 150., 150., 150., 150. /)
-  !-
-  ! Root profile description for the different vegetation types.
-  ! These are the factor in the exponential which gets
-  ! the root density as a function of depth
-  REAL(r_std), PARAMETER, DIMENSION(nvmc)     :: humcste_mtc  = &
-  & (/5., .8, .8, 1., .8, .8, 1., 1., .8, 4., 4., 4., 4./)
-
-
-  !------------------
-  ! Albedo - sechiba
-  !------------------
-  !
-  ! Initial snow albedo value for each vegetation type
-  ! as it will be used in condveg_snow
-  ! Values are from the Thesis of S. Chalita (1992)
-  REAL(r_std), PARAMETER, DIMENSION(nvmc)     :: snowa_ini_mtc = &
-  & (/ 0.35, 0.,   0.,   0.14, 0.14, &
-  &    0.14, 0.14, 0.14, 0.14, 0.18, &
-  &    0.18, 0.18, 0.18 /)
-  !-
-  ! Decay rate of snow albedo value for each vegetation type
-  ! as it will be used in condveg_snow
-  ! Values are from the Thesis of S. Chalita (1992)
-  REAL(r_std), PARAMETER, DIMENSION(nvmc)     :: snowa_dec_mtc = &
-  & (/ 0.45, 0.,   0.,   0.06, 0.06, &
-  &    0.11, 0.06, 0.11, 0.11, 0.52, &
-  &    0.52, 0.52, 0.52 /)
-  !-
-  ! leaf albedo of vegetation type, visible albedo
-  REAL(r_std), PARAMETER, DIMENSION(nvmc)     :: alb_leaf_vis_mtc = &
-  & (/ .00, .04, .06, .06, .06, &
-  &    .06, .06, .06, .06, .10, &
-  &    .10, .10, .10 /) 
-  ! leaf albedo of vegetation type, near infrared albedo
-  REAL(r_std), PARAMETER, DIMENSION(nvmc)     :: alb_leaf_nir_mtc = &
-  & (/   .00, .20, .22, .22, .22, &
-  &      .22, .22, .22, .22, .30, &
-  &      .30, .30, .30   /)
-
-
-  !
-  !------------------------
-  !   Soil - vegetation
-  !------------------------
-
-  ! Table which contains the correlation between the soil types
-  ! and vegetation type. Two modes exist :
-  !  1) pref_soil_veg = 0 then we have an equidistribution
-  !     of vegetation on soil types
-  !  2) Else for each pft the prefered soil type is given :
-  !     1=sand, 2=loan, 3=clay
-  ! The variable is initialized in slowproc.
-  INTEGER(i_std), PARAMETER, DIMENSION(nvmc)     :: pref_soil_veg_sand_mtc = &
-  & (/ 1, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 /)
-
-  INTEGER(i_std), PARAMETER, DIMENSION(nvmc)     :: pref_soil_veg_loan_mtc = &
-  & (/ 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 /)
-
-  INTEGER(i_std), PARAMETER, DIMENSION(nvmc)     :: pref_soil_veg_clay_mtc = &
-  & (/ 3, 1, 1, 1, 1, 1 ,1 ,1 ,1 ,1 ,1 ,1, 1 /)
-
-
-  !
-  !-------------------------------
-  ! Parameters already externalised (from sechiba)
-  ! to classify
-  !----------------------------------
-  !
-  ! used in hydrolc
-   REAL(r_std), PARAMETER, DIMENSION(nvmc)              :: throughfall_by_mtc = &
-  & (/ 30., 30., 30., 30., 30., 30., 30., 30., 30., 30., 30., 30., 30. /)
-  ! used in diffuco
-   REAL(r_std), PARAMETER, DIMENSION(nvmc)        :: rveg_mtc = &  
-  & (/ 1., 1., 1., 1., 1., 1. ,1. ,1. ,1. ,1. ,1. ,1., 1. /)
-
-
+!------------------------
 END MODULE constantes_mtc
Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_parameters/pft_parameters.f90
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_parameters/pft_parameters.f90	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_parameters/pft_parameters.f90	(revision 257)
@@ -1,3 +1,3 @@
-!    09/2010
+! Version 0:   26/06/2010
 ! This is the module where we define the number of pfts and the values of the 
 ! parameters
@@ -9,4 +9,5 @@
 USE constantes
 USE ioipsl
+USE parallel
 USE defprec
 
@@ -50,4 +51,14 @@
   ! Is the vegetation type a tree ?
   LOGICAL,ALLOCATABLE, SAVE, DIMENSION (:) :: is_tree
+  !>> DS new for merge in the trunk   ! 15/06/2011 
+  ! Add for writing history files in stomate_lpj.f90 'treeFracPrimDec' and 'treeFracPrimEver'
+  ! is PFT deciduous ?
+  LOGICAL,ALLOCATABLE, SAVE, DIMENSION (:) :: is_deciduous
+  LOGICAL,ALLOCATABLE, SAVE, DIMENSION (:) :: is_evergreen
+  LOGICAL,ALLOCATABLE, SAVE, DIMENSION (:) :: is_c3
+  ! used in diffuco   !! Nathalie le 28 mars 2006 - sur proposition de Fred Hourdin, ajout
+  !! d'un potentiometre pour regler la resistance de la vegetation
+  REAL(r_std), ALLOCATABLE, SAVE, DIMENSION (:)      ::  rveg_pft
+
   !-
   ! 2 .Stomate
@@ -61,4 +72,71 @@
   LOGICAL, ALLOCATABLE, SAVE, DIMENSION (:) :: natural
 
+  !-------------------------------
+  ! Evapotranspiration -  sechiba
+  !-------------------------------
+  !-
+  ! Structural resistance.
+  ! Value for rstruct_const : one for each vegetation type
+  REAL(r_std), ALLOCATABLE, SAVE, DIMENSION (:) :: rstruct_const
+  !
+  ! A vegetation dependent constant used in the calculation
+  ! of the surface resistance.
+  ! Value for kzero one for each vegetation type
+  REAL(r_std), ALLOCATABLE, SAVE, DIMENSION (:) :: kzero  
+
+
+  !-------------------
+  ! Water - sechiba
+  !-------------------
+  !-
+  ! Maximum field capacity for each of the vegetations (Temporary).
+  ! Value of wmax_veg : max quantity of water :
+  ! one for each vegetation type en Kg/M3
+  REAL(r_std), ALLOCATABLE, SAVE, DIMENSION (:) :: wmax_veg
+  ! Root profile description for the different vegetation types.
+  ! These are the factor in the exponential which gets
+  ! the root density as a function of depth
+  REAL(r_std), ALLOCATABLE, SAVE, DIMENSION (:) :: humcste
+  ! used in hydrolc
+  REAL(r_std), ALLOCATABLE, SAVE, DIMENSION (:)   :: throughfall_by_pft
+
+
+  !------------------
+  ! Albedo - sechiba
+  !------------------
+  !-
+  ! Initial snow albedo value for each vegetation type
+  ! as it will be used in condveg_snow
+  ! Values are from the Thesis of S. Chalita (1992)
+  REAL(r_std), ALLOCATABLE, SAVE, DIMENSION (:) :: snowa_ini
+  !
+  ! Decay rate of snow albedo value for each vegetation type
+  ! as it will be used in condveg_snow
+  ! Values are from the Thesis of S. Chalita (1992)
+  REAL(r_std), ALLOCATABLE, SAVE, DIMENSION (:) :: snowa_dec
+  !
+  ! leaf albedo of vegetation type, visible albedo
+  REAL(r_std), ALLOCATABLE, SAVE, DIMENSION (:) :: alb_leaf_vis
+  ! leaf albedo of vegetation type, near infrared albedo
+  REAL(r_std), ALLOCATABLE, SAVE, DIMENSION (:) :: alb_leaf_nir
+  ! leaf albedo of vegetation type, VIS+NIR
+  REAL(r_std), ALLOCATABLE, SAVE, DIMENSION (:) :: alb_leaf
+
+
+  !------------------------
+  !   Soil - vegetation
+  !------------------------
+  !
+  ! Table which contains the correlation between the soil types
+  ! and vegetation type. Two modes exist :
+  !  1) pref_soil_veg = 0 then we have an equidistribution
+  !     of vegetation on soil types
+  !  2) Else for each pft the prefered soil type is given :
+  !     1=sand, 2=loan, 3=clay
+  ! The variable is initialized in slowproc.
+  INTEGER(i_std), ALLOCATABLE, SAVE, DIMENSION (:,:) :: pref_soil_veg
+  INTEGER(i_std), ALLOCATABLE, SAVE, DIMENSION (:) :: pref_soil_veg_sand
+  INTEGER(i_std), ALLOCATABLE, SAVE, DIMENSION (:) :: pref_soil_veg_loan
+  INTEGER(i_std), ALLOCATABLE, SAVE, DIMENSION (:) :: pref_soil_veg_clay
 
   !----------------
@@ -163,16 +241,14 @@
   ! for carbohydrate reserve, tabulated
   REAL(r_std), ALLOCATABLE, SAVE, DIMENSION (:) ::cm_zero_carbres
+
  
-
-
   !----------------
   ! Fire - stomate
   !----------------
-
+  !
   ! flamability: critical fraction of water holding capacity
   REAL(r_std), ALLOCATABLE, SAVE, DIMENSION (:) :: flam
   ! fire resistance
   REAL(r_std), ALLOCATABLE, SAVE, DIMENSION (:) :: resist
-
 
 
@@ -195,5 +271,4 @@
   ! 1 .Stomate
   !-
-  !
   ! maximum LAI, PFT-specific
   REAL(r_std), ALLOCATABLE, SAVE, DIMENSION (:) :: lai_max 
@@ -235,4 +310,7 @@
   REAL(r_std), ALLOCATABLE, SAVE, DIMENSION (:) :: alloc_max
   REAL(r_std), ALLOCATABLE, SAVE, DIMENSION (:) :: demi_alloc
+  !>> DS new for merge in the trunk
+  ! 15/06/2011 : add leaflife_mtc for the new formalism used for calculate sla
+  REAL(r_std), ALLOCATABLE, SAVE, DIMENSION (:) :: leaflife_tab
   !-
   ! 3. Senescence
@@ -282,73 +360,4 @@
 
 
-  !-------------------------------
-  ! Evapotranspiration -  sechiba
-  !-------------------------------
-  !-
-  ! Structural resistance.
-  ! Value for rstruct_const : one for each vegetation type
-  REAL(r_std), ALLOCATABLE, SAVE, DIMENSION (:) :: rstruct_const
-  !
-  ! A vegetation dependent constant used in the calculation
-  ! of the surface resistance.
-  ! Value for kzero one for each vegetation type
-  REAL(r_std), ALLOCATABLE, SAVE, DIMENSION (:) :: kzero  
-
-
-  !-------------------
-  ! Water - sechiba
-  !-------------------
-  !-
-  ! Maximum field capacity for each of the vegetations (Temporary).
-  ! Value of wmax_veg : max quantity of water :
-  ! one for each vegetation type en Kg/M3
-  REAL(r_std), ALLOCATABLE, SAVE, DIMENSION (:) :: wmax_veg
-  ! Root profile description for the different vegetation types.
-  ! These are the factor in the exponential which gets
-  ! the root density as a function of depth
-  REAL(r_std), ALLOCATABLE, SAVE, DIMENSION (:) :: humcste
-
-
-  !------------------
-  ! Albedo - sechiba
-  !------------------
-  !-
-  ! Initial snow albedo value for each vegetation type
-  ! as it will be used in condveg_snow
-  ! Values are from the Thesis of S. Chalita (1992)
-  REAL(r_std), ALLOCATABLE, SAVE, DIMENSION (:) :: snowa_ini
-  !
-  ! Decay rate of snow albedo value for each vegetation type
-  ! as it will be used in condveg_snow
-  ! Values are from the Thesis of S. Chalita (1992)
-  REAL(r_std), ALLOCATABLE, SAVE, DIMENSION (:) :: snowa_dec
-  !
-  ! leaf albedo of vegetation type, visible albedo
-  REAL(r_std), ALLOCATABLE, SAVE, DIMENSION (:) :: alb_leaf_vis
-  ! leaf albedo of vegetation type, near infrared albedo
-  REAL(r_std), ALLOCATABLE, SAVE, DIMENSION (:) :: alb_leaf_nir
-  ! leaf albedo of vegetation type, VIS+NIR
-  REAL(r_std), ALLOCATABLE, SAVE, DIMENSION (:) :: alb_leaf
-
-
-  !
-  !------------------------
-  !   Soil - vegetation
-  !------------------------
-
-  ! Table which contains the correlation between the soil types
-  ! and vegetation type. Two modes exist :
-  !  1) pref_soil_veg = 0 then we have an equidistribution
-  !     of vegetation on soil types
-  !  2) Else for each pft the prefered soil type is given :
-  !     1=sand, 2=loan, 3=clay
-  ! The variable is initialized in slowproc.
-  INTEGER(i_std), ALLOCATABLE, SAVE, DIMENSION (:,:) :: pref_soil_veg
-  INTEGER(i_std), ALLOCATABLE, SAVE, DIMENSION (:) :: pref_soil_veg_sand
-  INTEGER(i_std), ALLOCATABLE, SAVE, DIMENSION (:) :: pref_soil_veg_loan
-  INTEGER(i_std), ALLOCATABLE, SAVE, DIMENSION (:) :: pref_soil_veg_clay
-
-
-  !
   !--------------------------------------------
   ! Internal parameters used in stomate_data
@@ -370,15 +379,4 @@
 
 
-  !-------------------------------
-  ! Parameters already externalised (from sechiba)
-  ! to classify
-  !----------------------------------
-  !
-  ! used in hydrolc and hydrol
-  REAL(r_std), ALLOCATABLE, SAVE, DIMENSION (:)   :: throughfall_by_pft
-  ! used in diffuco   !! Nathalie le 28 mars 2006 - sur proposition de Fred Hourdin, ajout
-  !! d'un potentiometre pour regler la resistance de la vegetation
-  REAL(r_std), ALLOCATABLE, SAVE, DIMENSION (:)      ::  rveg_pft
-
 
 CONTAINS
@@ -397,18 +395,24 @@
    IF(l_first_define_pft) THEN
 
+      ! 1. First time step
       IF(long_print) THEN
          WRITE(numout,*) 'l_first_define_pft :we read the parameters from the def files'
       ENDIF
 
+      ! 2. Memory allocation
       ! Allocation of memory for the pfts-parameters
       CALL pft_parameters_alloc
 
+      ! 3. Correspondance table 
+      
+      ! 3.1 Initialisation of the correspondance table
       ! Initialisation of the correspondance table
       pft_to_mtc (:) = undef_integer
       
-      ! Reading of the conrrespondance table in the .def file
-      CALL getin('PFT_TO_MTC',pft_to_mtc)
-
-      ! Add the standard configuration
+      ! 3.2 Reading of the conrrespondance table in the .def file
+      CALL getin_p('PFT_TO_MTC',pft_to_mtc)
+
+      ! 3.3 If the user want to use the standard configuration, he needn't to fill the correspondance array
+      !     If the configuration is wrong, send a error message to the user.
       IF(nvm .EQ. 13 ) THEN
          IF(pft_to_mtc(1) .EQ. undef_integer) THEN
@@ -422,5 +426,7 @@
       ENDIF
 
-     ! What happened if pft_to_mtc(j) > nvmc (if the mtc doesn't exist)?
+      ! 3.4 Some error messages
+
+      ! 3.4.1 What happened if pft_to_mtc(j) > nvmc (if the mtc doesn't exist)?
        DO i = 1, nvm
           IF(pft_to_mtc(i) .GT. nvmc) THEN
@@ -431,5 +437,5 @@
 
 
-      ! Verify if pft_to_mtc(1) = 1 
+      ! 3.4.2 Check if pft_to_mtc(1) = 1 
        IF(pft_to_mtc(1) .NE. 1) THEN
           WRITE(numout,*) 'the first pft has to be the bare soil'
@@ -445,8 +451,8 @@
       
    
-      ! Initialisation of the pfts-parameters
+      ! 4.Initialisation of the pfts-parameters
       CALL pft_parameters_init
 
-      ! Could be useful : correspondance between the number of the pft
+      ! 5. A useful message to the user: correspondance between the number of the pft
       ! and the name of the associated mtc 
       DO i = 1,nvm
@@ -454,9 +460,12 @@
       ENDDO
 
-
-      !------------------------------------------------------!
-      ! Initialisation of tables 2D  which are used in the code !
-      !------------------------------------------------------!
-      !
+      ! 6. Initialisation of 2D arrays used in the code
+
+      !-alb_leaf
+      alb_leaf(:) = zero
+
+      !- pref_soil_veg 
+      pref_soil_veg(:,:) = zero_int
+
       !- pheno_gdd_crit
       pheno_gdd_crit(:,:) = zero 
@@ -470,14 +479,15 @@
       !-coeff_maint_zero
       coeff_maint_zero(:,:) = zero
-      !
-      !-alb_leaf
-      alb_leaf(:) = zero
-      !- pref_soil_veg (see slowproc)
+
+      ! 7. End message
+      IF(long_print) THEN
+         WRITE(numout,*) 'pft_parameters_done'
+      ENDIF
 
    ELSE 
 
-       l_first_define_pft = .FALSE.
+      l_first_define_pft = .FALSE.
        
-       RETURN
+      RETURN
 
    ENDIF
@@ -496,27 +506,54 @@
    !------------
 
-   ! Initialisation !! not all the parameters are initialized 
-
-   !----------------------
+   !
+   ! 1. Initialisation !! not all the parameters are initialized 
+   !
+
+   !-
    ! Vegetation structure 
-   !----------------------
-   !-
+   !-
+   !
    ! 1 .Sechiba
-   !-
+   !
    veget_ori_fixed_test_1(:) = zero
    llaimax(:) = zero
    llaimin(:) = zero
    height_presc(:) = zero
-   !-
+   rveg_pft(:) = zero
+   !
    ! 2 .Stomate
    !
    leaf_tab(:) = zero_int
    sla(:) = zero   
-   !----------------
+   !-
+   ! Evapotranspiration -  sechiba
+   !-
+   rstruct_const(:) = zero
+   kzero(:) = zero
+   !-
+   ! Water - sechiba
+   !-
+   wmax_veg(:) = zero
+   humcste(:) = zero
+   throughfall_by_pft(:) = zero
+   !-
+   ! Albedo - sechiba
+   !-
+   snowa_ini(:) = zero
+   snowa_dec(:) = zero
+   alb_leaf_vis(:) = zero
+   alb_leaf_nir(:) = zero
+   !-
+   ! Soil - vegetation
+   !-
+   pref_soil_veg_sand(:) = zero_int
+   pref_soil_veg_loan(:) = zero_int
+   pref_soil_veg_clay(:) = zero_int
+   !-
    ! Photosynthesis
-   !----------------
-   !-
+   !-
+   !
    ! 1 .CO2
-   !-
+   !
    gsslope(:) = zero
    gsoffset(:) = zero
@@ -526,8 +563,8 @@
    co2_topt_fix(:) = zero
    co2_tmax_fix(:) = zero
-   !-
+   ext_coeff(:) = zero
+   !
    ! 2 .Stomate
-   !-
-   ext_coeff(:) = zero
+   !
    vcmax_opt(:) = zero
    vjmax_opt(:) = zero
@@ -541,8 +578,7 @@
    tphoto_max_b(:) = zero
    tphoto_max_c(:) = zero
-   !----------------------
+   !-
    ! Respiration - stomate
-   !----------------------
-   !
+   !-
    maint_resp_slope_c(:) = zero
    maint_resp_slope_b(:) = zero
@@ -556,29 +592,27 @@
    cm_zero_fruit(:) = zero
    cm_zero_carbres(:) = zero
-   !----------------
+   !-
    ! Fire - stomate
-   !---------------
+   !-
    ! 
    flam(:) = zero
    resist(:) = zero
-   !----------------
+   !-
    ! Flux - LUC
-   !---------------
-   !
+   !-
    coeff_lcchange_1(:) = zero
    coeff_lcchange_10(:) = zero
    coeff_lcchange_100(:) = zero
-   !
-   !-----------
+   !-
    ! Phenology
-   !-----------
-   !-
+   !-
+   !
    ! 1 .Stomate
-   !-
+   !
    lai_max(:) = zero
    pheno_type(:) = zero_int
-   !-
+   !
    ! 2. Leaf Onset
-   !-
+   !
    pheno_gdd_crit_c(:) = zero
    pheno_gdd_crit_b(:) = zero
@@ -595,7 +629,9 @@
    alloc_max(:) = zero
    demi_alloc(:) = zero  
-   !-
+  !>> DS new for merge in the trunk 15/06/2011
+   leaflife_tab(:) = zero
+   !
    ! 3. Senescence
-   !-
+   !
    leaffall(:) = zero
    leafagecrit(:) = zero
@@ -608,39 +644,13 @@
    senescence_temp_b(:) = zero 
    senescence_temp_a(:) = zero 
-   !-----------
+   !-
    ! DGVM
-   !-----------
-   !
+   !-
    residence_time(:) = zero
    tmin_crit(:) = zero
    tcm_crit(:) = zero
-   !-------------------------------
-   ! Evapotranspiration -  sechiba
-   !-------------------------------
-   !-
-   rstruct_const(:) = zero
-   kzero(:) = zero
-   !-------------------
-   ! Water - sechiba
-   !-------------------
-   !-
-   wmax_veg(:) = zero
-   humcste(:) = zero
-   !------------------
-   ! Albedo - sechiba
-   !------------------
-   !-
-   snowa_ini(:) = zero
-   snowa_dec(:) = zero
-   alb_leaf_vis(:) = zero
-   alb_leaf_nir(:) = zero
-   !------------------------
-   !   Soil - vegetation
-   !------------------------
-   pref_soil_veg(:,:) = zero_int
-
-   !------------------------
+   !-
    !  Internal_parameters
-   !------------------------
+   !-
    lai_initmin(:) = zero
    bm_sapl(:,:) = zero
@@ -649,15 +659,9 @@
    cn_sapl(:) = zero
    leaf_timecst(:) = zero  
-   !-------------------------------
-   ! Parameters already externalised (from sechiba)
-   ! to classify
-   !----------------------------------
-   throughfall_by_pft(:) = zero
-   rveg_pft(:) = zero
-
-
-   !-------------------------------------------------------------!
-   ! Correspondance between the PFTs values and thes MTCs values !
-   !-------------------------------------------------------------!  
+
+
+   !
+   ! 2. Correspondance between the PFTs values and thes MTCs values 
+   !
  
    DO j= 1, nvm
@@ -666,10 +670,10 @@
       PFT_name(j) = MTC_name(pft_to_mtc(j))
 
-      !----------------------
+      !-
       ! Vegetation structure 
-      !----------------------
-      !-
+      !-
+      !
       ! 1 .Sechiba
-      !-
+      !
       veget_ori_fixed_test_1(j) = veget_ori_fixed_mtc(pft_to_mtc(j))
       llaimax(j) = llaimax_mtc(pft_to_mtc(j))
@@ -678,16 +682,50 @@
       type_of_lai(j) = type_of_lai_mtc(pft_to_mtc(j))
       is_tree(j) = is_tree_mtc(pft_to_mtc(j))
-      !-
+      rveg_pft(j) = rveg_mtc(pft_to_mtc(j))
+
+      !>> DS new for merge in the trunk   ! 15/06/2011 
+      ! Add for writing history files in stomate_lpj.f90 'treeFracPrimDec' and 'treeFracPrimEver'
+      is_deciduous(j) = is_deciduous_mtc(pft_to_mtc(j))
+      is_evergreen(j) = is_evergreen_mtc(pft_to_mtc(j))
+      is_c3(j) = is_c3(pft_to_mtc(j))
+
+      !
       ! 2 .Stomate
-      !- 
+      !
       leaf_tab(j) = leaf_tab_mtc(pft_to_mtc(j))
       sla(j) = sla_mtc(pft_to_mtc(j))
       natural(j) = natural_mtc(pft_to_mtc(j))
-      !----------------
+
+      !-
+      ! Evapotranspiration -  sechiba
+      !-
+      rstruct_const(j) = rstruct_const_mtc(pft_to_mtc(j))
+      kzero(j) = kzero_mtc(pft_to_mtc(j))
+      !-
+      ! Water - sechiba
+      !-
+      wmax_veg(j) = wmax_veg_mtc(pft_to_mtc(j))
+      humcste(j) = humcste_mtc(pft_to_mtc(j))
+      throughfall_by_pft(j) = throughfall_by_mtc(pft_to_mtc(j))
+      !-
+      ! Albedo - sechiba
+      !-
+      snowa_ini(j) = snowa_ini_mtc(pft_to_mtc(j))
+      snowa_dec(j) = snowa_dec_mtc(pft_to_mtc(j)) 
+      alb_leaf_vis(j) = alb_leaf_vis_mtc(pft_to_mtc(j))  
+      alb_leaf_nir(j) = alb_leaf_nir_mtc(pft_to_mtc(j))
+      !-
+      !   Soil - vegetation
+      !-
+      pref_soil_veg_sand(j) = pref_soil_veg_sand_mtc(pft_to_mtc(j))
+      pref_soil_veg_loan(j) = pref_soil_veg_loan_mtc(pft_to_mtc(j))
+      pref_soil_veg_clay(j) = pref_soil_veg_clay_mtc(pft_to_mtc(j))
+
+      !-
       ! Photosynthesis
-      !----------------
-      !-
+      !-
+      !
       ! 1 .CO2
-      !-
+      !
       is_c4(j) = is_c4_mtc(pft_to_mtc(j))
       gsslope(j) = gsslope_mtc(pft_to_mtc(j))
@@ -698,7 +736,7 @@
       co2_topt_fix(j) = co2_topt_fix_mtc(pft_to_mtc(j))
       co2_tmax_fix(j) = co2_tmax_fix_mtc(pft_to_mtc(j))
-      !-
+      !
       ! 2 .Stomate
-      !-
+      !
       ext_coeff(j) = ext_coeff_mtc(pft_to_mtc(j))
       vcmax_opt(j) = vcmax_opt_mtc(pft_to_mtc(j))
@@ -713,7 +751,7 @@
       tphoto_max_b(j) = tphoto_max_b_mtc(pft_to_mtc(j))
       tphoto_max_c(j) = tphoto_max_c_mtc(pft_to_mtc(j))
-      !----------------------
+      !-
       ! Respiration - stomate
-      !----------------------
+      !-
       maint_resp_slope_c(j) = maint_resp_slope_c_mtc(pft_to_mtc(j))               
       maint_resp_slope_b(j) = maint_resp_slope_b_mtc(pft_to_mtc(j))
@@ -727,27 +765,27 @@
       cm_zero_fruit(j) = cm_zero_fruit_mtc(pft_to_mtc(j))
       cm_zero_carbres(j) = cm_zero_carbres_mtc(pft_to_mtc(j))
-      !----------------
+      !-
       ! Fire - stomate
-      !---------------
+      !-
       flam(j) = flam_mtc(pft_to_mtc(j))
       resist(j) = resist_mtc(pft_to_mtc(j))
-      !----------------
+      !-
       ! Flux - LUC
-      !---------------
+      !-
       coeff_lcchange_1(j) = coeff_lcchange_1_mtc(pft_to_mtc(j))
       coeff_lcchange_10(j) = coeff_lcchange_10_mtc(pft_to_mtc(j))
       coeff_lcchange_100(j) = coeff_lcchange_100_mtc(pft_to_mtc(j))
-      !-----------
+      !-
       ! Phenology
-      !-----------
-      !-
+      !-
+      !
       ! 1 .Stomate
-      !-
+      !
       lai_max(j) = lai_max_mtc(pft_to_mtc(j))
       pheno_model(j) = pheno_model_mtc(pft_to_mtc(j))
       pheno_type(j) = pheno_type_mtc(pft_to_mtc(j))
-      !-
+      !
       ! 2. Leaf Onset
-      !-
+      !
       pheno_gdd_crit_c(j) = pheno_gdd_crit_c_mtc(pft_to_mtc(j))
       pheno_gdd_crit_b(j) = pheno_gdd_crit_b_mtc(pft_to_mtc(j))         
@@ -764,7 +802,9 @@
       alloc_max(j) = alloc_max_mtc(pft_to_mtc(j))
       demi_alloc(j) = demi_alloc_mtc(pft_to_mtc(j))
-      !-
+  !>> DS new for merge in the trunk   ! 15/06/2011 
+      leaflife_tab(j) = leaflife_mtc(pft_to_mtc(j))
+      !
       ! 3. Senescence
-      !-
+      !
       leaffall(j) = leaffall_mtc(pft_to_mtc(j))
       leafagecrit(j) = leafagecrit_mtc(pft_to_mtc(j))
@@ -778,46 +818,11 @@
       senescence_temp_b(j) = senescence_temp_b_mtc(pft_to_mtc(j))
       senescence_temp_a(j) = senescence_temp_a_mtc(pft_to_mtc(j))
-      !-----------
+      !-
       ! DGVM
-      !-----------
       residence_time(j) = residence_time_mtc(pft_to_mtc(j))
       tmin_crit(j) = tmin_crit_mtc(pft_to_mtc(j))
       tcm_crit(j) =  tcm_crit_mtc(pft_to_mtc(j))
       
-      !-------------------------------
-      ! Evapotranspiration -  sechiba
-      !-------------------------------
-      !-
-      rstruct_const(j) = rstruct_const_mtc(pft_to_mtc(j))
-      kzero(j) = kzero_mtc(pft_to_mtc(j))
-      !-------------------
-      ! Water - sechiba
-      !-------------------
-      !-
-      wmax_veg(j) = wmax_veg_mtc(pft_to_mtc(j))
-      humcste(j) = humcste_mtc(pft_to_mtc(j))
-      !------------------
-      ! Albedo - sechiba
-      !------------------
-      !-
-      snowa_ini(j) = snowa_ini_mtc(pft_to_mtc(j))
-      snowa_dec(j) = snowa_dec_mtc(pft_to_mtc(j)) 
-      alb_leaf_vis(j) = alb_leaf_vis_mtc(pft_to_mtc(j))  
-      alb_leaf_nir(j) = alb_leaf_nir_mtc(pft_to_mtc(j))
-      !------------------------
-      !   Soil - vegetation
-      !------------------------
-      pref_soil_veg_sand(j) = pref_soil_veg_sand_mtc(pft_to_mtc(j))
-      pref_soil_veg_loan(j) = pref_soil_veg_loan_mtc(pft_to_mtc(j))
-      pref_soil_veg_clay(j) = pref_soil_veg_clay_mtc(pft_to_mtc(j))
-      !-------------------------------
-      ! Parameters already externalised (from sechiba)
-      ! to classify
-      !---------------------------------- 
-      throughfall_by_pft(j) = throughfall_by_mtc(pft_to_mtc(j))
-      rveg_pft(j) = rveg_mtc(pft_to_mtc(j))
-
-  ! end loop over nvm    
-   ENDDO
+   ENDDO ! end loop over nvm 
 
  END SUBROUTINE pft_parameters_init
@@ -840,4 +845,16 @@
    l_error = l_error .OR. (ier .NE. 0)
    !-
+   !>> DS new for merge in the trunk   ! 15/06/2011 
+   ! Add for writing history files in stomate_lpj.f90 'treeFracPrimDec' and 'treeFracPrimEver'
+   ALLOCATE(is_deciduous(nvm),stat=ier)   
+   l_error = l_error .OR. (ier .NE. 0)
+   ALLOCATE(is_evergreen(nvm),stat=ier)  
+   l_error = l_error .OR. (ier .NE. 0)
+   ALLOCATE(is_c3(nvm),stat=ier)  
+   l_error = l_error .OR. (ier .NE. 0)
+   ALLOCATE(leaflife_tab(nvm),stat=ier)   
+   l_error = l_error .OR. (ier .NE. 0)
+   ! >> END
+
    ALLOCATE(veget_ori_fixed_test_1(nvm),stat=ier)
    l_error = l_error .OR. (ier .NE. 0)
@@ -1066,13 +1083,200 @@
 
  END SUBROUTINE pft_parameters_alloc
+!
+!=
+!
+ SUBROUTINE getin_sechiba_pft_parameters
+
+   IMPLICIT NONE
+  
+   LOGICAL, SAVE ::  first_call = .TRUE.
+
+  IF(first_call) THEN
+
+     ! No calling to getin for veget_ori_fixed_test_1, llaimax and height_presc
+     ! use of setvar in slowproc.f90
+
+     !-
+     ! Vegetation structure
+     !-
+     CALL getin_p('LLAIMIN',llaimin)
+     CALL getin('TYPE_OF_LAI',type_of_lai)
+     CALL getin_p('IS_TREE',is_tree)
+     CALL getin_p('NATURAL',natural)
+
+     !>> DS new for merge in the trunk   ! 15/06/2011 
+     ! Add for writing history files in stomate_lpj.f90 'treeFracPrimDec' and 'treeFracPrimEver'
+     CALL getin('IS_DECIDUOUS',is_deciduous)
+     CALL getin('IS_EVERGREEN',is_evergreen)  
+     CALL getin_p('IS_C3',is_c3)   
+
+     !-
+     ! Photosynthesis
+     !-
+     CALL getin_p('IS_C4',is_c4)
+     CALL getin_p('GSSLOPE',gsslope)
+     CALL getin_p('GSOFFSET',gsoffset)
+     CALL getin_p('VCMAX_FIX',vcmax_fix)
+     CALL getin_p('VJMAX_FIX',vjmax_fix)
+     CALL getin_p('CO2_TMIN_FIX',co2_tmin_fix)
+     CALL getin_p('CO2_TOPT_FIX',co2_topt_fix)
+     CALL getin_p('CO2_TMAX_FIX',co2_tmax_fix)
+     CALL getin_p('EXT_COEFF',ext_coeff)
+     !-
+     ! Evapotranspiration -  sechiba
+     !-
+     CALL getin_p('RSTRUCT_CONST',rstruct_const)
+     CALL getin_p('KZERO',kzero)
+     CALL getin_p('RVEG_PFT', rveg_pft)    
+     !-
+     ! Water-hydrology - sechiba
+     !-
+     CALL getin_p('WMAX_VEG',wmax_veg)
+     CALL getin_p('HYDROL_HUMCSTE', humcste)
+     CALL getin_p('PERCENT_TROUGHFALL_PFT',throughfall_by_pft)
+     !-
+     ! Albedo - sechiba
+     !-
+     CALL getin_p('SNOWA_INI',snowa_ini)
+     CALL getin_p('SNOWA_DEC',snowa_dec)
+     CALL getin_p('ALB_LEAF_VIS',alb_leaf_vis)
+     CALL getin_p('ALB_LEAF_NIR',alb_leaf_nir)
+     !-
+     ! Soil - vegetation
+     !-
+     CALL getin_p('PREF_SOIL_VEG_SAND',pref_soil_veg_sand)
+     CALL getin_p('PREF_SOIL_VEG_LOAN',pref_soil_veg_loan)         
+     CALL getin_p('PREF_SOIL_VEG_CLAY',pref_soil_veg_clay)
+
+     first_call = .FALSE.
+
+  ENDIF
+
+END SUBROUTINE getin_sechiba_pft_parameters
+!
+!=
+!
+SUBROUTINE getin_stomate_pft_parameters
+
+  IMPLICIT NONE
+
+  LOGICAL, SAVE ::  first_call = .TRUE.
+
+  IF(first_call) THEN
+
+      !-
+      ! Vegetation structure
+      !-
+      CALL getin_p('LEAF_TAB',leaf_tab)
+      CALL getin_p('SLA',sla)
+      !-
+      ! Photosynthesis
+      !-
+      CALL getin_p('VCMAX_OPT',vcmax_opt)
+      CALL getin_p('VJMAX_OPT',vjmax_opt)
+      CALL getin_p('TPHOTO_MIN_A',tphoto_min_a)
+      CALL getin_p('TPHOTO_MIN_B',tphoto_min_b)
+      CALL getin_p('TPHOTO_MIN_C',tphoto_min_c)
+      CALL getin_p('TPHOTO_OPT_A',tphoto_opt_a)
+      CALL getin_p('TPHOTO_OPT_B',tphoto_opt_b)
+      CALL getin_p('TPHOTO_OPT_C',tphoto_opt_c)
+      CALL getin_p('TPHOTO_MAX_A',tphoto_max_a)
+      CALL getin_p('TPHOTO_MAX_B',tphoto_max_b)
+      CALL getin_p('TPHOTO_MAX_C',tphoto_max_c)
+      !-
+      ! Respiration - stomate
+      !-
+      CALL getin_p('MAINT_RESP_SLOPE_C',maint_resp_slope_c) 
+      CALL getin_p('MAINT_RESP_SLOPE_B',maint_resp_slope_b)
+      CALL getin_p('MAINT_RESP_SLOPE_A',maint_resp_slope_a)
+      CALL getin_p('CM_ZERO_LEAF',cm_zero_leaf)
+      CALL getin_p('CM_ZERO_SAPABOVE',cm_zero_sapabove)
+      CALL getin_p('CM_ZERO_SAPBELOW',cm_zero_sapbelow)
+      CALL getin_p('CM_ZERO_HEARTABOVE',cm_zero_heartabove)
+      CALL getin_p('CM_ZERO_HEARTBELOW',cm_zero_heartbelow)
+      CALL getin_p('CM_ZERO_ROOT',cm_zero_root)
+      CALL getin_p('CM_ZERO_FRUIT',cm_zero_fruit)
+      CALL getin_p('CM_ZERO_CARBRES',cm_zero_carbres)
+      !-
+      ! Fire - stomate
+      !-
+      CALL getin_p('FLAM',flam)
+      CALL getin_p('RESIST',resist)
+      !-
+      ! Flux - LUC
+      !-
+      CALL getin_p('COEFF_LCCHANGE_1',coeff_lcchange_1)
+      CALL getin_p('COEFF_LCCHANGE_10',coeff_lcchange_10)
+      CALL getin_p('COEFF_LCCHANGE_100',coeff_lcchange_100)
+      !-
+      ! Phenology
+      !-
+      CALL getin_p('LAI_MAX',lai_max)
+      CALL getin('PHENO_MODEL',pheno_model)
+      CALL getin_p('PHENO_TYPE',pheno_type)
+      !-
+      ! Phenology : Leaf Onset
+      !-
+      CALL getin_p('PHENO_GDD_CRIT_C',pheno_gdd_crit_c)
+      CALL getin_p('PHENO_GDD_CRIT_B',pheno_gdd_crit_b)
+      CALL getin_p('PHENO_GDD_CRIT_A',pheno_gdd_crit_a)
+      CALL getin_p('NGD_CRIT',ngd_crit)
+      CALL getin_p('NCDGDD_TEMP', ncdgdd_temp)
+      CALL getin_p('HUM_FRAC', hum_frac)
+      CALL getin_p('LOWGPP_TIME', lowgpp_time)
+      CALL getin_p('HUM_MIN_TIME', hum_min_time)
+      CALL getin_p('TAU_SAP',tau_sap)
+      CALL getin_p('TAU_FRUIT',tau_fruit)
+      CALL getin_p('ECUREUIL',ecureuil)
+      CALL getin_p('ALLOC_MIN',alloc_min)
+      CALL getin_p('ALLOC_MAX',alloc_max)
+      CALL getin_p('DEMI_ALLOC',demi_alloc)
+
+      !>> DS new for merge in the trunk
+      ! 15/06/2011 : add leaflife_mtc for the new formalism used for calculate sla
+      CALL getin_p('LEAFLIFE_TAB',leaflife_tab)
+
+      !-
+      ! Phenology : Senescence
+      !-
+      CALL getin_p('LEAFFALL',leaffall)
+      CALL getin_p('LEAFAGECRIT',leafagecrit)  
+      CALL getin('SENESCENCE_TYPE', senescence_type) 
+      CALL getin_p('SENESCENCE_HUM', senescence_hum)
+      CALL getin_p('NOSENESCENCE_HUM', nosenescence_hum) 
+      CALL getin_p('MAX_TURNOVER_TIME',max_turnover_time)
+      CALL getin_p('MIN_TURNOVER_TIME',min_turnover_time)
+      CALL getin_p('MIN_LEAF_AGE_FOR_SENESCENCE', min_leaf_age_for_senescence)
+      CALL getin_p('SENESCENCE_TEMP_C',senescence_temp_c)
+      CALL getin_p('SENESCENCE_TEMP_B',senescence_temp_b)
+      CALL getin_p('SENESCENCE_TEMP_A',senescence_temp_a)
+      !-
+      ! DGVM
+      !-
+      CALL getin_p('RESIDENCE_TIME',residence_time)
+      CALL getin_p('TMIN_CRIT',tmin_crit)
+      CALL getin_p('TCM_CRIT',tcm_crit)
+      
+     first_call = .FALSE.
+       
+  ENDIF
+  
+END SUBROUTINE getin_stomate_pft_parameters
  !
  !=
  !
  SUBROUTINE pft_parameters_clear
-
+   
    l_first_define_pft = .TRUE.
-
+   
    IF(ALLOCATED(pft_to_mtc))DEALLOCATE(pft_to_mtc)
    IF(ALLOCATED(PFT_name))DEALLOCATE(PFT_name)
+   !-
+   !>> DS new for merge in the trunk   ! 15/06/2011 
+   ! Add for writing history files in stomate_lpj.f90 'treeFracPrimDec' and 'treeFracPrimEver'
+   IF(ALLOCATED(is_deciduous))DEALLOCATE(is_deciduous)
+   IF(ALLOCATED(is_evergreen))DEALLOCATE(is_evergreen)
+   IF(ALLOCATED(leaflife_tab))DEALLOCATE(leaflife_tab)
+   IF(ALLOCATED(is_c3))DEALLOCATE(is_c3)  
    !-
    IF(ALLOCATED(veget_ori_fixed_test_1))DEALLOCATE(veget_ori_fixed_test_1)   
@@ -1194,193 +1398,7 @@
    !-
    IF(ALLOCATED(throughfall_by_pft))DEALLOCATE(throughfall_by_pft)
-   IF (ALLOCATED(rveg_pft))DEALLOCATE(rveg_pft)
-
+   IF(ALLOCATED(rveg_pft))DEALLOCATE(rveg_pft)
+   
  END SUBROUTINE pft_parameters_clear
-!
-!=
-!
- SUBROUTINE getin_sechiba_pft_parameters
-
-   IMPLICIT NONE
-  
-   LOGICAL, SAVE ::  first_call = .TRUE.
-
-  IF(first_call) THEN
-
-     !----------------------
-     ! Vegetation structure
-     !---------------------
-     !      
-     CALL getin('LLAIMIN',llaimin)
-     CALL getin('TYPE_OF_LAI',type_of_lai)
-     CALL getin('IS_TREE',is_tree)
-     ! No calling to getin for
-     ! veget_ori_fixed_test_1, llaimax and height_presc
-     ! use of setvar in slowproc.f90
-     
-     !-----------------
-     ! Photosynthesis
-     !-----------------
-     !-
-     CALL getin('IS_C4',is_c4)
-     CALL getin('GSSLOPE',gsslope)
-     CALL getin('GSOFFSET',gsoffset)
-     CALL getin('VCMAX_FIX',vcmax_fix)
-     CALL getin('VJMAX_FIX',vjmax_fix)
-     CALL getin('CO2_TMIN_FIX',co2_tmin_fix)
-     CALL getin('CO2_TOPT_FIX',co2_topt_fix)
-     CALL getin('CO2_TMAX_FIX',co2_tmax_fix)
-     CALL getin('EXT_COEFF',ext_coeff)
-     !-------------------------------
-     ! Evapotranspiration -  sechiba
-     !-------------------------------
-     !
-     CALL getin('RSTRUCT_CONST',rstruct_const)
-     CALL getin('KZERO',kzero)
-     CALL getin('RVEG_PFT', rveg_pft)    
-     !---------------------------
-     ! Water-hydrology - sechiba
-     !---------------------------
-     !
-     CALL getin('WMAX_VEG',wmax_veg)
-     CALL getin('HYDROL_HUMCSTE', humcste)
-     CALL getin('PERCENT_TROUGHFALL_PFT',throughfall_by_pft)
-     !------------------
-     ! Albedo - sechiba
-     !------------------
-     !
-     CALL getin('SNOWA_INI',snowa_ini)
-     CALL getin('SNOWA_DEC',snowa_dec)
-     CALL getin('ALB_LEAF_VIS',alb_leaf_vis)
-     CALL getin('ALB_LEAF_NIR',alb_leaf_nir)
-
-     !------------------------
-     !   Soil - vegetation
-     !------------------------ 
-     !
-     CALL getin('PREF_SOIL_VEG_SAND',pref_soil_veg_sand)
-     CALL getin('PREF_SOIL_VEG_LOAN',pref_soil_veg_loan)         
-     CALL getin('PREF_SOIL_VEG_CLAY',pref_soil_veg_clay)
-
-     first_call = .FALSE.
-
-  ENDIF
-
-END SUBROUTINE getin_sechiba_pft_parameters
-!
-!=
-!
-SUBROUTINE getin_stomate_pft_parameters
-
-  IMPLICIT NONE
-
-  LOGICAL, SAVE ::  first_call = .TRUE.
-
-  IF(first_call) THEN
-
-     !----------------------
-     ! Vegetation structure
-     !---------------------
-     !
-     CALL getin('LEAF_TAB',leaf_tab)
-     CALL getin('SLA',sla)
-     CALL getin('NATURAL',natural)
-     !-----------------
-     ! Photosynthesis
-     !-----------------
-     !
-     CALL getin('VCMAX_OPT',vcmax_opt)
-     CALL getin('VJMAX_OPT',vjmax_opt)
-     CALL getin('TPHOTO_MIN_A',tphoto_min_a)
-     CALL getin('TPHOTO_MIN_B',tphoto_min_b)
-     CALL getin('TPHOTO_MIN_C',tphoto_min_c)
-     CALL getin('TPHOTO_OPT_A',tphoto_opt_a)
-     CALL getin('TPHOTO_OPT_B',tphoto_opt_b)
-     CALL getin('TPHOTO_OPT_C',tphoto_opt_c)
-     CALL getin('TPHOTO_MAX_A',tphoto_max_a)
-     CALL getin('TPHOTO_MAX_B',tphoto_max_b)
-     CALL getin('TPHOTO_MAX_C',tphoto_max_c)
-     !----------------------
-     ! Respiration - stomate
-     !----------------------
-     !
-     CALL getin('MAINT_RESP_SLOPE_C',maint_resp_slope_c) 
-     CALL getin('MAINT_RESP_SLOPE_B',maint_resp_slope_b)
-     CALL getin('MAINT_RESP_SLOPE_A',maint_resp_slope_a)
-     CALL getin('CM_ZERO_LEAF',cm_zero_leaf)
-     CALL getin('CM_ZERO_SAPABOVE',cm_zero_sapabove)
-     CALL getin('CM_ZERO_SAPBELOW',cm_zero_sapbelow)
-     CALL getin('CM_ZERO_HEARTABOVE',cm_zero_heartabove)
-     CALL getin('CM_ZERO_HEARTBELOW',cm_zero_heartbelow)
-     CALL getin('CM_ZERO_ROOT',cm_zero_root)
-     CALL getin('CM_ZERO_FRUIT',cm_zero_fruit)
-     CALL getin('CM_ZERO_CARBRES',cm_zero_carbres)
-     
-     !----------------
-     ! Fire - stomate
-     !---------------
-     !
-     CALL getin('FLAM',flam)
-     CALL getin('RESIST',resist)
-     !----------------
-     ! Flux - LUC
-     !---------------
-     !
-     CALL getin('COEFF_LCCHANGE_1',coeff_lcchange_1)
-     CALL getin('COEFF_LCCHANGE_10',coeff_lcchange_10)
-     CALL getin('COEFF_LCCHANGE_100',coeff_lcchange_100)
-
-     !-----------
-     ! Phenology
-     !-----------
-     !-
-     ! 1 .Stomate
-     !-
-     CALL getin('LAI_MAX',lai_max)
-     CALL getin('PHENO_MODEL',pheno_model)
-     CALL getin('PHENO_TYPE',pheno_type)
-     !-
-     ! 2. Leaf Onset
-     !-
-     CALL getin('PHENO_GDD_CRIT_C',pheno_gdd_crit_c)
-     CALL getin('PHENO_GDD_CRIT_B',pheno_gdd_crit_b)
-     CALL getin('PHENO_GDD_CRIT_A',pheno_gdd_crit_a)
-     CALL getin('NGD_CRIT',ngd_crit)
-     CALL getin('NCDGDD_TEMP', ncdgdd_temp)
-     CALL getin('HUM_FRAC', hum_frac)
-     CALL getin('LOWGPP_TIME', lowgpp_time)
-     CALL getin('HUM_MIN_TIME', hum_min_time)
-     CALL getin('TAU_SAP',tau_sap)
-     CALL getin('TAU_FRUIT',tau_fruit)
-     CALL getin('ECUREUIL',ecureuil)
-     CALL getin('ALLOC_MIN',alloc_min)
-     CALL getin('ALLOC_MAX',alloc_max)
-     CALL getin('DEMI_ALLOC',demi_alloc)
-     !-
-     ! 3. Senescence
-     !-
-     CALL getin('LEAFFALL',leaffall)
-     CALL getin('LEAFAGECRIT',leafagecrit)  
-     CALL getin('SENESCENCE_TYPE', senescence_type) 
-     CALL getin('SENESCENCE_HUM', senescence_hum)
-     CALL getin('NOSENESCENCE_HUM', nosenescence_hum) 
-     CALL getin('MAX_TURNOVER_TIME',max_turnover_time)
-     CALL getin('MIN_TURNOVER_TIME',min_turnover_time)
-     CALL getin('MIN_LEAF_AGE_FOR_SENESCENCE', min_leaf_age_for_senescence)
-     CALL getin('SENESCENCE_TEMP_C',senescence_temp_c)
-     CALL getin('SENESCENCE_TEMP_B',senescence_temp_b)
-     CALL getin('SENESCENCE_TEMP_A',senescence_temp_a)
-     !-----------
-     ! DGVM
-     !-----------
-     CALL getin('RESIDENCE_TIME',residence_time)
-     CALL getin('TMIN_CRIT',tmin_crit)
-     CALL getin('TCM_CRIT',tcm_crit)
-
-     first_call = .FALSE.
-       
-  ENDIF
-  
-END SUBROUTINE getin_stomate_pft_parameters
 
 END MODULE pft_parameters
Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_sechiba/AA_make
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_sechiba/AA_make	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_sechiba/AA_make	(revision 257)
@@ -1,4 +1,11 @@
 #-
-#- $Id: AA_make,v 1.22 2010/04/20 13:59:56 ssipsl Exp $
+#- $Id: AA_make 41 2011-01-01 19:56:53Z mmaipsl $
+#-
+PARALLEL_LIB = $(LIBDIR)/libparallel.a
+SXPARALLEL_LIB = $(PARALLEL_LIB)
+#-Q- sxnec  SXPARALLEL_LIB = $(LIBDIR)/libsxparallel.a
+#-Q- sx6nec SXPARALLEL_LIB = $(LIBDIR)/libsxparallel.a
+#-Q- eshpux SXPARALLEL_LIB = $(LIBDIR)/libsxparallel.a
+#-Q- sx8brodie SXPARALLEL_LIB = $(LIBDIR)/libsxparallel.a
 #-
 PARAM_LIB = $(LIBDIR)/libparameters.a
@@ -8,11 +15,4 @@
 #-Q- eshpux SXPARAM_LIB = $(LIBDIR)/libsxparameters.a
 #-Q- sx8brodie SXPARAM_LIB = $(LIBDIR)/libsxparameters.a
-#-
-PARALLEL_LIB = $(LIBDIR)/libparallel.a
-SXPARALLEL_LIB = $(PARALLEL_LIB)
-#-Q- sxnec  SXPARALLEL_LIB = $(LIBDIR)/libsxparallel.a
-#-Q- sx6nec SXPARALLEL_LIB = $(LIBDIR)/libsxparallel.a
-#-Q- eshpux SXPARALLEL_LIB = $(LIBDIR)/libsxparallel.a
-#-Q- sx8brodie SXPARALLEL_LIB = $(LIBDIR)/libsxparallel.a
 #-
 ORGLOB_LIB = $(LIBDIR)/liborglob.a
@@ -54,6 +54,7 @@
 #-
 all:
+	$(M_K) libparallel
 	$(M_K) libparameters
-	$(M_K) libparallel
+	$(M_K) liborglob
 	$(M_K) libstomate
 	$(M_K) m_all
@@ -63,9 +64,9 @@
 #-Q- intel m_all: WORK_MOD $(MODEL_LIB)($(OBJSMODS1))
 
+libparallel:
+	(cd ../src_parallel; $(M_K) -f Makefile)
+
 libparameters:
 	(cd ../src_parameters; $(M_K) -f Makefile)
-
-libparallel:
-	(cd ../src_parallel; $(M_K) -f Makefile)
 
 liborglob:
Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_sechiba/AA_make.ldef
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_sechiba/AA_make.ldef	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_sechiba/AA_make.ldef	(revision 257)
@@ -1,4 +1,4 @@
 #-
-#- $Id: AA_make.ldef,v 1.7 2008/01/08 11:49:07 ssipsl Exp $
+#- $Id: AA_make.ldef 12 2010-11-05 15:42:13Z mmaipsl $
 #-
 #---------------------------------------------------------------------
Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_sechiba/condveg.f90
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_sechiba/condveg.f90	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_sechiba/condveg.f90	(revision 257)
@@ -6,7 +6,10 @@
 !!
 !! @author Marie-Alice Foujols and Jan Polcher
-!! @Version : $Revision: 1.30 $, $Date: 2009/01/07 13:39:45 $
+!! @Version : $Revision: 45 $, $Date: 2011-01-01 21:30:44 +0100 (Sat, 01 Jan 2011) $
 !! 
-!! $Header: /home/ssipsl/CVSREP/ORCHIDEE/src_sechiba/condveg.f90,v 1.30 2009/01/07 13:39:45 ssipsl Exp $
+!< $HeadURL: http://forge.ipsl.jussieu.fr/orchidee/svn/trunk/ORCHIDEE/src_sechiba/condveg.f90 $
+!< $Date: 2011-01-01 21:30:44 +0100 (Sat, 01 Jan 2011) $
+!< $Author: mmaipsl $
+!< $Revision: 45 $
 !! IPSL (2006)
 !!  This software is governed by the CeCILL licence see ORCHIDEE/ORCHIDEE_CeCILL.LIC
@@ -210,5 +213,5 @@
     REAL(r_std),DIMENSION (kjpindex,nvm), INTENT (in):: veget            !! Vegetation distribution
     REAL(r_std),DIMENSION (kjpindex,2), INTENT (in)  :: lalo             !! Geographical coordinates
-    INTEGER(i_std),DIMENSION (kjpindex,4), INTENT(in):: neighbours       !! neighoring grid points if land
+    INTEGER(i_std),DIMENSION (kjpindex,8), INTENT(in):: neighbours       !! neighoring grid points if land
     REAL(r_std), DIMENSION (kjpindex,2), INTENT(in)  :: resolution       !! size in x an y of the grid (m)
     REAL(r_std),DIMENSION (kjpindex), INTENT(in)     :: contfrac         ! Fraction of land in each grid box.
@@ -663,6 +666,6 @@
       ! snow albedo on vegetated surfaces
       !
-      fraction_veg(:) = 1. - totfrac_nobio(:)
-      snowa_veg(:) = 0.
+      fraction_veg(:) = un - totfrac_nobio(:)
+      snowa_veg(:) = zero
       DO jv = 1, nvm
         DO ji = 1, kjpindex
@@ -1112,5 +1115,5 @@
     ENDDO
     !
-    WHERE ( sumveg(:) .GT. 0.0 ) z0(:) = z0(:) / sumveg(:)
+    WHERE ( sumveg(:) .GT. zero ) z0(:) = z0(:) / sumveg(:)
     !
     z0(:) = (un - totfrac_nobio(:)) * z0(:)
@@ -1166,11 +1169,6 @@
     !
 !!$    DS :Correction 11/02/2011 : update 2D parameters 
-!!$      before the components were updated but not the  parameter itself!
     alb_leaf(1:nvm) = alb_leaf_vis(:)
     alb_leaf(nvm+1:2*nvm) = alb_leaf_nir(:)
-!!$ maybe we could use directly alb_leaf_vis and alb_leaf_nir in alb_leaf_temp
-    !
-!!$    alb_leaf_tmp(:,1) = alb_leaf_vis(:)
-!!$    alb_leaf_tmp(:,2) = alb_leaf_nir(:)
     !
     alb_leaf_tmp(:,1) = alb_leaf(1:nvm)
@@ -1188,5 +1186,5 @@
        !
        ! Correction Nathalie le 12 Avril 2006 - suppression de la dependance en deadleaf_cover
-       !albedo(:,ks) = veget(:,1) * ( (1.-deadleaf_cover(:))*alb_bare(:) + &
+       !albedo(:,ks) = veget(:,1) * ( (un-deadleaf_cover(:))*alb_bare(:) + &
        !                              deadleaf_cover(:)*alb_deadleaf(ks)    )
        albedo(:,ks) = veget(:,1) * alb_bare(:,ks)
Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_sechiba/diffuco.f90
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_sechiba/diffuco.f90	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_sechiba/diffuco.f90	(revision 257)
@@ -3,7 +3,10 @@
 !!
 !! @author Marie-Alice Foujols and Jan Polcher
-!! @Version : $Revision: 1.35 $, $Date: 2010/04/07 09:16:40 $
+!! @Version : $Revision: 42 $, $Date: 2011-01-01 21:15:03 +0100 (Sat, 01 Jan 2011) $
 !! 
-!! $Header: /home/ssipsl/CVSREP/ORCHIDEE/src_sechiba/diffuco.f90,v 1.35 2010/04/07 09:16:40 ssipsl Exp $
+!< $HeadURL: http://forge.ipsl.jussieu.fr/orchidee/svn/trunk/ORCHIDEE/src_sechiba/diffuco.f90 $
+!< $Date: 2011-01-01 21:15:03 +0100 (Sat, 01 Jan 2011) $
+!< $Author: mmaipsl $
+!< $Revision: 42 $
 !! IPSL (2006)
 !!  This software is governed by the CeCILL licence see ORCHIDEE/ORCHIDEE_CeCILL.LIC
@@ -38,5 +41,4 @@
   !! Nathalie le 28 mars 2006 - sur proposition de Fred Hourdin, ajout
   !! d'un potentiometre pour regler la resistance de la vegetation ( rveg is now in pft_parameters)
-
   ! MM
   REAL(r_std), ALLOCATABLE, SAVE, DIMENSION (:)      :: wind                     !! Wind norm
@@ -242,5 +244,4 @@
     ! beta coefficient for bare soil
     !
-
     CALL diffuco_bare (kjpindex, dtradia, u, v, q_cdrag, rsol, evap_bare_lim, evapot, humrel, veget, vbeta4) 
 
@@ -744,5 +745,5 @@
                 IF ( zrapp .LT. un ) THEN
                    ! Ajout Nathalie - Juin 2006
-                    vbeta23(ji,jv) = MAX(vbeta2(ji,jv) - vbeta2(ji,jv) * zrapp, 0.)
+                    vbeta23(ji,jv) = MAX(vbeta2(ji,jv) - vbeta2(ji,jv) * zrapp, zero)
                     ! Fin ajout Nathalie
                     vbeta2(ji,jv) = vbeta2(ji,jv) * zrapp
@@ -1004,5 +1005,5 @@
     !
     DO jl = 1, nlai+1
-      laitab(jl) = laimax*(EXP(lai_level_depth*REAL(jl-1,r_std))-1.)/(EXP(lai_level_depth*REAL(nlai,r_std))-1.)
+      laitab(jl) = laimax*(EXP(lai_level_depth*REAL(jl-1,r_std))-1.)/(EXP(lai_level_depth*REAL(nlai,r_std))-un)
     ENDDO
     !
@@ -1100,5 +1101,5 @@
       !
       WHERE ( assimilate(:) )
-        water_lim(:) = MIN( 2.*humrel(:,jv), 1. )
+        water_lim(:) = MIN( 2.*humrel(:,jv), un )
       ENDWHERE
       ! give a default value of ci for all pixel that do not assimilate
@@ -1255,5 +1256,5 @@
           DO ji = 1, kjpindex
             !
-            assimi(ji) = 0.
+            assimi(ji) = zero
             !
           ENDDO
@@ -1288,5 +1289,5 @@
           DO ji = 1, kjpindex
             !
-            assimi(ji) = 0.
+            assimi(ji) = zero
             !
           ENDDO
@@ -1383,5 +1384,5 @@
         IF ( jl .EQ. 1 ) THEN
           !
-          leaf_gs_top(:) = 0.
+          leaf_gs_top(:) = zero
           !
           IF ( nic .GT. 0 ) then
@@ -1437,5 +1438,5 @@
               laitab(ilai(iainia)+1)
           !
-          rveget(iainia,jv) = 1./gstop(iainia)
+          rveget(iainia,jv) = un/gstop(iainia)
           !
         ENDDO
@@ -1448,7 +1449,7 @@
           !
           ! Correction Nathalie - le 27 Mars 2006 - Interdire a rstruct d'etre negatif
-          !rstruct(iainia,jv) = 1./gstot(iainia) - &
+          !rstruct(iainia,jv) = un/gstot(iainia) - &
           !     rveget(iainia,jv)
-          rstruct(iainia,jv) = MAX( 1./gstot(iainia) - &
+          rstruct(iainia,jv) = MAX( un/gstot(iainia) - &
                rveget(iainia,jv), min_sechiba)
           !
@@ -1556,6 +1557,6 @@
     REAL(r_std)                                    :: coeff_dew_veg
 
-    vbeta2sum(:) = 0.
-    vbeta3sum(:) = 0.
+    vbeta2sum(:) = zero
+    vbeta3sum(:) = zero
     DO jv = 1, nvm
       vbeta2sum(:) = vbeta2sum(:) + vbeta2(:,jv)
@@ -1593,9 +1594,9 @@
 
     ! for vectorization: some arrays
-    vegetsum(:) = 0.
+    vegetsum(:) = zero
     DO jv = 1, nvm
       vegetsum(:) = vegetsum(:) + veget(:,jv)
     ENDDO
-    vegetsum2(:) = 0.
+    vegetsum2(:) = zero
     DO jv = 2, nvm
       vegetsum2(:) = vegetsum2(:) + veget(:,jv)
@@ -1667,8 +1668,6 @@
                          & + dew_veg_poly_coeff(2)*lai(ji,jv) &
                          & + dew_veg_poly_coeff(1)
-
-
                  ELSE
-                    coeff_dew_veg=1.
+                    coeff_dew_veg=un
                  ENDIF
               ELSE
Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_sechiba/enerbil.f90
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_sechiba/enerbil.f90	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_sechiba/enerbil.f90	(revision 257)
@@ -3,7 +3,10 @@
 !!
 !! @author Marie-Alice Foujols and Jan Polcher
-!! @Version : $Revision: 1.24 $, $Date: 2009/01/07 13:39:45 $
+!! @Version : $Revision: 47 $, $Date: 2011-01-01 21:34:45 +0100 (Sat, 01 Jan 2011) $
 !! 
-!! $Header: /home/ssipsl/CVSREP/ORCHIDEE/src_sechiba/enerbil.f90,v 1.24 2009/01/07 13:39:45 ssipsl Exp $
+!< $HeadURL: http://forge.ipsl.jussieu.fr/orchidee/svn/trunk/ORCHIDEE/src_sechiba/enerbil.f90 $
+!< $Date: 2011-01-01 21:34:45 +0100 (Sat, 01 Jan 2011) $
+!< $Author: mmaipsl $
+!< $Revision: 47 $
 !! IPSL (2006)
 !!  This software is governed by the CeCILL licence see ORCHIDEE/ORCHIDEE_CeCILL.LIC
@@ -121,16 +124,16 @@
     REAL(r_std),DIMENSION (kjpindex), INTENT (inout)   :: evapot           !! Soil Potential Evaporation
     REAL(r_std),DIMENSION (kjpindex), INTENT (inout)   :: evapot_corr !! Soil Potential Evaporation Correction
+    REAL(r_std),DIMENSION (kjpindex), INTENT (inout)   :: temp_sol         !! Soil temperature
+    REAL(r_std),DIMENSION (kjpindex), INTENT (inout)   :: qsurf            !! Surface specific humidity
+    REAL(r_std),DIMENSION (kjpindex), INTENT (inout)   :: fluxsens         !! Sensible chaleur flux
+    REAL(r_std),DIMENSION (kjpindex), INTENT (inout)   :: fluxlat          !! Latent chaleur flux
+    REAL(r_std),DIMENSION (kjpindex), INTENT (inout)   :: tsol_rad         !! Tsol_rad
+    REAL(r_std),DIMENSION (kjpindex), INTENT (inout)   :: vevapp           !! Total of evaporation
+    REAL(r_std),DIMENSION (kjpindex,nvm), INTENT (inout) :: gpp              !! Assimilation, gC/m**2 total area.
+    REAL(r_std),DIMENSION (kjpindex), INTENT (inout)   :: temp_sol_new     !! New soil temperature
     ! output fields
-    REAL(r_std),DIMENSION (kjpindex), INTENT (out)     :: fluxsens         !! Sensible chaleur flux
-    REAL(r_std),DIMENSION (kjpindex), INTENT (out)     :: fluxlat          !! Latent chaleur flux
-    REAL(r_std),DIMENSION (kjpindex), INTENT (out)     :: vevapp           !! Total of evaporation
     REAL(r_std),DIMENSION (kjpindex), INTENT (out)     :: vevapnu          !! Bare soil evaporation
     REAL(r_std),DIMENSION (kjpindex), INTENT (out)     :: vevapsno         !! Snow evaporation
-    REAL(r_std),DIMENSION (kjpindex), INTENT (out)     :: tsol_rad         !! Tsol_rad
-    REAL(r_std),DIMENSION (kjpindex), INTENT (out)     :: temp_sol_new     !! New soil temperature
-    REAL(r_std),DIMENSION (kjpindex), INTENT (out)     :: temp_sol         !! Soil temperature
-    REAL(r_std),DIMENSION (kjpindex), INTENT (out)     :: qsurf            !! Surface specific humidity
     REAL(r_std),DIMENSION (kjpindex,nvm), INTENT (out) :: transpir         !! Transpiration
-    REAL(r_std),DIMENSION (kjpindex,nvm), INTENT (out) :: gpp              !! Assimilation, gC/m**2 total area.
     REAL(r_std),DIMENSION (kjpindex,nvm), INTENT (out) :: vevapwet         !! Interception 
     REAL(r_std),DIMENSION (kjpindex), INTENT (out)     :: t2mdiag          !! 2-meter temperature
@@ -281,5 +284,5 @@
     ! output fields, they need to initialized somehow for the model forcing ORCHIDEE.
     !
-    REAL(r_std),DIMENSION (kjpindex), INTENT (out)           :: temp_sol           !! Soil temperature
+    REAL(r_std),DIMENSION (kjpindex), INTENT (inout)         :: temp_sol           !! Soil temperature
     REAL(r_std),DIMENSION (kjpindex), INTENT (out)           :: temp_sol_new       !! New soil temperature
     REAL(r_std),DIMENSION (kjpindex), INTENT (out)           :: qsurf              !! near surface specific humidity
@@ -423,7 +426,7 @@
         !Config        the model is started without a restart file. 
         !
-        CALL setvar_p (evapot, val_exp, 'ENERBIL_EVAPOT', 0.0_r_std)
+        CALL setvar_p (evapot, val_exp, 'ENERBIL_EVAPOT', zero)
         IF ( ok_var("evapot_corr") ) THEN
-           CALL setvar_p (evapot_corr, val_exp, 'ENERBIL_EVAPOT', 0.0_r_std)
+           CALL setvar_p (evapot_corr, val_exp, 'ENERBIL_EVAPOT', zero)
         ENDIF
         !
@@ -778,4 +781,5 @@
     REAL(r_std)                                     :: correction
     REAL(r_std)                                     :: speed, qc
+    LOGICAL,DIMENSION (kjpindex)                   :: warning_correction
     ! initialisation
 
@@ -840,4 +844,5 @@
 !    grad_qsat(:)= (qsol_sat_new(:)- qsat_air(:)) / ((psnew(:) - epot_air(:)) / cp_air) ! * dtradia
     !- Penser a sortir evapot en meme temps qu'evapot_corr tdo.
+    warning_correction(:)=.FALSE.
     DO ji=1,kjpindex
 
@@ -852,5 +857,5 @@
              correction = chalev0 * rau(ji) * qc * grad_qsat(ji) * (un - vevapp(ji)/evapot(ji)) / correction
           ELSE
-             WRITE(numout,*) "Denominateur de la correction de milly nul! Aucune correction appliquee"
+             warning_correction(ji)=.TRUE.
           ENDIF
        ELSE
@@ -862,5 +867,11 @@
        
     ENDDO
-
+    IF ( ANY(warning_correction) ) THEN
+       DO ji=1,kjpindex
+          IF ( warning_correction(ji) ) THEN
+             WRITE(numout,*) ji,"Denominateur de la correction de milly nul! Aucune correction appliquee"
+          ENDIF
+       ENDDO
+    ENDIF
     IF (long_print) WRITE (numout,*) ' enerbil_flux done '
 
@@ -886,5 +897,5 @@
     REAL(r_std),DIMENSION (kjpindex), INTENT (in)            :: evapot           !! Soil Potential Evaporation
     REAL(r_std),DIMENSION (kjpindex, nvm), INTENT (in)       :: humrel           !! Relative humidity
-!!$ DS 15022011 humrel was used in a previuos version of Orchidee, developped by Nathalie. Need to be discussed if it should be introduces again
+!!$ DS 15022011 humrel was used in a previous version of Orchidee, developped by Nathalie. Need to be discussed if it should be introduces again
     REAL(r_std),DIMENSION (kjpindex,nvm), INTENT (in)        :: vbeta2           !! Interception resistance
     REAL(r_std),DIMENSION (kjpindex,nvm), INTENT (in)        :: vbeta3           !! Vegetation resistance
@@ -969,5 +980,5 @@
     ELSEIF ( control%stomate_watchout ) THEN
 
-      gpp(:,:) = 0.0
+      gpp(:,:) = zero
 
     ENDIF
@@ -1001,5 +1012,5 @@
 
     ! initialisation
-   IF (long_print) WRITE (numout,*) ' enerbil_fusion start ', MINVAL(soilcap), MINLOC(soilcap),&
+    IF (long_print) WRITE (numout,*) ' enerbil_fusion start ', MINVAL(soilcap), MINLOC(soilcap),&
          & MAXVAL(soilcap), MAXLOC(soilcap)
     !
Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_sechiba/hydrol.f90
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_sechiba/hydrol.f90	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_sechiba/hydrol.f90	(revision 257)
@@ -3,7 +3,10 @@
 !!
 !! @author Marie-Alice Foujols and Jan Polcher
-!! @Version : $Revision: 1.36 $, $Date: 2009/01/07 13:39:45 $
+!! @Version : $Revision: 45 $, $Date: 2011-01-01 21:30:44 +0100 (Sat, 01 Jan 2011) $
 !!
-!! $Header: /home/ssipsl/CVSREP/ORCHIDEE/src_sechiba/hydrol.f90,v 1.36 2009/01/07 13:39:45 ssipsl Exp $
+!< $HeadURL: http://forge.ipsl.jussieu.fr/orchidee/svn/trunk/ORCHIDEE/src_sechiba/hydrol.f90 $
+!< $Date: 2011-01-01 21:30:44 +0100 (Sat, 01 Jan 2011) $
+!< $Author: mmaipsl $
+!< $Revision: 45 $
 !! IPSL (2006)
 !!  This software is governed by the CeCILL licence see ORCHIDEE/ORCHIDEE_CeCILL.LIC
@@ -224,11 +227,11 @@
     !! We consider that any water on the ice is snow and we only peforme a water balance to have consistency.
     !! The water balance is limite to + or - 10^6 so that accumulation is not endless
+    REAL(r_std),DIMENSION (kjpindex), INTENT (inout)     :: runoff           !! Complete runoff
+    REAL(r_std),DIMENSION (kjpindex), INTENT (inout)     :: drainage         !! Drainage
+    REAL(r_std),DIMENSION (kjpindex,nbdl), INTENT (inout):: shumdiag         !! relative soil moisture
     ! output fields
-    REAL(r_std),DIMENSION (kjpindex), INTENT (out)     :: runoff           !! Complete runoff
-    REAL(r_std),DIMENSION (kjpindex), INTENT (out)     :: drainage         !! Drainage
     REAL(r_std),DIMENSION (kjpindex,nvm), INTENT (out) :: humrel           !! Relative humidity
     REAL(r_std),DIMENSION (kjpindex,nvm), INTENT (out) :: vegstress        !! Veg. moisture stress (only for vegetation growth)
     REAL(r_std),DIMENSION (kjpindex), INTENT (out)     :: drysoil_frac     !! function of litter wetness
-    REAL(r_std),DIMENSION (kjpindex,nbdl), INTENT (out):: shumdiag         !! relative soil moisture
     REAL(r_std),DIMENSION (kjpindex), INTENT (out)     :: litterhumdiag    !! litter humidity
     REAL(r_std),DIMENSION (kjpindex), INTENT (out)     :: tot_melt         !! Total melt    
@@ -1082,5 +1085,5 @@
        !
        DO jsl=1,nslm
-          CALL setvar_p (us(:,:,:,jsl), val_exp, 'US_INIT', 0.0_r_std)
+          CALL setvar_p (us(:,:,:,jsl), val_exp, 'US_INIT', zero)
        ENDDO
        !
@@ -1101,5 +1104,5 @@
        !Config        started without a restart file.
        !
-       CALL setvar_p (ae_ns, val_exp, 'EVAPNU_SOIL', 0.0_r_std)
+       CALL setvar_p (ae_ns, val_exp, 'EVAPNU_SOIL', zero)
        !
        !Config Key  = HYDROL_SNOW
@@ -1110,5 +1113,5 @@
        !Config        started without a restart file.
        !
-       CALL setvar_p (snow, val_exp, 'HYDROL_SNOW', 0.0_r_std)
+       CALL setvar_p (snow, val_exp, 'HYDROL_SNOW', zero)
        !
        !Config Key  = HYDROL_SNOWAGE
@@ -1119,5 +1122,5 @@
        !Config        started without a restart file.
        !
-       CALL setvar_p (snow_age, val_exp, 'HYDROL_SNOWAGE', 0.0_r_std)
+       CALL setvar_p (snow_age, val_exp, 'HYDROL_SNOWAGE', zero)
        !
        !Config Key  = HYDROL_SNOW_NOBIO
@@ -1128,5 +1131,5 @@
        !Config        started without a restart file.
        !
-       CALL setvar_p (snow_nobio, val_exp, 'HYDROL_SNOW_NOBIO', 0.0_r_std)
+       CALL setvar_p (snow_nobio, val_exp, 'HYDROL_SNOW_NOBIO', zero)
        !
        !Config Key  = HYDROL_SNOW_NOBIO_AGE
@@ -1137,5 +1140,5 @@
        !Config        started without a restart file.
        !
-       CALL setvar_p (snow_nobio_age, val_exp, 'HYDROL_SNOW_NOBIO_AGE', 0.0_r_std)
+       CALL setvar_p (snow_nobio_age, val_exp, 'HYDROL_SNOW_NOBIO_AGE', zero)
        !
        !
@@ -1148,5 +1151,5 @@
        !Config        the model is started without a restart file. 
        !
-       CALL setvar_p (qsintveg, val_exp, 'HYDROL_QSV', 0.0_r_std)
+       CALL setvar_p (qsintveg, val_exp, 'HYDROL_QSV', zero)
        !
        ! There is no need to configure the initialisation of resdist. If not available it is the vegetation map
@@ -1717,5 +1720,5 @@
           IF (snow(ji).GT.sneige) THEN
              !
-             snowmelt(ji) = (1. - frac_nobio(ji,iice))*(temp_sol_new(ji) - tp_00) * soilcap(ji) / chalfu0
+             snowmelt(ji) = (un - frac_nobio(ji,iice))*(temp_sol_new(ji) - tp_00) * soilcap(ji) / chalfu0
              !
              ! 1.3.1.1 enough snow for melting or not
@@ -1890,5 +1893,4 @@
     REAL(r_std), DIMENSION (kjpindex,nvm)          :: zqsintvegnew
     LOGICAL, SAVE                                  :: firstcall=.TRUE.
-!    REAL(r_std), SAVE, DIMENSION(nvm)              :: throughfall_by_pft
 
     IF ( firstcall ) THEN
@@ -2078,5 +2080,5 @@
     DO jv = 1, nvm
       DO ji = 1, kjpindex
-         IF ( ABS(qsintveg(ji,jv)) > 0. .AND. ABS(qsintveg(ji,jv)) < EPS1 ) THEN
+         IF ( ABS(qsintveg(ji,jv)) > zero .AND. ABS(qsintveg(ji,jv)) < EPS1 ) THEN
             qsintveg(ji,jv) = EPS1
          ENDIF
Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_sechiba/hydrolc.f90
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_sechiba/hydrolc.f90	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_sechiba/hydrolc.f90	(revision 257)
@@ -3,7 +3,10 @@
 !!
 !! @author Marie-Alice Foujols and Jan Polcher
-!! @Version : $Revision: 1.21 $, $Date: 2010/05/07 08:28:13 $
+!! @Version : $Revision: 45 $, $Date: 2011-01-01 21:30:44 +0100 (Sat, 01 Jan 2011) $
 !! 
-!! $Header: /home/ssipsl/CVSREP/ORCHIDEE/src_sechiba/hydrolc.f90,v 1.21 2010/05/07 08:28:13 ssipsl Exp $
+!< $HeadURL: http://forge.ipsl.jussieu.fr/orchidee/svn/trunk/ORCHIDEE/src_sechiba/hydrolc.f90 $
+!< $Date: 2011-01-01 21:30:44 +0100 (Sat, 01 Jan 2011) $
+!< $Author: mmaipsl $
+!< $Revision: 45 $
 !! IPSL (2006)
 !!  This software is governed by the CeCILL licence see ORCHIDEE/ORCHIDEE_CeCILL.LIC
@@ -145,15 +148,16 @@
     !! We consider that any water on the ice is snow and we only peforme a water balance to have consistency.
     !! The water balance is limite to + or - 10^6 so that accumulation is not endless
+    REAL(r_std),DIMENSION (kjpindex,nvm), INTENT (inout) :: humrel        !! Relative humidity
+    REAL(r_std),DIMENSION (kjpindex,nvm), INTENT (inout) :: vegstress     !! Veg. moisture stress (only for vegetation growth)
+    REAL(r_std),DIMENSION (kjpindex,nvm), INTENT (inout) :: qsintveg      !! Water on vegetation due to interception
     ! output fields
-    REAL(r_std),DIMENSION (kjpindex), INTENT (out)     :: run_off_tot   !! Complete runoff
-    REAL(r_std),DIMENSION (kjpindex), INTENT (out)     :: drainage      !! Drainage
-    REAL(r_std),DIMENSION (kjpindex,nvm), INTENT (out) :: humrel        !! Relative humidity
-    REAL(r_std),DIMENSION (kjpindex,nvm), INTENT (out) :: vegstress     !! Veg. moisture stress (only for vegetation growth)
+    REAL(r_std),DIMENSION (kjpindex), INTENT (inout)     :: run_off_tot   !! Complete runoff
+    REAL(r_std),DIMENSION (kjpindex), INTENT (inout)     :: drainage      !! Drainage
+    REAL(r_std),DIMENSION (kjpindex,nbdl), INTENT (inout):: shumdiag      !! relative soil moisture
+
     REAL(r_std),DIMENSION (kjpindex), INTENT (out)     :: rsol          !! Resistence to bare soil evaporation
     REAL(r_std),DIMENSION (kjpindex), INTENT (out)     :: drysoil_frac  !! Fraction of visibly dry soil (between 0 and 1)
-    REAL(r_std),DIMENSION (kjpindex,nbdl), INTENT (out):: shumdiag      !! relative soil moisture
     REAL(r_std),DIMENSION (kjpindex), INTENT (out)     :: litterhumdiag !! litter humidity
     REAL(r_std),DIMENSION (kjpindex), INTENT (out)     :: tot_melt      !! Total melt    
-    REAL(r_std),DIMENSION (kjpindex,nvm), INTENT (out) :: qsintveg      !! Water on vegetation due to interception
 
     !
@@ -293,5 +297,4 @@
        CALL hydrolc_alma(kjpindex, index, .FALSE., qsintveg, snow, snow_nobio, soilwet)
     ENDIF
-
 
     !
@@ -313,5 +316,5 @@
           DO ji = 1, kjpindex
              IF ( vegtot(ji) .GT. zero ) THEN
-                histvar(ji)=histvar(ji)+veget(ji,jv)/vegtot(ji)*MAX((0.1-dss(ji,jv))*mx_eau_eau, 0.0)
+                histvar(ji)=histvar(ji)+veget(ji,jv)/vegtot(ji)*MAX((0.1-dss(ji,jv))*mx_eau_eau, zero)
              ENDIF
           ENDDO
@@ -322,11 +325,11 @@
        CALL histwrite(hist_id, 'mrso', kjit, histvar, kjpindex, index)
 
-       histvar(:)=run_off_tot(:)/86400.
+       histvar(:)=run_off_tot(:)/one_day
        CALL histwrite(hist_id, 'mrros', kjit, histvar, kjpindex, index)
 
-       histvar(:)=(run_off_tot(:)+drainage(:))/86400.
+       histvar(:)=(run_off_tot(:)+drainage(:))/one_day
        CALL histwrite(hist_id, 'mrro', kjit, histvar, kjpindex, index)
 
-       histvar(:)=(precip_rain(:)-SUM(precisol(:,:),dim=2))/86400.
+       histvar(:)=(precip_rain(:)-SUM(precisol(:,:),dim=2))/one_day
        CALL histwrite(hist_id, 'prveg', kjit, histvar, kjpindex, index)
 
@@ -369,5 +372,5 @@
              DO ji = 1, kjpindex
                 IF ( vegtot(ji) .GT. zero ) THEN
-                   histvar(ji)=histvar(ji)+veget(ji,jv)/vegtot(ji)*MAX((0.1-dss(ji,jv))*mx_eau_eau, 0.0)
+                   histvar(ji)=histvar(ji)+veget(ji,jv)/vegtot(ji)*MAX((0.1-dss(ji,jv))*mx_eau_eau, zero)
                 ENDIF
              ENDDO
@@ -375,5 +378,5 @@
           CALL histwrite(hist2_id, 'mrsos', kjit, histvar, kjpindex, index)
 
-          histvar(:)=(run_off_tot(:)+drainage(:))/86400.
+          histvar(:)=(run_off_tot(:)+drainage(:))/one_day
           CALL histwrite(hist2_id, 'mrro', kjit, histvar, kjpindex, index)
 
@@ -772,5 +775,5 @@
         !Config        started without a restart file.
         !
-        CALL setvar_p (snow, val_exp, 'HYDROL_SNOW', 0.0_r_std)
+        CALL setvar_p (snow, val_exp, 'HYDROL_SNOW', zero)
         !
         !Config Key  = HYDROL_SNOWAGE
@@ -781,5 +784,5 @@
         !Config        started without a restart file.
         !
-        CALL setvar_p (snow_age, val_exp, 'HYDROL_SNOWAGE', 0.0_r_std)
+        CALL setvar_p (snow_age, val_exp, 'HYDROL_SNOWAGE', zero)
         !
         !Config Key  = HYDROL_SNOW_NOBIO
@@ -790,5 +793,5 @@
         !Config        started without a restart file.
         !
-        CALL setvar_p (snow_nobio, val_exp, 'HYDROL_SNOW_NOBIO', 0.0_r_std)
+        CALL setvar_p (snow_nobio, val_exp, 'HYDROL_SNOW_NOBIO', zero)
         !
         !Config Key  = HYDROL_SNOW_NOBIO_AGE
@@ -799,5 +802,5 @@
         !Config        started without a restart file.
         !
-        CALL setvar_p (snow_nobio_age, val_exp, 'HYDROL_SNOW_NOBIO_AGE', 0.0_r_std)
+        CALL setvar_p (snow_nobio_age, val_exp, 'HYDROL_SNOW_NOBIO_AGE', zero)
         !
         !Config Key  = HYDROL_HUMR
@@ -808,6 +811,6 @@
         !Config        started without a restart file.
         !
-        CALL setvar_p (humrel, val_exp,'HYDROL_HUMR', 1.0_r_std)
-        CALL setvar_p (vegstress, val_exp,'HYDROL_HUMR', 1.0_r_std)
+        CALL setvar_p (humrel, val_exp,'HYDROL_HUMR', un)
+        CALL setvar_p (vegstress, val_exp,'HYDROL_HUMR', un)
         !
         !Config Key  = HYDROL_BQSB
@@ -827,5 +830,5 @@
         !Config        started without a restart file.
         !
-        CALL setvar_p (gqsb, val_exp, 'HYDROL_GQSB', 0.0_r_std)
+        CALL setvar_p (gqsb, val_exp, 'HYDROL_GQSB', zero)
         !
         !Config Key  = HYDROL_DSG
@@ -836,5 +839,5 @@
         !Config        started without a restart file.
         !
-        CALL setvar_p (dsg, val_exp, 'HYDROL_DSG', 0.0_r_std)
+        CALL setvar_p (dsg, val_exp, 'HYDROL_DSG', zero)
 
         ! set inital value for dsp if needed
@@ -872,5 +875,5 @@
         !Config        the model is started without a restart file. 
         !
-        CALL setvar_p (qsintveg, val_exp, 'HYDROL_QSV', 0.0_r_std)
+        CALL setvar_p (qsintveg, val_exp, 'HYDROL_QSV', zero)
         !
         tmpdss = dsg - gqsb / mx_eau_eau
@@ -889,5 +892,5 @@
                     IF (.NOT. (dsg(ji,1).EQ. zero .OR. gqsb(ji,1).EQ.zero)) THEN
                        ! Ajouts Nathalie - Fred - le 28 Mars 2006
-                       a_subgrd(ji)=MIN(MAX(dsg(ji,1)-dss(ji,1),0.)/dsg_min,1.)
+                       a_subgrd(ji)=MIN(MAX(dsg(ji,1)-dss(ji,1),zero)/dsg_min,un)
                        !
                     ENDIF
@@ -906,5 +909,5 @@
                  IF (.NOT. (dsg(ji,1).EQ. zero .OR. gqsb(ji,1).EQ.zero)) THEN
                     ! Ajouts Nathalie - Fred - le 28 Mars 2006
-                    a_subgrd(ji)=MIN(MAX(dsg(ji,1)-dss(ji,1),0.)/dsg_min,1.)
+                    a_subgrd(ji)=MIN(MAX(dsg(ji,1)-dss(ji,1),zero)/dsg_min,un)
                     !
                  ENDIF
@@ -915,5 +918,5 @@
            ! Correction Nathalie - le 28 Mars 2006 - re-ecriture drysoil_frac/hdry - Fred Hourdin
            ! revu 22 novembre 2007
-           hdry(:) = a_subgrd(:)*dss(:,1) + (1.-a_subgrd(:))*dsp(:,1)
+           hdry(:) = a_subgrd(:)*dss(:,1) + (un-a_subgrd(:))*dsp(:,1)
         ENDIF
         !
@@ -1090,5 +1093,5 @@
 
     ! The fraction of soil which is visibly dry (dry when dss = 0.1 m)
-    drysoil_frac(:) = MIN(MAX(dss(:,1),0.)*10._r_std, un)
+    drysoil_frac(:) = MIN(MAX(dss(:,1),zero)*10._r_std, un)
     !
     ! Compute the resistance to bare soil evaporation
@@ -1102,6 +1105,6 @@
           ! du fond. En gros, rsol=hdry*rsol_cste pour hdry < 1m70
           !rsol(ji) = dss(ji,1) * rsol_cste
-          !rsol(ji) =  ( drysoil_frac(ji) + 1./(10.*(dpu_cste - drysoil_frac(ji))+1.e-10)**2 ) * rsol_cste
-          rsol(ji) =  ( hdry(ji) + 1./(10.*(dpu_cste - hdry(ji))+1.e-10)**2 ) * rsol_cste
+          !rsol(ji) =  ( drysoil_frac(ji) + un/(10.*(dpu_cste - drysoil_frac(ji))+1.e-10)**2 ) * rsol_cste
+          rsol(ji) =  ( hdry(ji) + un/(10.*(dpu_cste - hdry(ji))+1.e-10)**2 ) * rsol_cste
        ENDIF
     ENDDO
@@ -1124,5 +1127,5 @@
 !!$            ( mean_dsg(ji) .GT. min_sechiba ) .AND. &
 !!$            ( mean_dsg(ji) .LT. 5.E-4 ) ) THEN
-!!$        litterhumdiag(ji) = 0.0
+!!$        litterhumdiag(ji) = zero
 !!$      ENDIF
 !!$    ENDDO
@@ -1273,5 +1276,5 @@
          IF (snow(ji).GT.sneige) THEN 
             !
-            snowmelt(ji) = (1. - frac_nobio(ji,iice))*(temp_sol_new(ji) - tp_00) * soilcap(ji) / chalfu0 
+            snowmelt(ji) = (un - frac_nobio(ji,iice))*(temp_sol_new(ji) - tp_00) * soilcap(ji) / chalfu0 
             !
             ! 1.3.1.1 enough snow for melting or not
@@ -1409,5 +1412,5 @@
                     &  (un - snow_nobio_age(ji,iice)/max_snow_age) * dtradia/one_day ) * &
                     &  EXP(-precip_snow(ji) / snow_trans) - snow_nobio_age(ji,iice)
-        IF (d_age(ji) .GT. 0. ) THEN
+        IF (d_age(ji) .GT. zero ) THEN
           xx(ji) = MAX( tp_00 - temp_sol_new(ji), zero )
           xx(ji) = ( xx(ji) / 7._r_std ) ** 4._r_std
@@ -1456,5 +1459,4 @@
     REAL(r_std), DIMENSION (kjpindex,nvm)          :: zqsintvegnew
     LOGICAL, SAVE                                  :: firstcall=.TRUE.
-!    REAL(r_std), SAVE, DIMENSION(nvm)              :: throughfall_by_pft
 
     IF ( firstcall ) THEN
@@ -1578,5 +1580,5 @@
         ENDIF
     !
-        IF (resdist(ji,jv) .GT. 0.) THEN
+        IF (resdist(ji,jv) .GT. zero) THEN
          qsintveg2(ji,jv) = qsintveg(ji,jv)/resdist(ji,jv)
         ELSE
@@ -1586,5 +1588,5 @@
     ENDDO
     !
-    vegchtot(:) = 0.
+    vegchtot(:) = zero
     DO jv = 1, nvm
       DO ji = 1, kjpindex
@@ -1595,5 +1597,5 @@
     DO jv = 1, nvm
       DO ji = 1, kjpindex
-        IF ( vegchtot(ji) .GT. 0. ) THEN
+        IF ( vegchtot(ji) .GT. zero ) THEN
           gdq(ji,jv) = ABS(vmr(ji,jv)) * gqsb(ji,jv)
           bdq(ji,jv) = ABS(vmr(ji,jv)) * bqsb(ji,jv)
@@ -1613,5 +1615,5 @@
     DO jv = 1, nvm
       DO ji = 1, kjpindex
-        IF ( ( vegchtot(ji) .GT. 0. ) .AND. ( vmr(ji,jv) .LT. 0. ) ) THEN
+        IF ( ( vegchtot(ji) .GT. zero ) .AND. ( vmr(ji,jv) .LT. zero ) ) THEN
           gtr(ji) = gtr(ji) + gdq(ji,jv)
           btr(ji) = btr(ji) + bdq(ji,jv)
@@ -1625,8 +1627,8 @@
     DO jv = 1, nvm
       DO ji = 1, kjpindex
-        IF ( vegchtot(ji) .GT. 0. .AND. ABS(vtr(ji)) .GT. EPS1) THEN
+        IF ( vegchtot(ji) .GT. zero .AND. ABS(vtr(ji)) .GT. EPS1) THEN
             fra(ji) = vmr(ji,jv) / vtr(ji)
-             IF ( vmr(ji,jv) .GT. 0.)  THEN
-              IF (veget(ji,jv) .GT. 0.) THEN
+             IF ( vmr(ji,jv) .GT. zero)  THEN
+              IF (veget(ji,jv) .GT. zero) THEN
                gqsb(ji,jv) = (resdist(ji,jv)*gqsb(ji,jv) + fra(ji)*gtr(ji))/veget(ji,jv)
                bqsb(ji,jv) = (resdist(ji,jv)*bqsb(ji,jv) + fra(ji)*btr(ji))/veget(ji,jv)
@@ -2003,6 +2005,6 @@
     IF (long_print) WRITE(numout,*)  'hydrolc_soil 3.0 : Vertical diffusion'
 
-    mean_bqsb(:) = 0.
-    mean_gqsb(:) = 0.
+    mean_bqsb(:) = zero
+    mean_gqsb(:) = zero
     DO jv = 1, nvm
       DO ji = 1, kjpindex
@@ -2030,5 +2032,5 @@
         DO ji = 1, kjpindex
            IF (lbad_ij(ji)) THEN
-              IF ( veget(ji,jv) .GT. 0. ) THEN
+              IF ( veget(ji,jv) .GT. zero ) THEN
                  !
                  bqsb(ji,jv) = mean_bqsb(ji)
@@ -2056,5 +2058,5 @@
 !        !
 !        DO ji = 1, kjpindex
-!          IF ( veget(ji,jv) .GT. 0. ) THEN
+!          IF ( veget(ji,jv) .GT. zero ) THEN
 !            !
 !            bqsb(ji,jv) = mean_bqsb(ji)
@@ -2082,6 +2084,6 @@
       ENDDO
       !
-      mean_bqsb(:) = 0.
-      mean_gqsb(:) = 0.
+      mean_bqsb(:) = zero
+      mean_gqsb(:) = zero
       DO jv = 1, nvm
         DO ji = 1, kjpindex
@@ -2180,6 +2182,6 @@
                zhumrel_up(ji) = EXP( - humcste(jv) * dss(ji,jv))
                ! Ajouts Nathalie - Fred - le 28 Mars 2006
-               a_subgrd(ji,jv)=MIN(MAX(dsg(ji,jv)-dss(ji,jv),0.)/dsg_min,1.)
-               humrel(ji,jv)=a_subgrd(ji,jv)*zhumrel_up(ji)+(1.-a_subgrd(ji,jv))*zhumrel_lo(ji)
+               a_subgrd(ji,jv)=MIN(MAX(dsg(ji,jv)-dss(ji,jv),zero)/dsg_min,un)
+               humrel(ji,jv)=a_subgrd(ji,jv)*zhumrel_up(ji)+(un-a_subgrd(ji,jv))*zhumrel_lo(ji)
                !
                vegstress(ji,jv) = zhumrel_lo(ji) + zhumrel_up(ji) - EXP( - humcste(jv) * dsg(ji,jv) ) 
@@ -2221,9 +2223,9 @@
 
     ! The fraction of visibly dry soil (dry when dss(:,1) = 0.1 m)
-    drysoil_frac(:) = MIN(MAX(dss(:,1),0.)*10._r_std, un)
+    drysoil_frac(:) = MIN(MAX(dss(:,1),zero)*10._r_std, un)
 
     ! Correction Nathalie - le 28 Mars 2006 - re-ecriture drysoil_frac/hdry - Fred Hourdin
     ! revu 22 novembre 2007
-    hdry(:) = a_subgrd(:,1)*dss(:,1) + (1.-a_subgrd(:,1))*dsp(:,1)
+    hdry(:) = a_subgrd(:,1)*dss(:,1) + (un-a_subgrd(:,1))*dsp(:,1)
     !
     ! Compute the resistance to bare soil evaporation.
@@ -2237,5 +2239,5 @@
           ! du fond. En gros, rsol=hdry*rsol_cste pour hdry < 1m70
           !rsol(ji) = dss(ji,1) * rsol_cste
-          rsol(ji) =  ( hdry(ji) + 1./(10.*(dpu_cste - hdry(ji))+1.e-10)**2 ) * rsol_cste
+          rsol(ji) =  ( hdry(ji) + un/(10.*(dpu_cste - hdry(ji))+1.e-10)**2 ) * rsol_cste
        ENDIF
     ENDDO
@@ -2389,5 +2391,5 @@
        IF ( ABS(delta_water(ji)-tot_flux(ji)) .GT. allowed_err ) THEN
           WRITE(numout,*) 'HYDROL does not conserve water. The erroneous point is : ', ji
-          WRITE(numout,*) 'The error in mm/d is :', (delta_water(ji)-tot_flux(ji))/dtradia, &
+          WRITE(numout,*) 'The error in mm/d is :', (delta_water(ji)-tot_flux(ji))/dtradia*one_day, &
                & ' and in mm/dt : ', delta_water(ji)-tot_flux(ji)
           WRITE(numout,*) 'delta_water : ', delta_water(ji), ' tot_flux : ', tot_flux(ji)
@@ -2520,5 +2522,5 @@
       !Config  Key  = HYDROL_TAU_HDIFF
       !Config  Desc = time scale (s) for horizontal diffusion of water
-      !Config  Def  = 86400.
+      !Config  Def  = one_day
       !Config  If   = HYDROL_OK_HDIFF
       !Config  Help = Defines how fast diffusion occurs horizontally between
@@ -2526,5 +2528,5 @@
       !Config         diffusion.
 
-      tau_hdiff = 86400.
+      tau_hdiff = one_day
       CALL getin_p('HYDROL_TAU_HDIFF',tau_hdiff)
 
Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_sechiba/intersurf.f90
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_sechiba/intersurf.f90	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_sechiba/intersurf.f90	(revision 257)
@@ -7,9 +7,12 @@
 !!
 !! @call sechiba_main
-!! @Version : $Revision: 1.85 $, $Date: 2010/07/29 15:58:19 $
+!! @Version : $Revision: 221 $, $Date: 2011-05-16 17:26:17 +0200 (Mon, 16 May 2011) $
 !!
 !! @author Marie-Alice Foujols and Jan Polcher
 !! 
-!! $Header: /home/ssipsl/CVSREP/ORCHIDEE/src_sechiba/intersurf.f90,v 1.85 2010/07/29 15:58:19 ssipsl Exp $
+!< $HeadURL: http://forge.ipsl.jussieu.fr/orchidee/svn/trunk/ORCHIDEE/src_sechiba/intersurf.f90 $
+!< $Date: 2011-05-16 17:26:17 +0200 (Mon, 16 May 2011) $
+!< $Author: martial.mancip $
+!< $Revision: 221 $
 !! IPSL (2006)
 !!  This software is governed by the CeCILL licence see ORCHIDEE/ORCHIDEE_CeCILL.LIC
@@ -181,5 +184,4 @@
     !
     CALL ipslnlf(new_number=numout,old_number=old_fileout)
-
     !
     IF (l_first_intersurf) THEN
@@ -225,5 +227,5 @@
        IF ( ok_watchout ) THEN
           IF (is_root_prc) THEN
-             zlev_mean = 0.
+             zlev_mean = zero
              DO ik=1, nbp_glo
                 j = ((index_g(ik)-1)/iim_g) + 1
@@ -391,5 +393,5 @@
 !!$               dt_split_watch,dt_watch,one_day
 !!$          CALL solarang (julian_watch, julian0, iim, jjm, lon, lat, sinang)
-!!$          WHERE ( sinang(:,:) .LT. EPSILON(1.) ) 
+!!$          WHERE ( sinang(:,:) .LT. EPSILON(un) ) 
 !!$             isinang(:,:) = isinang(:,:) - 1
 !!$          ENDWHERE
@@ -529,18 +531,18 @@
           CALL histwrite (hist_id, 'riverflow',itau_sechiba, driver, kjpindex, kindex)
        ! 
-          CALL histwrite (hist_id, 'temp_sol', itau_sechiba, temp_sol_NEW, iim*jjm, kindex)
-          CALL histwrite (hist_id, 'tsol_max', itau_sechiba, temp_sol_NEW, iim*jjm, kindex)
-          CALL histwrite (hist_id, 'tsol_min', itau_sechiba, temp_sol_NEW, iim*jjm, kindex)
-          CALL histwrite (hist_id, 'fluxsens', itau_sechiba, fluxsens, iim*jjm, kindex)
-          CALL histwrite (hist_id, 'fluxlat',  itau_sechiba, fluxlat, iim*jjm, kindex)
-          CALL histwrite (hist_id, 'swnet',    itau_sechiba, dswnet, iim*jjm, kindex)
-          CALL histwrite (hist_id, 'swdown',   itau_sechiba, dswdown, iim*jjm, kindex)
-          CALL histwrite (hist_id, 'alb_vis',  itau_sechiba, albedo(:,:,1), iim*jjm, kindex)
-          CALL histwrite (hist_id, 'alb_nir',  itau_sechiba, albedo(:,:,2), iim*jjm, kindex)
-          CALL histwrite (hist_id, 'tair',     itau_sechiba, temp_air, iim*jjm, kindex)
-          CALL histwrite (hist_id, 'qair',     itau_sechiba, qair, iim*jjm, kindex)
+          CALL histwrite (hist_id, 'temp_sol', itau_sechiba, temp_sol_NEW, kjpindex, kindex)
+          CALL histwrite (hist_id, 'tsol_max', itau_sechiba, temp_sol_NEW, kjpindex, kindex)
+          CALL histwrite (hist_id, 'tsol_min', itau_sechiba, temp_sol_NEW, kjpindex, kindex)
+          CALL histwrite (hist_id, 'fluxsens', itau_sechiba, fluxsens, kjpindex, kindex)
+          CALL histwrite (hist_id, 'fluxlat',  itau_sechiba, fluxlat, kjpindex, kindex)
+          CALL histwrite (hist_id, 'swnet',    itau_sechiba, dswnet, kjpindex, kindex)
+          CALL histwrite (hist_id, 'swdown',   itau_sechiba, dswdown, kjpindex, kindex)
+          CALL histwrite (hist_id, 'alb_vis',  itau_sechiba, albedo(:,:,1), kjpindex, kindex)
+          CALL histwrite (hist_id, 'alb_nir',  itau_sechiba, albedo(:,:,2), kjpindex, kindex)
+          CALL histwrite (hist_id, 'tair',     itau_sechiba, temp_air, kjpindex, kindex)
+          CALL histwrite (hist_id, 'qair',     itau_sechiba, qair, kjpindex, kindex)
           ! Ajout Nathalie - Juin 2006 - on conserve q2m/t2m
-          CALL histwrite (hist_id, 'q2m',     itau_sechiba, qair, iim*jjm, kindex)
-          CALL histwrite (hist_id, 't2m',     itau_sechiba, temp_air, iim*jjm, kindex)
+          CALL histwrite (hist_id, 'q2m',     itau_sechiba, qair, kjpindex, kindex)
+          CALL histwrite (hist_id, 't2m',     itau_sechiba, temp_air, kjpindex, kindex)
           IF ( hist2_id > 0 ) THEN
              CALL histwrite (hist2_id, 'evap',     itau_sechiba, zvevapp, kjpindex, kindex)
@@ -548,32 +550,32 @@
              CALL histwrite (hist2_id, 'riverflow',itau_sechiba, driver, kjpindex, kindex)
              ! 
-             CALL histwrite (hist2_id, 'temp_sol', itau_sechiba, temp_sol_NEW, iim*jjm, kindex)
-             CALL histwrite (hist2_id, 'tsol_max', itau_sechiba, temp_sol_NEW, iim*jjm, kindex)
-             CALL histwrite (hist2_id, 'tsol_min', itau_sechiba, temp_sol_NEW, iim*jjm, kindex)
-             CALL histwrite (hist2_id, 'fluxsens', itau_sechiba, fluxsens, iim*jjm, kindex)
-             CALL histwrite (hist2_id, 'fluxlat',  itau_sechiba, fluxlat, iim*jjm, kindex)
-             CALL histwrite (hist2_id, 'swnet',    itau_sechiba, dswnet, iim*jjm, kindex)
-             CALL histwrite (hist2_id, 'swdown',   itau_sechiba, dswdown, iim*jjm, kindex)
-             CALL histwrite (hist2_id, 'alb_vis',  itau_sechiba, albedo(:,:,1), iim*jjm, kindex)
-             CALL histwrite (hist2_id, 'alb_nir',  itau_sechiba, albedo(:,:,2), iim*jjm, kindex)
-             CALL histwrite (hist2_id, 'tair',     itau_sechiba, temp_air, iim*jjm, kindex)
-             CALL histwrite (hist2_id, 'qair',     itau_sechiba, qair, iim*jjm, kindex)
-             CALL histwrite (hist2_id, 'q2m',     itau_sechiba, qair, iim*jjm, kindex)
-             CALL histwrite (hist2_id, 't2m',     itau_sechiba, temp_air, iim*jjm, kindex)
+             CALL histwrite (hist2_id, 'temp_sol', itau_sechiba, temp_sol_NEW, kjpindex, kindex)
+             CALL histwrite (hist2_id, 'tsol_max', itau_sechiba, temp_sol_NEW, kjpindex, kindex)
+             CALL histwrite (hist2_id, 'tsol_min', itau_sechiba, temp_sol_NEW, kjpindex, kindex)
+             CALL histwrite (hist2_id, 'fluxsens', itau_sechiba, fluxsens, kjpindex, kindex)
+             CALL histwrite (hist2_id, 'fluxlat',  itau_sechiba, fluxlat, kjpindex, kindex)
+             CALL histwrite (hist2_id, 'swnet',    itau_sechiba, dswnet, kjpindex, kindex)
+             CALL histwrite (hist2_id, 'swdown',   itau_sechiba, dswdown, kjpindex, kindex)
+             CALL histwrite (hist2_id, 'alb_vis',  itau_sechiba, albedo(:,:,1), kjpindex, kindex)
+             CALL histwrite (hist2_id, 'alb_nir',  itau_sechiba, albedo(:,:,2), kjpindex, kindex)
+             CALL histwrite (hist2_id, 'tair',     itau_sechiba, temp_air, kjpindex, kindex)
+             CALL histwrite (hist2_id, 'qair',     itau_sechiba, qair, kjpindex, kindex)
+             CALL histwrite (hist2_id, 'q2m',     itau_sechiba, qair, kjpindex, kindex)
+             CALL histwrite (hist2_id, 't2m',     itau_sechiba, temp_air, kjpindex, kindex)
           ENDIF
        ELSE
           CALL histwrite (hist_id, 'Evap', itau_sechiba, zvevapp, kjpindex, kindex)
-          CALL histwrite (hist_id, 'SWnet',    itau_sechiba, dswnet, iim*jjm, kindex)
-          CALL histwrite (hist_id, 'Qh', itau_sechiba, fluxsens, iim*jjm, kindex)
-          CALL histwrite (hist_id, 'Qle',  itau_sechiba, fluxlat, iim*jjm, kindex)
-          CALL histwrite (hist_id, 'AvgSurfT', itau_sechiba, temp_sol_NEW, iim*jjm, kindex)
-          CALL histwrite (hist_id, 'RadT', itau_sechiba, temp_sol_NEW, iim*jjm, kindex)
+          CALL histwrite (hist_id, 'SWnet',    itau_sechiba, dswnet, kjpindex, kindex)
+          CALL histwrite (hist_id, 'Qh', itau_sechiba, fluxsens, kjpindex, kindex)
+          CALL histwrite (hist_id, 'Qle',  itau_sechiba, fluxlat, kjpindex, kindex)
+          CALL histwrite (hist_id, 'AvgSurfT', itau_sechiba, temp_sol_NEW, kjpindex, kindex)
+          CALL histwrite (hist_id, 'RadT', itau_sechiba, temp_sol_NEW, kjpindex, kindex)
           IF ( hist2_id > 0 ) THEN
              CALL histwrite (hist2_id, 'Evap', itau_sechiba, zvevapp, kjpindex, kindex)
-             CALL histwrite (hist2_id, 'SWnet',    itau_sechiba, dswnet, iim*jjm, kindex)
-             CALL histwrite (hist2_id, 'Qh', itau_sechiba, fluxsens, iim*jjm, kindex)
-             CALL histwrite (hist2_id, 'Qle',  itau_sechiba, fluxlat, iim*jjm, kindex)
-             CALL histwrite (hist2_id, 'AvgSurfT', itau_sechiba, temp_sol_NEW, iim*jjm, kindex)
-             CALL histwrite (hist2_id, 'RadT', itau_sechiba, temp_sol_NEW, iim*jjm, kindex)
+             CALL histwrite (hist2_id, 'SWnet',    itau_sechiba, dswnet, kjpindex, kindex)
+             CALL histwrite (hist2_id, 'Qh', itau_sechiba, fluxsens, kjpindex, kindex)
+             CALL histwrite (hist2_id, 'Qle',  itau_sechiba, fluxlat, kjpindex, kindex)
+             CALL histwrite (hist2_id, 'AvgSurfT', itau_sechiba, temp_sol_NEW, kjpindex, kindex)
+             CALL histwrite (hist2_id, 'RadT', itau_sechiba, temp_sol_NEW, kjpindex, kindex)
           ENDIF
        ENDIF
@@ -780,5 +782,5 @@
        !
        IF ( ok_watchout ) THEN
-          zlev_mean = 0.
+          zlev_mean = zero
           DO ik=1, kjpindex
 
@@ -905,5 +907,5 @@
 !!$          julian_watch = date0_shifted+((itau_sechiba-0.5)/dt_split_watch)*dt_watch/one_day
 !!$          CALL solarang (julian_watch, julian0, iim, jjm, lon, lat, sinang)
-!!$          WHERE ( sinang(:,:) .LT. EPSILON(1.) ) 
+!!$          WHERE ( sinang(:,:) .LT. EPSILON(un) ) 
 !!$             isinang(:,:) = isinang(:,:) - 1
 !!$          ENDWHERE
@@ -1448,5 +1450,5 @@
        IF ( ok_watchout ) THEN
           IF (is_root_prc) THEN
-             zlev_mean = 0.
+             zlev_mean = zero
              DO ik=1, nbp_glo
                 j = ((index_g(ik)-1)/iim_g) + 1
@@ -1602,5 +1604,5 @@
 !!$          julian_watch = date0_shifted+((itau_sechiba-0.5)/dt_split_watch)*dt_watch/one_day
 !!$          CALL solarang (julian_watch, julian0, iim, jjm, tmp_lon, tmp_lat, sinang)
-!!$          WHERE ( sinang(:,:) .LT. EPSILON(1.) ) 
+!!$          WHERE ( sinang(:,:) .LT. EPSILON(un) ) 
 !!$             isinang(:,:) = isinang(:,:) - 1
 !!$          ENDWHERE
@@ -2178,5 +2180,5 @@
        IF ( ok_watchout ) THEN
           IF (is_root_prc) THEN
-             zlev_mean = 0.
+             zlev_mean = zero
              DO ik=1, nbp_glo
                 j = ((index_g(ik)-1)/iim_g) + 1
@@ -2332,5 +2334,5 @@
 !!$          julian_watch = date0_shifted+((itau_sechiba-0.5)/dt_split_watch)*dt_watch/one_day
 !!$          CALL solarang (julian_watch, julian0, iim, jjm, tmp_lon, tmp_lat, sinang)
-!!$          WHERE ( sinang(:,:) .LT. EPSILON(1.) )
+!!$          WHERE ( sinang(:,:) .LT. EPSILON(un) )
 !!$             isinang(:,:) = isinang(:,:) - 1
 !!$          ENDWHERE
@@ -2586,5 +2588,5 @@
        CALL tlen2itau('1Y',dt,date0,year_length)
        IF ( TRIM(calendar_str) .EQ. 'gregorian' ) THEN  
-          year_spread=1.0
+          year_spread=un
        ELSE
           year_spread = one_year/365.2425
@@ -2610,5 +2612,5 @@
        ! Real date
        CALL ju2ymds (in_julian, year, month, day, sec)
-!!$       jur=0.
+!!$       jur=zero
 !!$       julian_diff = in_julian
 !!$       month_len = ioget_mon_len (year,month)
@@ -2630,7 +2632,7 @@
        ENDIF
     ELSE 
-!!$       in_julian = itau2date(istp-1, 0., dt)
+!!$       in_julian = itau2date(istp-1, zero, dt)
 !!$       CALL ju2ymds (in_julian, year, month, day, sec)
-!!$       jur=0.
+!!$       jur=zero
 !!$       julian_diff = in_julian
 !!$       month_len = ioget_mon_len (year,month)
@@ -2693,5 +2695,4 @@
     CALL getin_p('NVM',nvm)
     WRITE(numout,*)'the number of pfts is : ', nvm
-!!$DS Debug 28/01/2011
     !
     !Config Key  = LONGPRINT
@@ -2723,5 +2724,5 @@
        !
        dt_watch = dt
-       CALL getin('DT_WATCHOUT',dt_watch)
+       CALL getin_p('DT_WATCHOUT',dt_watch)
        dt_split_watch = dt_watch / dt
        !
@@ -2740,9 +2741,7 @@
     ENDIF
 
-
 !!$    DS : reading of IMPOSE_PARAM
     ! Option : do you want to change the values of the parameters
     CALL getin_p('IMPOSE_PARAM',impose_param)
-    ! Calling pft_parameters
     CALL pft_parameters_main  
     !
@@ -2784,4 +2783,7 @@
     IF ( control_flags%hydrol_cwrr ) THEN
        CALL getin_hydrol_cwrr_parameters
+    ELSE
+       CALL getin_hydrolc_parameters
+       ! we read the parameters for the choisnel hydrology
     ENDIF
 
@@ -2800,12 +2802,4 @@
        CALL getin_co2_parameters
     ENDIF
-
-
-
-!!$    DS : reading of IMPOSE_PARAM
-!!$    ! Option : do you want to change the values of the parameters
-!!$    CALL getin_p('IMPOS_PARAM',impos_param)
-!!$    ! Calling pft_parameters
-!!$    CALL pft_main  
 
     !
@@ -2844,7 +2838,7 @@
        WRITE(numout,*) 'It is not possible because it has to be modified ', &
             ' to give correct values.'
-       CALL ipslerr (3,'intsurf_config', &
-         &          'Use of STOMATE_OK_DGVM not allowed with this version.',&
-         &          'ORCHIDEE will stop.', &
+       CALL ipslerr (2,'intsurf_config', &
+         &          'Use of STOMATE_OK_DGVM is not stable for this version.',&
+         &          'ORCHIDEE should not give correct results with this option activated.', &
          &          'Please disable DGVM to use this version of ORCHIDEE.')
     ENDIF
@@ -2965,5 +2959,5 @@
     CALL getin_p('SECHIBA_reset_time', overwrite_time)
     !
-    lev(:) = 0.
+    lev(:) = zero
     itau_dep = istp
     in_julian = itau2date(istp, date0, dt)
@@ -3186,5 +3180,5 @@
     !Config  Key  = WRITE_STEP
     !Config  Desc = Frequency in seconds at which to WRITE output
-    !Config  Def  = 86400.0
+    !Config  Def  = one_day
     !Config  Help = This variables gives the frequency the output of
     !Config         the model should be written into the netCDF file.
@@ -3198,8 +3192,4 @@
     !
     veg(1:nvm)   = (/ (REAL(i,r_std),i=1,nvm) /)
-!$$ DS DEBUG
-    WRITE(numout,*)'nvm : = ', nvm
-    WRITE(numout,*)'veg : =', veg
-!$$ nvm =13 (put the calling to getin before)
     sol(1:ngrnd) = (/ (REAL(i,r_std),i=1,ngrnd) /)   
     soltyp(1:nstm) = (/ (REAL(i,r_std),i=1,nstm) /)
@@ -3216,6 +3206,6 @@
     WRITE(flux_sc,'("ave(X*",F8.1,")")') one_day/dt
     !WRITE(flux_sc,'("(ave(X)*",F8.1,")")') one_day/dt
-    WRITE(flux_insec,'("ave(X*",F8.6,")")') 1.0/dt
-    WRITE(flux_scinsec,'("ave(scatter(X*",F8.6,"))")') 1.0/dt
+    WRITE(flux_insec,'("ave(X*",F8.6,")")') un/dt
+    WRITE(flux_scinsec,'("ave(scatter(X*",F8.6,"))")') un/dt
     WRITE(numout,*) flux_op, one_day/dt, dt, dw
     !-
@@ -3371,8 +3361,4 @@
                & iim,jjm, hori_id, 1,1,1, -99, 32, once(1), dt,dw)  
        ENDIF
-       IF ( control_flags%ok_stomate .OR. control_flags%stomate_watchout ) THEN
-          CALL histdef (hist_id,'CO2FLUX','Total output CO2 flux', 'gC/day/(m^2 tot)', &
-               & iim,jjm, hori_id, nvm, 1, nvm, vegax_id, 32, avescatter(1), dt, dw)
-       ENDIF
        !-
        !- SECHIBA_HISTLEVEL = 2
@@ -3692,9 +3678,4 @@
        CALL histdef(hist_id, 'nobiofrac', 'Fraction of other surface types', '1', &
             & iim,jjm, hori_id, nnobio, 1, nnobio, nobioax_id, 32, avescatter(3), dt,dw)
-       IF ( control_flags%ok_stomate .OR. control_flags%stomate_watchout ) THEN
-          ! Total output CO2 flux                             
-          CALL histdef (hist_id,'CO2FLUX','Total output CO2 flux', 'gC/day/(m^2 tot)', &
-               & iim,jjm, hori_id, nvm, 1, nvm, vegax_id, 32, avescatter(1), dt, dw)
-       ENDIF
      !- 
      !-  General energy balance
@@ -4033,8 +4014,4 @@
           CALL histdef(hist2_id, 'emis', 'Surface emissivity', '?', &
                & iim,jjm, hori_id2, 1,1,1, -99, 32, fluxop2(2), dt, dw2)
-          IF ( control_flags%ok_stomate .OR. control_flags%stomate_watchout ) THEN
-             CALL histdef (hist2_id,'CO2FLUX','Total output CO2 flux', 'gC/day/(m^2 tot)', &
-                  & iim,jjm, hori_id2, nvm, 1, nvm, vegax_id2, 32, avescatter2(2), dt, dw2)
-          ENDIF
           !-
           !- SECHIBA_HISTLEVEL2 = 3
@@ -4298,8 +4275,4 @@
           CALL histdef(hist2_id, 'nobiofrac', 'Fraction of other surface types', '1', &
                & iim,jjm, hori_id2, nnobio, 1, nnobio, nobioax_id2, 32, avescatter2(3), dt, dw2)
-          IF ( control_flags%ok_stomate .OR. control_flags%stomate_watchout ) THEN
-             CALL histdef (hist2_id,'CO2FLUX','Total output CO2 flux', 'gC/day/(m^2 tot)', &
-                  & iim,jjm, hori_id2, nvm, 1, nvm, vegax_id2, 32, avescatter2(1), dt, dw2)
-          ENDIF
           !- 
           !-  General energy balance
@@ -4465,6 +4438,6 @@
        hist_days_stom = 10.
        CALL getin_p('STOMATE_HIST_DT', hist_days_stom)       
-       IF ( hist_days_stom == -1. ) THEN
-          hist_dt_stom = -1.
+       IF ( hist_days_stom == moins_un ) THEN
+          hist_dt_stom = moins_un
           WRITE(numout,*) 'output frequency for STOMATE history file (d): one month.'
        ELSE
@@ -4477,5 +4450,5 @@
        dt_slow_ = one_day
        CALL getin_p('DT_SLOW', dt_slow_)
-       IF ( hist_days_stom /= -1. ) THEN
+       IF ( hist_days_stom /= moins_un ) THEN
           IF (dt_slow_ > hist_dt_stom) THEN
              WRITE(numout,*) "DT_SLOW = ",dt_slow_,"  , STOMATE_HIST_DT = ",hist_dt_stom
@@ -4567,8 +4540,8 @@
        !Config  Help = Time step of the STOMATE IPCC history file
        !-
-       hist_days_stom_ipcc = 0.
+       hist_days_stom_ipcc = zero
        CALL getin_p('STOMATE_IPCC_HIST_DT', hist_days_stom_ipcc)       
-       IF ( hist_days_stom_ipcc == -1. ) THEN
-          hist_dt_stom_ipcc = -1.
+       IF ( hist_days_stom_ipcc == moins_un ) THEN
+          hist_dt_stom_ipcc = moins_un
           WRITE(numout,*) 'output frequency for STOMATE IPCC history file (d): one month.'
        ELSE
@@ -4581,5 +4554,5 @@
        dt_slow_ = one_day
        CALL getin_p('DT_SLOW', dt_slow_)
-       IF ( hist_days_stom_ipcc > 0. ) THEN
+       IF ( hist_days_stom_ipcc > zero ) THEN
           IF (dt_slow_ > hist_dt_stom_ipcc) THEN
              WRITE(numout,*) "DT_SLOW = ",dt_slow_,"  , STOMATE_IPCC_HIST_DT = ",hist_dt_stom_ipcc
@@ -4822,16 +4795,16 @@
          &               1,1,1, -99,32, ave(5), dt, hist_dt)
 
-    ! Monthly CO2 flux                                  
-    CALL histdef (hist_id_stom, &
-         &               TRIM("CO2FLUX_MONTHLY     "), &
-         &               TRIM("Monthly CO2 flux                                  "), &
+    ! CO2 flux                                  
+    CALL histdef (hist_id_stom, &
+         &               TRIM("CO2FLUX             "), &
+         &               TRIM("CO2 flux                                          "), &
          &               TRIM("gC/m^2/pft/mth      "), iim,jjm, hist_hori_id, &
          &               nvm,1,nvm, hist_PFTaxis_id,32, ave(1), dt, hist_dt)
 
-    CALL histdef(hist_id_stom, &
-         &               TRIM("CO2FLUX_MONTHLY_SUM "), &
-         &               TRIM("Monthly CO2 flux                                  "), &
-         &               TRIM("PgC/m^2/mth          "), 1,1, hist_hori_id, &
-         &               1,1,1, -99, 32, ave(1), dt, hist_dt)
+!!$    CALL histdef(hist_id_stom, &
+!!$         &               TRIM("CO2FLUX_MONTHLY_SUM "), &
+!!$         &               TRIM("Monthly CO2 flux Sum                              "), &
+!!$         &               TRIM("PgC/m^2/mth         "), iim,jjm, hist_hori_id, &
+!!$         &               1,1,1, -99, 32, 'inst(scatter(X))', dt, hist_dt)
 
     ! Output CO2 flux from fire                         
@@ -5121,4 +5094,18 @@
          &               TRIM("1/day               "), iim,jjm, hist_hori_id, &
          &               nvm,1,nvm, hist_PFTaxis_id,32, ave(6), dt, hist_dt)
+
+    ! Establish tree
+    CALL histdef (hist_id_stom, &
+         &               TRIM("ESTABTREE           "), &
+         &               TRIM("Rate of tree establishement                       "), &
+         &               TRIM("1/day               "), iim,jjm, hist_hori_id, &
+         &               1,1,1, -99,32, ave(6), dt, hist_dt)
+
+    ! Establish grass
+    CALL histdef (hist_id_stom, &
+         &               TRIM("ESTABGRASS          "), &
+         &               TRIM("Rate of grass establishement                      "), &
+         &               TRIM("1/day               "), iim,jjm, hist_hori_id, &
+         &               1,1,1, -99,32, ave(6), dt, hist_dt)
 
     ! Fraction of plants that dies (light competition)  
Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_sechiba/sechiba.f90
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_sechiba/sechiba.f90	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_sechiba/sechiba.f90	(revision 257)
@@ -4,7 +4,10 @@
 !!
 !! @author Marie-Alice Foujols and Jan Polcher
-!! @Version : $Revision: 1.46 $, $Date: 2010/05/07 08:28:13 $
+!! @Version : $Revision: 45 $, $Date: 2011-01-01 21:30:44 +0100 (Sat, 01 Jan 2011) $
 !! 
-!! $Header: /home/ssipsl/CVSREP/ORCHIDEE/src_sechiba/sechiba.f90,v 1.46 2010/05/07 08:28:13 ssipsl Exp $
+!< $HeadURL: http://forge.ipsl.jussieu.fr/orchidee/svn/trunk/ORCHIDEE/src_sechiba/sechiba.f90 $
+!< $Date: 2011-01-01 21:30:44 +0100 (Sat, 01 Jan 2011) $
+!< $Author: mmaipsl $
+!< $Revision: 45 $
 !! IPSL (2006)
 !!  This software is governed by the CeCILL licence see ORCHIDEE/ORCHIDEE_CeCILL.LIC
@@ -239,5 +242,5 @@
     REAL(r_std),DIMENSION (kjpindex), INTENT (out)           :: tsol_rad         !! Radiative surface temperature
     REAL(r_std),DIMENSION (kjpindex), INTENT (out)           :: vevapp           !! Total of evaporation
-    REAL(r_std),DIMENSION (kjpindex), INTENT (out)           :: temp_sol_new     !! New soil temperature
+    REAL(r_std),DIMENSION (kjpindex), INTENT (inout)           :: temp_sol_new     !! New soil temperature
     REAL(r_std),DIMENSION (kjpindex), INTENT (out)           :: qsurf_out        !! Surface specific humidity
     REAL(r_std),DIMENSION (kjpindex), INTENT (out)           :: z0_out           !! Surface roughness (output diagnostic)
@@ -256,7 +259,4 @@
     REAL(r_std), DIMENSION(kjpindex) :: sum_treefrac, sum_grassfrac, sum_cropfrac
     INTEGER(i_std) :: jv
-
-
-
 
     IF (long_print) WRITE(numout,*) ' kjpindex =',kjpindex
@@ -636,23 +636,12 @@
        ENDIF
 
-       histvar(:)=SUM(vevapwet(:,:),dim=2)/86400
+       histvar(:)=SUM(vevapwet(:,:),dim=2)/one_day
        CALL histwrite(hist_id, 'evspsblveg', kjit, histvar, kjpindex, index)
 
-       histvar(:)=(vevapnu(:)+vevapsno(:))/86400
+       histvar(:)=(vevapnu(:)+vevapsno(:))/one_day
        CALL histwrite(hist_id, 'evspsblsoi', kjit, histvar, kjpindex, index)
 
-       histvar(:)=SUM(transpir(:,:),dim=2)/86400
+       histvar(:)=SUM(transpir(:,:),dim=2)/one_day
        CALL histwrite(hist_id, 'tran', kjit, histvar, kjpindex, index)
-
-!------------------------------------
-
-!       histvar(:)=SUM(veget_max(:,2:9),dim=2)*100*contfrac(:)
-!       CALL histwrite(hist_id, 'treeFrac', kjit, histvar, kjpindex, index)
-
-!       histvar(:)=SUM(veget_max(:,10:11),dim=2)*100*contfrac(:)
-!       CALL histwrite(hist_id, 'grassFrac', kjit, histvar, kjpindex, index)
-
-!       histvar(:)=SUM(veget_max(:,12:13),dim=2)*100*contfrac(:)
-!       CALL histwrite(hist_id, 'cropFrac', kjit, histvar, kjpindex, index)
 
 !$$ 25/10/10 Modif DS & NViovy
@@ -666,5 +655,4 @@
        histvar(:)= sum_cropfrac(:)*100*contfrac(:)
        CALL histwrite(hist_id, 'cropFrac', kjit, histvar, kjpindex, index)
-
 
        histvar(:)=veget_max(:,1)*100*contfrac(:)
@@ -1347,5 +1335,4 @@
     ENDDO
 
-
     !
     ! 2. restart value
@@ -1372,4 +1359,6 @@
     !
 
+    control%river_routing = control_in%river_routing
+    control%hydrol_cwrr = control_in%hydrol_cwrr
     control%ok_co2 = control_in%ok_co2
     control%ok_sechiba = control_in%ok_sechiba
Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_sechiba/sechiba_io.f90
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_sechiba/sechiba_io.f90	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_sechiba/sechiba_io.f90	(revision 257)
@@ -10,7 +10,10 @@
 !!
 !! @author Marie-Alice Foujols and Jan Polcher
-!! @Version : $Revision: 1.8 $, $Date: 2008/03/21 13:56:12 $
+!! @Version : $Revision: 12 $, $Date: 2010-11-05 16:42:13 +0100 (Fri, 05 Nov 2010) $
 !! 
-!! $Header: /home/ssipsl/CVSREP/ORCHIDEE/src_sechiba/sechiba_io.f90,v 1.8 2008/03/21 13:56:12 ssipsl Exp $
+!< $HeadURL: http://forge.ipsl.jussieu.fr/orchidee/svn/trunk/ORCHIDEE/src_sechiba/sechiba_io.f90 $
+!< $Date: 2010-11-05 16:42:13 +0100 (Fri, 05 Nov 2010) $
+!< $Author: mmaipsl $
+!< $Revision: 12 $
 !! IPSL (2006)
 !!  This software is governed by the CeCILL licence see ORCHIDEE/ORCHIDEE_CeCILL.LIC
Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_sechiba/sechiba_io_p.f90
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_sechiba/sechiba_io_p.f90	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_sechiba/sechiba_io_p.f90	(revision 257)
@@ -10,7 +10,10 @@
 !!
 !! @author Marie-Alice Foujols and Jan Polcher
-!! @Version : $Revision: 1.4 $, $Date: 2008/03/21 13:56:12 $
+!! @Version : $Revision: 12 $, $Date: 2010-11-05 16:42:13 +0100 (Fri, 05 Nov 2010) $
 !! 
-!! $Header: /home/ssipsl/CVSREP/ORCHIDEE/src_sechiba/sechiba_io_p.f90,v 1.4 2008/03/21 13:56:12 ssipsl Exp $
+!< $HeadURL: http://forge.ipsl.jussieu.fr/orchidee/svn/trunk/ORCHIDEE/src_sechiba/sechiba_io_p.f90 $
+!< $Date: 2010-11-05 16:42:13 +0100 (Fri, 05 Nov 2010) $
+!< $Author: mmaipsl $
+!< $Revision: 12 $
 !! IPSL (2006)
 !!  This software is governed by the CeCILL licence see ORCHIDEE/ORCHIDEE_CeCILL.LIC
Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_sechiba/slowproc.f90
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_sechiba/slowproc.f90	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_sechiba/slowproc.f90	(revision 257)
@@ -2,5 +2,8 @@
 ! Daily update of leaf area index etc.
 !
-!! $Header: /home/ssipsl/CVSREP/ORCHIDEE/src_sechiba/slowproc.f90,v 1.48 2010/04/20 14:12:04 ssipsl Exp $
+!< $HeadURL: http://forge.ipsl.jussieu.fr/orchidee/svn/trunk/ORCHIDEE/src_sechiba/slowproc.f90 $
+!< $Date: 2011-01-01 21:30:44 +0100 (Sat, 01 Jan 2011) $
+!< $Author: mmaipsl $
+!< $Revision: 45 $
 !! IPSL (2006)
 !!  This software is governed by the CeCILL licence see ORCHIDEE/ORCHIDEE_CeCILL.LIC
@@ -54,4 +57,5 @@
   LOGICAL, SAVE                                   :: old_lai = .FALSE.         ! Old Lai Map interpolation
   LOGICAL, SAVE                                   :: impveg = .FALSE.
+  LOGICAL, SAVE                                   :: impsoilt = .FALSE.
   LOGICAL, SAVE                                   :: old_veget = .FALSE.         ! Old veget Map interpolation
   !
@@ -143,5 +147,5 @@
     LOGICAL, PARAMETER                                 :: check = .FALSE.
 
-    REAL(r_std), SAVE                                       :: sec_old = 0.
+    REAL(r_std), SAVE                                       :: sec_old = zero
     !
     ! do initialisation
@@ -299,5 +303,5 @@
     ! Test each day and assert all slow processes (days and years)
     !
-    IF ( sec_old >= one_day - dtradia .AND.  sec >= 0. ) THEN
+    IF ( sec_old >= one_day - dtradia .AND.  sec >= zero ) THEN
        !
        ! reset counter
@@ -510,8 +514,6 @@
     LOGICAL, PARAMETER                                 :: check = .FALSE.
     !
-    ! DS 15032011 add for replacing SUM(veget_max(ji,nvm-1:nvm 
+    ! DS 15032011 add for replacing SUM(veget_max(ji,nvm-1:nvm)) 
     REAL(r_std)    :: sum_veget_max
-    !
-
 
     !
@@ -582,5 +584,5 @@
     !Config        only done once a day.
     !
-    CALL setvar_p (day_counter, val_exp, 'SECHIBA_DAY', 0.0_r_std)
+    CALL setvar_p (day_counter, val_exp, 'SECHIBA_DAY', zero)
     !
     !Config Key  = LAI_MAP
@@ -733,4 +735,7 @@
        CALL restget_p (rest_id, var_name, nbp_glo, nvm, 12, kjit, .TRUE., laimap)
        !
+    ELSE
+       !
+       ALLOCATE (laimap(1,1,1))
     ENDIF
     !
@@ -806,5 +811,5 @@
     !Config  Key  = DT_SLOW
     !Config  Desc = Time step of STOMATE and other slow processes
-    !Config  Def  = 86400.
+    !Config  Def  = one_day
     !Config  Help = Time step (s) of regular update of vegetation
     !Config         cover, LAI etc. This is also the time step
@@ -905,23 +910,42 @@
        CALL setvar_p (lai, val_exp, 'SECHIBA_LAI', llaimax)
 
- 
-       !Config Key  = SOIL_FRACTIONS
-       !Config Desc = Fraction of the 3 soil types (0-dim mode)
-       !Config Def  = 0.28, 0.52, 0.20
+       !
+       !Config Key  = IMPOSE_SOILT
+       !Config Desc = Should the soil typ be prescribed
+       !Config Def  = n
        !Config If   = IMPOSE_VEG
-       !Config Help = Determines the fraction for the 3 soil types
-       !Config        in the mesh in the following order : sand loam and clay.
-       !
-       CALL setvar_p (soiltype, val_exp, 'SOIL_FRACTIONS', soiltype_default)
-
-
-       !Config Key  = CLAY_FRACTION
-       !Config Desc = Fraction of the clay fraction (0-dim mode)
-       !Config Def  = 0.2
-       !Config If   = IMPOSE_VEG
-       !Config Help = Determines the fraction of clay in the grid box.
-       !
-       CALL setvar_p (clayfraction, val_exp, 'CLAY_FRACTION', clayfraction_default)
-
+       !Config Help = This flag allows the user to impose a soil type distribution.
+       !Config        It is espacially interesting for 0D
+       !Config        simulations. On the globe it does not make too much sense as
+       !Config        it imposes the same soil everywhere
+       !
+       impsoilt = .FALSE.
+       CALL getin_p('IMPOSE_SOILT', impsoilt)
+       IF (impsoilt) THEN
+          !Config Key  = SOIL_FRACTIONS
+          !Config Desc = Fraction of the 3 soil types (0-dim mode)
+          !Config Def  = 0.28, 0.52, 0.20
+          !Config If   = IMPOSE_VEG
+          !Config If   = IMPOSE_SOILT
+          !Config Help = Determines the fraction for the 3 soil types
+          !Config        in the mesh in the following order : sand loam and clay.
+          !
+          CALL setvar_p (soiltype, val_exp, 'SOIL_FRACTIONS', soiltype_default)
+
+          !Config Key  = CLAY_FRACTION
+          !Config Desc = Fraction of the clay fraction (0-dim mode)
+          !Config Def  = 0.2
+          !Config If   = IMPOSE_VEG
+          !Config If   = IMPOSE_SOILT
+          !Config Help = Determines the fraction of clay in the grid box.
+          !
+          CALL setvar_p (clayfraction, val_exp, 'CLAY_FRACTION', clayfraction_default)
+       ELSE
+          IF ( MINVAL(soiltype) .EQ. MAXVAL(soiltype) .AND. MAXVAL(soiltype) .EQ. val_exp .OR.&
+               & MINVAL(clayfraction) .EQ. MAXVAL(clayfraction) .AND. MAXVAL(clayfraction) .EQ. val_exp) THEN
+
+             CALL slowproc_soilt(kjpindex, lalo, neighbours, resolution, contfrac, soiltype, clayfraction)
+          ENDIF
+       ENDIF
        !
        !Config Key  = SLOWPROC_HEIGHT
@@ -1005,5 +1029,5 @@
              ! If restart doesn't contain veget, then it is the first computation
              CALL slowproc_update(kjpindex, lalo, neighbours, resolution, contfrac, &
-                  &               veget_max, frac_nobio, veget_max, frac_nobio, veget_year, init=.TRUE.)
+               &               veget_nextyear, frac_nobio_nextyear, veget_max, frac_nobio, veget_year, init=.TRUE.)
              !
              IF ( control%ok_dgvm  ) THEN
@@ -1172,7 +1196,7 @@
        !
     CASE('MAXR')
-       pref_soil_veg(:,1) = pref_soil_veg_sand
-       pref_soil_veg(:,2) = pref_soil_veg_loan      
-       pref_soil_veg(:,3) = pref_soil_veg_clay
+       pref_soil_veg(:,1) = pref_soil_veg_sand(:)
+       pref_soil_veg(:,2) = pref_soil_veg_loan(:)      
+       pref_soil_veg(:,3) = pref_soil_veg_clay(:)
        !
        ! Current default : equidistribution.
@@ -1365,5 +1389,5 @@
     !
 
-    IF ( ( tau .LT. dt ) .OR. ( dt .LE. 0. ) .OR. ( tau .LE. 0. ) ) THEN
+    IF ( ( tau .LT. dt ) .OR. ( dt .LE. zero ) .OR. ( tau .LE. zero ) ) THEN
        WRITE(numout,*) 'slowproc_long: Problem with time steps'
        WRITE(numout,*) 'dt=',dt
@@ -1411,5 +1435,5 @@
     ! 1.1 Sum up
     !
-    fracsum(:) = 0.
+    fracsum(:) = zero
     DO jv = 1, nnobio
        DO ji = 1, kjpindex
@@ -1477,5 +1501,4 @@
        ENDDO
     ENDDO
-    
     !
     ! 3. if lai of a vegetation type (jv > 1) is small, increase soil part
@@ -1501,8 +1524,8 @@
     ! Ajout Nouveau calcul (stomate-like) 
     DO ji = 1, kjpindex
-       SUMveg = 0.0
+       SUMveg = zero
        veget(ji,1) = veget_max(ji,1)
        DO jv = 2, nvm
-          veget(ji,jv) = veget_max(ji,jv) * ( 1. - exp( - lai(ji,jv) * ext_coeff(jv) ) )
+          veget(ji,jv) = veget_max(ji,jv) * ( un - exp( - lai(ji,jv) * ext_coeff(jv) ) )
           veget(ji,1) = veget(ji,1) + (veget_max(ji,jv) - veget(ji,jv))
           SUMveg = SUMveg + veget(ji,jv)
@@ -1515,5 +1538,4 @@
        ENDIF
     ENDDO
-
     !
     ! 4. Sum up surface fractions and test if the sum is equal to 1
@@ -1523,5 +1545,5 @@
     ! 4.1 Sum up
     !
-    fracsum(:) = 0.
+    fracsum(:) = zero
     DO jv = 1, nnobio
        DO ji = 1, kjpindex
@@ -1599,5 +1621,5 @@
     REAL(r_std), DIMENSION (kjpindex,2), INTENT(in)     :: resolution !! size in x an y of the grid (m)
 
-    REAL(r_std), DIMENSION(kjpindex,nvm,12), INTENT(in) :: laimap     !! LAI lue
+    REAL(r_std), DIMENSION(:,:,:), INTENT(in)           :: laimap     !! LAI lue
     LOGICAL, INTENT(in)                                :: read_lai
     ! 0.2 Output
@@ -1610,5 +1632,5 @@
     ! Test Nathalie. On impose LAI PFT 1 a 0
     ! On boucle sur 2,nvm au lieu de 1,nvm
-    lai(: ,1) = 0.0
+    lai(: ,1) = zero
     DO jv = 2,nvm
 !!$    DO jv = 1,nvm
@@ -1771,5 +1793,5 @@
     !
     WHERE  ( laimaporig(:,:,:) .LT. 0 )
-       laimaporig(:,:,:) = 0.
+       laimaporig(:,:,:) = zero
     ENDWHERE
     !
@@ -1831,5 +1853,5 @@
     ilast = 1
     n_origlai(:) = 0
-    laimap(:,:,:) = 0.    
+    laimap(:,:,:) = zero   
     !
     DO ip=1,ijml
@@ -1943,5 +1965,5 @@
              ! Antartica
              DO jv =1,nvm
-                laimap(ip,jv,:) = 0.
+                laimap(ip,jv,:) = zero
              ENDDO
              !
@@ -1949,5 +1971,5 @@
              ! Artica
              DO jv =1,nvm
-                laimap(ip,jv,:) = 0.
+                laimap(ip,jv,:) = zero
              ENDDO
              !
@@ -1955,5 +1977,5 @@
              ! Greenland
              DO jv =1,nvm
-                laimap(ip,jv,:) = 0.
+                laimap(ip,jv,:) = zero
              ENDDO
              !
@@ -2590,5 +2612,5 @@
        DO ib = 1, nbpt
           idi=1
-          sumf=0.
+          sumf=zero
           DO WHILE ( sub_area(ib,idi) > zero ) 
              ip = sub_index(ib,idi,1)
@@ -2622,6 +2644,5 @@
              IF (PRESENT(init)) THEN
                 IF (init) THEN
-!                   veget_next(ib,:) = (/ 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0. /)
-                    veget_next(ib,1) = 1.
+                    veget_next(ib,1) = un
                     veget_next(ib,2:nvm) = zero
                 ELSE
@@ -2658,5 +2679,5 @@
           !
           idi=1
-          sumf=0.
+          sumf=zero
           DO WHILE ( sub_area(ib,idi) > zero ) 
              ip = sub_index(ib,idi,1)
@@ -2763,6 +2784,6 @@
           err=norm-un
           IF (debug) &
-             WRITE(numout,*) "ib ",ib," SUM(veget_next(ib,:)+frac_nobio_next(ib,:))-1., sumf",err,sumf
-          IF (abs(err) > -EPSILON(1._r_std)) THEN
+             WRITE(numout,*) "ib ",ib," SUM(veget_next(ib,:)+frac_nobio_next(ib,:))-un, sumf",err,sumf
+          IF (abs(err) > -EPSILON(un)) THEN
 !MM 1.9.3
 !          IF (abs(err) > 0.) THEN
@@ -2775,6 +2796,6 @@
              err=norm-un
              IF (debug) &
-                  WRITE(numout,*) "ib ",ib," SUM(veget_next(ib,:)+frac_nobio_next(ib,:))-1.",err
-             IF (abs(err) > EPSILON(1._r_std)) THEN
+                  WRITE(numout,*) "ib ",ib," SUM(veget_next(ib,:)+frac_nobio_next(ib,:))-un",err
+             IF (abs(err) > EPSILON(un)) THEN
 !MM 1.9.3
 !             IF (abs(err) > 0.) THEN
@@ -2927,6 +2948,6 @@
        !
        !
-       veget(ib,:) = 0.0
-       frac_nobio (ib,:) = 0.0
+       veget(ib,:) = zero
+       frac_nobio (ib,:) = zero
        !
     ENDDO
@@ -3063,5 +3084,5 @@
         frac_origveg(:,vid) =  REAL(n_origveg(:,vid),r_std) /  REAL(n_found(:),r_std)
       ELSEWHERE
-         frac_origveg(:,vid) = 0.
+         frac_origveg(:,vid) = zero
       ENDWHERE
     ENDDO
@@ -3099,19 +3120,19 @@
           IF ( lalo(ib,1) .LT. -56.0) THEN
              ! Antartica
-             frac_nobio(ib,:) = 0.0
-             frac_nobio(ib,iice) = 1.0
-             veget(ib,:) = 0.0
+             frac_nobio(ib,:) = zero
+             frac_nobio(ib,iice) = un
+             veget(ib,:) = zero
              !
           ELSE IF ( lalo(ib,1) .GT. 70.0) THEN
              ! Artica
-             frac_nobio(ib,:) = 0.0
-             frac_nobio(ib,iice) = 1.0
-             veget(ib,:) = 0.0
+             frac_nobio(ib,:) = zero
+             frac_nobio(ib,iice) = un
+             veget(ib,:) = zero
              !
           ELSE IF ( lalo(ib,1) .GT. 55.0 .AND. lalo(ib,2) .GT. -65.0 .AND. lalo(ib,2) .LT. -20.0) THEN
              ! Greenland
-             frac_nobio(ib,:) = 0.0
-             frac_nobio(ib,iice) = 1.0
-             veget(ib,:) = 0.0
+             frac_nobio(ib,:) = zero
+             frac_nobio(ib,iice) = un
+             veget(ib,:) = zero
              !
           ELSE
@@ -3144,5 +3165,5 @@
        DO vid = 1, nvm
           IF ( veget(ib,vid) .LT. min_vegfrac ) THEN
-             veget(ib,vid) = 0.0
+             veget(ib,vid) = zero
           ENDIF
        ENDDO
@@ -3346,5 +3367,5 @@
           frac_origveg(:,vid) = n_origveg(:,vid) / n_found(:)
        ELSEWHERE
-          frac_origveg(:,vid) = 0.
+          frac_origveg(:,vid) = zero
        ENDWHERE
     ENDDO
@@ -3382,19 +3403,19 @@
           IF ( lalo(ib,1) .LT. -56.0) THEN
              ! Antartica
-             frac_nobio(ib,:) = 0.0
-             frac_nobio(ib,iice) = 1.0
-             veget(ib,:) = 0.0
+             frac_nobio(ib,:) = zero
+             frac_nobio(ib,iice) = un
+             veget(ib,:) = zero
              !
           ELSE IF ( lalo(ib,1) .GT. 70.0) THEN
              ! Artica
-             frac_nobio(ib,:) = 0.0
-             frac_nobio(ib,iice) = 1.0
-             veget(ib,:) = 0.0
+             frac_nobio(ib,:) = zero
+             frac_nobio(ib,iice) = un
+             veget(ib,:) = zero
              !
           ELSE IF ( lalo(ib,1) .GT. 55.0 .AND. lalo(ib,2) .GT. -65.0 .AND. lalo(ib,2) .LT. -20.0) THEN
              ! Greenland
-             frac_nobio(ib,:) = 0.0
-             frac_nobio(ib,iice) = 1.0
-             veget(ib,:) = 0.0
+             frac_nobio(ib,:) = zero
+             frac_nobio(ib,iice) = un
+             veget(ib,:) = zero
              !
           ELSE
@@ -3427,5 +3448,5 @@
        DO vid = 1, nvm
           IF ( veget(ib,vid) .LT. min_vegfrac ) THEN
-             veget(ib,vid) = 0.0
+             veget(ib,vid) = zero
           ENDIF
        ENDDO
@@ -3554,6 +3575,6 @@
        !
        !
-       veget(ib,:) = 0.0
-       frac_nobio (ib,:) = 0.0
+       veget(ib,:) = zero
+       frac_nobio (ib,:) = zero
        !
     ENDDO
@@ -3690,5 +3711,5 @@
         frac_origveg(:,vid) =  REAL(n_origveg(:,vid),r_std) /  REAL(n_found(:),r_std)
       ELSEWHERE
-         frac_origveg(:,vid) = 0.
+         frac_origveg(:,vid) = zero
       ENDWHERE
     ENDDO
@@ -3726,19 +3747,19 @@
           IF ( lalo(ib,1) .LT. -56.0) THEN
              ! Antartica
-             frac_nobio(ib,:) = 0.0
-             frac_nobio(ib,iice) = 1.0
-             veget(ib,:) = 0.0
+             frac_nobio(ib,:) = zero
+             frac_nobio(ib,iice) = un
+             veget(ib,:) = zero
              !
           ELSE IF ( lalo(ib,1) .GT. 70.0) THEN
              ! Artica
-             frac_nobio(ib,:) = 0.0
-             frac_nobio(ib,iice) = 1.0
-             veget(ib,:) = 0.0
+             frac_nobio(ib,:) = zero
+             frac_nobio(ib,iice) = un
+             veget(ib,:) = zero
              !
           ELSE IF ( lalo(ib,1) .GT. 55.0 .AND. lalo(ib,2) .GT. -65.0 .AND. lalo(ib,2) .LT. -20.0) THEN
              ! Greenland
-             frac_nobio(ib,:) = 0.0
-             frac_nobio(ib,iice) = 1.0
-             veget(ib,:) = 0.0
+             frac_nobio(ib,:) = zero
+             frac_nobio(ib,iice) = un
+             veget(ib,:) = zero
              !
           ELSE
@@ -3771,5 +3792,5 @@
        DO vid = 1, nvm
           IF ( veget(ib,vid) .LT. min_vegfrac ) THEN
-             veget(ib,vid) = 0.0
+             veget(ib,vid) = zero
           ENDIF
        ENDDO
@@ -3962,5 +3983,5 @@
           frac_origveg(:,vid) = n_origveg(:,vid) / n_found(:)
        ELSEWHERE
-          frac_origveg(:,vid) = 0.
+          frac_origveg(:,vid) = zero
        ENDWHERE
     ENDDO
@@ -3998,19 +4019,19 @@
           IF ( lalo(ib,1) .LT. -56.0) THEN
              ! Antartica
-             frac_nobio(ib,:) = 0.0
-             frac_nobio(ib,iice) = 1.0
-             veget(ib,:) = 0.0
+             frac_nobio(ib,:) = zero
+             frac_nobio(ib,iice) = un
+             veget(ib,:) = zero
              !
           ELSE IF ( lalo(ib,1) .GT. 70.0) THEN
              ! Artica
-             frac_nobio(ib,:) = 0.0
-             frac_nobio(ib,iice) = 1.0
-             veget(ib,:) = 0.0
+             frac_nobio(ib,:) = zero
+             frac_nobio(ib,iice) = un
+             veget(ib,:) = zero
              !
           ELSE IF ( lalo(ib,1) .GT. 55.0 .AND. lalo(ib,2) .GT. -65.0 .AND. lalo(ib,2) .LT. -20.0) THEN
              ! Greenland
-             frac_nobio(ib,:) = 0.0
-             frac_nobio(ib,iice) = 1.0
-             veget(ib,:) = 0.0
+             frac_nobio(ib,:) = zero
+             frac_nobio(ib,iice) = un
+             veget(ib,:) = zero
              !
           ELSE
@@ -4043,5 +4064,5 @@
        DO vid = 1, nvm
           IF ( veget(ib,vid) .LT. min_vegfrac ) THEN
-             veget(ib,vid) = 0.0
+             veget(ib,vid) = zero
           ENDIF
        ENDDO
Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_sechiba/thermosoil.f90
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_sechiba/thermosoil.f90	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_sechiba/thermosoil.f90	(revision 257)
@@ -3,7 +3,10 @@
 !!
 !! @author Marie-Alice Foujols and Jan Polcher
-!! @Version : $Revision: 1.15 $, $Date: 2009/01/07 13:39:45 $
+!! @Version : $Revision: 45 $, $Date: 2011-01-01 21:30:44 +0100 (Sat, 01 Jan 2011) $
 !! 
-!! $Header: /home/ssipsl/CVSREP/ORCHIDEE/src_sechiba/thermosoil.f90,v 1.15 2009/01/07 13:39:45 ssipsl Exp $
+!< $HeadURL: http://forge.ipsl.jussieu.fr/orchidee/svn/trunk/ORCHIDEE/src_sechiba/thermosoil.f90 $
+!< $Date: 2011-01-01 21:30:44 +0100 (Sat, 01 Jan 2011) $
+!< $Author: mmaipsl $
+!< $Revision: 45 $
 !! IPSL (2006)
 !!  This software is governed by the CeCILL licence see ORCHIDEE/ORCHIDEE_CeCILL.LIC
@@ -98,9 +101,9 @@
     REAL(r_std),DIMENSION (kjpindex), INTENT (in)      :: temp_sol_new     !! New soil temperature
     REAL(r_std),DIMENSION (kjpindex), INTENT (in)      :: snow             !! Snow quantity
+    REAL(r_std),DIMENSION (kjpindex,nbdl), INTENT (in) :: shumdiag         !! Diagnostic of relative humidity
     ! output fields
-    REAL(r_std),DIMENSION (kjpindex), INTENT (out)     :: soilcap          !! Soil capacity
-    REAL(r_std),DIMENSION (kjpindex), INTENT (out)     :: soilflx          
-    REAL(r_std),DIMENSION (kjpindex,nbdl), INTENT (in) :: shumdiag         !! Diagnostic of relative humidity
-    REAL(r_std),DIMENSION (kjpindex,nbdl), INTENT (out):: stempdiag        !! diagnostic temp profile
+    REAL(r_std),DIMENSION (kjpindex), INTENT (inout)     :: soilcap        !! Soil capacity
+    REAL(r_std),DIMENSION (kjpindex), INTENT (inout)     :: soilflx          
+    REAL(r_std),DIMENSION (kjpindex,nbdl), INTENT (inout):: stempdiag        !! diagnostic temp profile
 
     REAL(r_std),DIMENSION (kjpindex,ngrnd) :: temp
@@ -645,7 +648,7 @@
     REAL(r_std), DIMENSION (kjpindex), INTENT (out)          :: soilflx           !!
     REAL(r_std), DIMENSION (kjpindex), INTENT (out)          :: z1                !!
-    REAL(r_std), DIMENSION (kjpindex,ngrnd), INTENT(out)     :: pcapa             !!
-    REAL(r_std), DIMENSION (kjpindex,ngrnd), INTENT(out)     :: pcapa_en          !!
-    REAL(r_std), DIMENSION (kjpindex,ngrnd), INTENT(out)     :: pkappa            !!
+    REAL(r_std), DIMENSION (kjpindex,ngrnd), INTENT(inout)     :: pcapa             !!
+    REAL(r_std), DIMENSION (kjpindex,ngrnd), INTENT(inout)     :: pcapa_en          !!
+    REAL(r_std), DIMENSION (kjpindex,ngrnd), INTENT(inout)     :: pkappa            !!
     REAL(r_std), DIMENSION (kjpindex,ngrnd-1), INTENT(out)     :: cgrnd             !!
     REAL(r_std), DIMENSION (kjpindex,ngrnd-1), INTENT(out)     :: dgrnd             !!
@@ -837,5 +840,5 @@
                 lev_prog = prev_prog + dz2(jg)
              ENDIF
-            intfact(jd,jg) = MAX(MIN(lev_diag,lev_prog)-MAX(prev_diag, prev_prog), 0.0)/(lev_diag-prev_diag)
+            intfact(jd,jg) = MAX(MIN(lev_diag,lev_prog)-MAX(prev_diag, prev_prog), zero)/(lev_diag-prev_diag)
             prev_prog = lev_prog
           ENDDO
@@ -857,5 +860,5 @@
     ENDIF
 
-    stempdiag(:,:) = 0.
+    stempdiag(:,:) = zero
     DO jg = 1, ngrnd
       DO jd = 1, nbdl
@@ -907,5 +910,5 @@
                 lev_prog = diaglev(jg)
              ENDIF
-             intfactw(jd,jg) = MAX(MIN(lev_diag,lev_prog)-MAX(prev_diag, prev_prog), 0.0)/(lev_diag-prev_diag)
+             intfactw(jd,jg) = MAX(MIN(lev_diag,lev_prog)-MAX(prev_diag, prev_prog), zero)/(lev_diag-prev_diag)
              prev_prog = lev_prog
           ENDDO
@@ -927,5 +930,5 @@
     ENDIF
 
-    wetdiag(:,:) = 0.
+    wetdiag(:,:) = zero
     DO jg = 1, nbdl
       DO jd = 1, ngrnd
Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_sechiba/watchout.f90
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_sechiba/watchout.f90	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_sechiba/watchout.f90	(revision 257)
@@ -3,4 +3,5 @@
   USE defprec
   USE parallel
+  USE constantes
   USE netcdf
 
@@ -10,5 +11,5 @@
 
   LOGICAL,SAVE,PUBLIC             :: ok_watchout = .FALSE.
-  REAL, SAVE,PUBLIC               :: dt_watch = 0.
+  REAL, SAVE,PUBLIC               :: dt_watch = zero
   INTEGER, SAVE,PUBLIC            :: last_action_watch = 0, &
        & last_check_watch = 0
Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/AA_make
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/AA_make	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/AA_make	(revision 257)
@@ -1,4 +1,11 @@
 #-
-#- $Id: AA_make,v 1.27 2010/04/06 14:34:32 ssipsl Exp $
+#- $Id: AA_make 41 2011-01-01 19:56:53Z mmaipsl $
+#-
+PARALLEL_LIB = $(LIBDIR)/libparallel.a
+SXPARALLEL_LIB = $(PARALLEL_LIB)
+#-Q- sxnec  SXPARALLEL_LIB = $(LIBDIR)/libsxparallel.a
+#-Q- sx6nec SXPARALLEL_LIB = $(LIBDIR)/libsxparallel.a
+#-Q- eshpux SXPARALLEL_LIB = $(LIBDIR)/libsxparallel.a
+#-Q- sx8brodie SXPARALLEL_LIB = $(LIBDIR)/libsxparallel.a
 #-
 PARAM_LIB = $(LIBDIR)/libparameters.a
@@ -9,10 +16,10 @@
 #-Q- sx8brodie SXPARAM_LIB = $(LIBDIR)/libsxparameters.a
 #-
-PARALLEL_LIB = $(LIBDIR)/libparallel.a
-SXPARALLEL_LIB = $(PARALLEL_LIB)
-#-Q- sxnec  SXPARALLEL_LIB = $(LIBDIR)/libsxparallel.a
-#-Q- sx6nec SXPARALLEL_LIB = $(LIBDIR)/libsxparallel.a
-#-Q- eshpux SXPARALLEL_LIB = $(LIBDIR)/libsxparallel.a
-#-Q- sx8brodie SXPARALLEL_LIB = $(LIBDIR)/libsxparallel.a
+ORGLOB_LIB = $(LIBDIR)/liborglob.a
+SXORGLOB_LIB = $(ORGLOB_LIB)
+#-Q- sxnec  SXORGLOB_LIB = $(LIBDIR)/libsxorglob.a
+#-Q- sx6nec SXORGLOB_LIB = $(LIBDIR)/libsxorglob.a
+#-Q- eshpux SXORGLOB_LIB = $(LIBDIR)/libsxorglob.a
+#-Q- sx8brodie SXORGLOB_LIB = $(LIBDIR)/libsxorglob.a
 #-
 MODS1 = stomate_data.f90      \
@@ -52,6 +59,7 @@
 #-
 all:
+	$(M_K) libparallel
 	$(M_K) libparameters
-	$(M_K) libparallel
+	$(M_K) liborglob
 	$(M_K) m_all
 	@echo stomate is OK
@@ -67,9 +75,12 @@
 #-Q- sxnec 	-limit vmemoryuse unlimited
 
+libparallel:
+	(cd ../src_parallel; $(M_K) -f Makefile)
+
 libparameters:
 	(cd ../src_parameters; $(M_K) -f Makefile)
 
-libparallel:
-	(cd ../src_parallel; $(M_K) -f Makefile)
+liborglob:
+	(cd ../src_global; $(M_K) -f Makefile)
 
 $(MODEL_LIB)(%.o): %.f90
Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/AA_make.ldef
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/AA_make.ldef	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/AA_make.ldef	(revision 257)
@@ -1,4 +1,4 @@
 #-
-#- $Id: AA_make.ldef,v 1.9 2008/01/08 11:49:08 ssipsl Exp $
+#- $Id: AA_make.ldef 12 2010-11-05 15:42:13Z mmaipsl $
 #-
 #---------------------------------------------------------------------
Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/lpj_constraints.f90
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/lpj_constraints.f90	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/lpj_constraints.f90	(revision 257)
@@ -129,5 +129,5 @@
 
              WHERE ( t2m_min_daily(:) .LT. tmin_crit(j) )
-                adapted(:,j) = 0.
+                adapted(:,j) = zero
              ENDWHERE
 
@@ -135,5 +135,5 @@
              !  ( adapted will approach 1)
 
-             adapted(:,j) = 1. - ( 1. - adapted(:,j) ) * (tau_adapt- dt)/tau_adapt
+             adapted(:,j) = un - ( un - adapted(:,j) ) * (tau_adapt- dt)/tau_adapt
 
           ENDIF
@@ -147,5 +147,5 @@
 
              WHERE ( when_growthinit(:,j) .GT. too_long*one_year )
-                adapted(:,j) = 0.
+                adapted(:,j) = zero
              ENDWHERE
 
@@ -160,5 +160,5 @@
              ! 2.1.3.1 several PFTs (ex: evergreen) don't need vernalization
 
-             regenerate(:,j) = 1.
+             regenerate(:,j) = un
 
           ELSE
@@ -167,5 +167,5 @@
 
              WHERE ( t2m_month(:) .LE. tcm_crit(j) )
-                regenerate(:,j) = 1.
+                regenerate(:,j) = un
              ENDWHERE
 
@@ -181,5 +181,5 @@
 
           WHERE ( regenerate(:,j) .LE. regenerate_min )
-             adapted(:,j) = 0.
+             adapted(:,j) = zero
           ENDWHERE
 
@@ -190,7 +190,7 @@
           !
 
-          adapted(:,j) = 0.
-
-          regenerate(:,j) = 0.
+          adapted(:,j) = zero
+
+          regenerate(:,j) = zero
 
        ENDIF
Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/lpj_cover.f90
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/lpj_cover.f90	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/lpj_cover.f90	(revision 257)
@@ -23,5 +23,5 @@
 
   SUBROUTINE cover (npts, cn_ind, ind, biomass, &
-       veget_max, veget_max_old, veget, lai, litter, carbon)
+       veget_max, veget_max_old, veget, lai, litter, carbon, turnover_daily, bm_to_litter)
 
     !
@@ -37,4 +37,5 @@
     ! density of individuals (1/(m**2 of ground))
     REAL(r_std), DIMENSION(npts,nvm), INTENT(in)          :: ind
+    ! "maximal" coverage fraction of a PFT (LAI -> infinity) on ground at beginning of time step
     REAL(r_std), DIMENSION(npts,nvm), INTENT(in)          :: veget_max_old
 
@@ -44,4 +45,8 @@
     ! "maximal" coverage fraction of a PFT (LAI -> infinity) on ground
     REAL(r_std), DIMENSION(npts,nvm), INTENT(inout)       :: veget_max
+    ! Turnover rates (gC/(m**2 of ground)/day)
+    REAL(r_std), DIMENSION(npts,nvm,nparts), INTENT(inout)          :: turnover_daily
+    ! conversion of biomass to litter (g/m**2 / day
+    REAL(r_std), DIMENSION(npts,nvm,nparts), INTENT(inout)          :: bm_to_litter
 
     ! 0.3 output
@@ -50,5 +55,5 @@
     REAL(r_std), DIMENSION(npts,nvm), INTENT(inout)       :: veget
     ! leaf area index OF AN INDIVIDUAL PLANT
-    REAL(r_std), DIMENSION(npts,nvm), INTENT(in)         :: lai
+    REAL(r_std), DIMENSION(npts,nvm), INTENT(inout)         :: lai
 
     ! metabolic and structural litter, above and below ground (gC/(m**2 of ground))
@@ -60,5 +65,5 @@
 
     ! index
-    INTEGER(i_std)                                         :: i,j
+    INTEGER(i_std)                                         :: i,j,k,m
 
     ! Litter dilution (gC/mÂ²)
@@ -68,7 +73,9 @@
 
     ! conversion vectors
-    REAL(r_std),DIMENSION(nvm)                                         :: delta_veg
+    REAL(r_std),DIMENSION(nvm)                                         :: delta_veg,reduct
     ! vecteur de conversion
-    REAL(r_std)                                                        :: delta_veg_sum
+    REAL(r_std)                                                        :: delta_veg_sum,diff,sr
+    REAL(r_std), DIMENSION(npts)                                       :: frac_nat,sum_vegettree,sum_vegetgrass
+    REAL(r_std), DIMENSION(npts)                                       :: sum_veget_natveg
 
     ! =========================================================================
@@ -81,5 +88,11 @@
     IF ( control%ok_dgvm ) THEN
 
-       veget_max(:,ibare_sechiba) = 1.
+       ! some initialisations
+       frac_nat(:) = un
+       sum_veget_natveg(:) = zero
+       sum_vegettree(:) = zero
+       sum_vegetgrass(:) = zero
+
+       veget_max(:,ibare_sechiba) = un
 
        DO j = 2,nvm
@@ -88,49 +101,78 @@
 
              veget_max(:,j) = ind(:,j) * cn_ind(:,j)
-
-          ENDIF
-
+             sum_veget_natveg(:) = sum_veget_natveg(:) + veget_max(:,j)
+
+          ELSE
+             !fraction occupied by agriculture needs to be substracted for the DGVM
+             !this is used below to constrain veget for natural vegetation, see below
+             frac_nat(:) = frac_nat(:) - veget_max(:,j)
+
+          ENDIF
+
+       ENDDO
+
+       DO i = 1, npts 
+
+          IF (sum_veget_natveg(i) .GT. frac_nat(i) .AND. frac_nat(i) .GT. min_stomate) THEN
+
+             DO j = 2,nvm
+                IF( natural(j) ) THEN
+                   veget_max(i,j) =  veget_max(i,j) * frac_nat(i) / sum_veget_natveg(i)
+                ENDIF
+             ENDDO
+
+          ENDIF
+       ENDDO
+
+       DO j = 2,nvm
           veget_max(:,ibare_sechiba) = veget_max(:,ibare_sechiba) - veget_max(:,j)
-
-       ENDDO
-
+       ENDDO
        veget_max(:,ibare_sechiba) = MAX( veget_max(:,ibare_sechiba), zero )
 
+       ! 1.3 calculate carbon fluxes between PFTs to maintain mass balance
+       !
+
+       DO i = 1, npts         
+          ! Generation of the conversion vector
+
+          delta_veg(:) = veget_max(i,:)-veget_max_old(i,:)
+          delta_veg_sum = SUM(delta_veg,MASK=delta_veg.LT.zero)
+
+          dilu_lit(i,:,:) = zero
+          dilu_soil_carbon(i,:) = zero
+          DO j=1, nvm
+             IF ( delta_veg(j) < -min_stomate ) THEN 
+                dilu_lit(i,:,:)=  dilu_lit(i,:,:) + delta_veg(j)*litter(i,:,j,:) / delta_veg_sum
+                dilu_soil_carbon(i,:)=  dilu_soil_carbon(i,:) + delta_veg(j) * carbon(i,:,j) / delta_veg_sum
+             ENDIF
+          ENDDO
+
+          DO j=1, nvm
+             IF ( delta_veg(j) > min_stomate) THEN
+
+                ! Dilution of reservoirs
+
+                ! Litter
+                litter(i,:,j,:)=(litter(i,:,j,:) * veget_max_old(i,j) + dilu_lit(i,:,:) * delta_veg(j)) / veget_max(i,j)
+
+                ! Soil carbon
+                carbon(i,:,j)=(carbon(i,:,j) * veget_max_old(i,j) + dilu_soil_carbon(i,:) * delta_veg(j)) / veget_max(i,j)
+
+             ENDIF
+
+             IF(j.GE.2.AND.veget_max_old(i,j).GT.min_stomate.AND.veget_max(i,j).GT.min_stomate) THEN
+
+                ! Correct biomass densities (i.e. also litter fall) to conserve mass 
+                ! since it's defined on veget_max
+
+                biomass(i,j,:)=biomass(i,j,:)*veget_max_old(i,j)/veget_max(i,j)
+                turnover_daily(i,j,:)=turnover_daily(i,j,:)*veget_max_old(i,j)/veget_max(i,j)
+                bm_to_litter(i,j,:)=bm_to_litter(i,j,:)*veget_max_old(i,j)/veget_max(i,j)
+
+             ENDIF
+
+          ENDDO
+       ENDDO
     ENDIF
-
-    DO i = 1, npts         
-       ! Generation of the conversion vector
-
-       delta_veg(:) = veget_max(i,:)-veget_max_old(i,:)
-       delta_veg_sum = SUM(delta_veg,MASK=delta_veg.LT.zero)
-
-       dilu_lit(i,:,:) = zero
-       dilu_soil_carbon(i,:) = zero
-       DO j=1, nvm
-          IF ( delta_veg(j) < -min_stomate ) THEN 
-             dilu_lit(i,:,:)=  dilu_lit(i,:,:) - delta_veg(j)*litter(i,:,j,:) / delta_veg_sum
-             dilu_soil_carbon(i,:)=  dilu_soil_carbon(i,:) - delta_veg(j) * carbon(i,:,j) / delta_veg_sum
-          ENDIF
-       ENDDO
-
-       DO j=1, nvm
-          IF ( delta_veg(j) > min_stomate) THEN
-
-             ! Dilution of reservoirs
-
-             ! Litter
-             litter(i,:,j,:)=(litter(i,:,j,:) * veget_max_old(i,j) + dilu_lit(i,:,:) * delta_veg(j)) / veget_max(i,j)
-
-             ! Soil carbon
-             carbon(i,:,j)=(carbon(i,:,j) * veget_max_old(i,j) + dilu_soil_carbon(i,:) * delta_veg(j)) / veget_max(i,j)
-
-          ENDIF
-          !SZ correct biomass to conserve mass since it's defined on veget_max
-          IF(j.GE.2.AND.veget_max_old(i,j).GT.min_stomate.AND.veget_max(i,j).GT.min_stomate) THEN
-             biomass(i,j,:)=biomass(i,j,:)*veget_max_old(i,j)/veget_max(i,j)
-          ENDIF
-
-       ENDDO
-    ENDDO
 
     !
@@ -140,4 +182,6 @@
     !
     !MM in Soenke code but not in merge version ; must keep that ??
+!NV, MM : we keep those comments for compatibility with CMIP5 computations.
+!! They have to be uncommented avec CMIP5 versions in the trunk !
 !!$    DO j = 2,nvm
 !!$       lai(:,j) = biomass(:,j,ileaf,icarbon)*sla(j)
@@ -153,9 +197,97 @@
              veget(i,j) = veget_max(i,j)
           ELSE
-             veget(i,j) = veget_max(i,j) * ( 1. - exp( - lai(i,j) * ext_coeff(j) ) )
+             IF ( control%ok_dgvm ) THEN
+!!$SZneed to check this - this formulation will cause 100% veget, otherwise there will always 
+!!$ be some percent bare ground
+                veget(i,j) = ind(i,j) * cn_ind(i,j)  * ( un - EXP( - lai(i,j) * ext_coeff(j) ) )
+             ELSE
+                veget(i,j) = veget_max(i,j) * ( un - EXP( - lai(i,j) * ext_coeff(j) ) )
+             ENDIF
+          ENDIF
+
+          ! check sums of fpc for natural vegetation (see correction below!) in dynamic mode
+          IF ( control%ok_dgvm ) THEN
+
+             IF(natural(j))THEN
+                IF(tree(j)) THEN
+                   sum_vegettree(i)=sum_vegettree(i)+veget(i,j)
+                ELSE 
+                   sum_vegetgrass(i)=sum_vegetgrass(i)+veget(i,j)
+                ENDIF
+             ENDIF
+
           ENDIF
        ENDDO
     ENDDO
-    !
+
+
+    ! 3.1 correct gridscale fpc for dynamic vegetation
+!!$SZ, this part should be obsolete now that veget_max is forced to 1.0
+!!$ nevertheless maintained just for savety. Whoever wants to test
+!!$ whether this works without is invited to do so.
+
+    ! in the DGVM mode, we can arrive at a sum of veget slighly exceeding 1.0,
+    ! because mainly of grass dynamics...
+    ! In this case, we devide the fpar over natural vegetation first such that 
+    ! grasses are shadowed by trees, and in the theoretically impossible case that
+    ! this is not sufficient, reduce proportionally all veget's.
+    !
+    IF ( control%ok_dgvm ) THEN
+
+       DO i = 1,npts
+
+          diff=sum_vegettree(i)+sum_vegetgrass(i)-frac_nat(i)
+          reduct(:) = 0.
+          ! ordinary case, the reason too much grasses 
+          ! reduce grass veget to match the maximum
+          IF (diff .GT. 0. ) THEN
+
+             IF (sum_vegetgrass(i).GT.min_stomate) THEN
+                sr=0.
+                DO j=2,nvm
+                   IF(natural(j).AND..NOT.tree(j)) THEN
+                      reduct(j)=-MIN(diff,sum_vegetgrass(i))*veget(i,j)/sum_vegetgrass(i)
+                      sr=sr+reduct(j)
+                   ENDIF
+                ENDDO
+                diff=diff+sr
+             ENDIF
+
+          ENDIF
+
+          ! this is theoretically impossible, since trees can only occupy 95%,
+          ! but better be save than sorry
+          IF (diff .GT. min_stomate ) THEN
+
+             IF (sum_vegettree(i).GT.min_stomate) THEN
+                sr=0.
+                DO j=2,nvm
+                   IF(natural(j).AND.tree(j)) THEN
+                      reduct(j)=-MIN(diff,sum_vegettree(i))*veget(i,j)/sum_vegettree(i)
+                      sr=sr+reduct(j)
+                   ENDIF
+                ENDDO
+                diff=diff+sr 
+             ENDIF
+
+          ENDIF
+
+!!$          ! tell user if the problem could not be resolved
+!!$          ! in theory the model should stop here!
+!!$          IF (diff .GT. min_stomate ) THEN
+!!$
+!!$             write(numout,*) 'ATT, DGVM!: veget exceeds bareground without vegetation left'
+!!$             write(numout,*) 'ATT, DGVM!: is this a bug? cell: ',i
+!!$             write(numout,*) 'ATT, DGVM!: veget ',veget(i,:)
+!!$
+!!$          ENDIF
+
+          ! finally, implement the reduction. (reduc is negative!)
+          veget(i,:)=veget(i,:)+reduct(:)
+
+       ENDDO
+
+    ENDIF
+
     veget(:,ibare_sechiba) = un
     DO j = 2,nvm
Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/lpj_crown.f90
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/lpj_crown.f90	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/lpj_crown.f90	(revision 257)
@@ -6,4 +6,8 @@
   !---------------------------------------------------------------------
   !- calculate individual crown area from stem mass.
+  !- SZ, I've put the woodmass calculation out of this routine
+  !      because after the very first establishment, woodmass
+  !      could not be calculated here as veget_max = zero and 
+  !      d_ind not known...
   !---------------------------------------------------------------------
   USE ioipsl
@@ -24,5 +28,5 @@
   !-
   SUBROUTINE crown &
-       &  (npts, PFTpresent, ind, biomass, veget_max, cn_ind, height)
+       &  (npts, PFTpresent, ind, biomass, woodmass_ind, veget_max, cn_ind, height)
     !---------------------------------------------------------------------
     ! 0 declarations
@@ -38,4 +42,6 @@
     ! biomass (gC/(m**2 of ground))
     REAL(r_std),DIMENSION(npts,nvm,nparts),INTENT(in) :: biomass
+    ! woodmass of the individual, needed to calculate crownarea in lpj_crownarea
+    REAL(r_std),DIMENSION(npts,nvm),INTENT(in) :: woodmass_ind
     !-
     ! 0.2 modified fields
@@ -59,5 +65,5 @@
     ! wood mass of an individual
     !-
-    REAL(r_std),DIMENSION(npts) :: woodmass
+!!$    REAL(r_std),DIMENSION(npts) :: woodmass
     !-
     ! index
@@ -75,5 +81,5 @@
     ! 1.1 check if DGVM activated
     !-
-    IF (.NOT.control%ok_dgvm) THEN
+    IF (.NOT.control%ok_dgvm .AND. lpj_gap_const_mort) THEN
        STOP 'crown: not to be called with static vegetation.'
     ENDIF
@@ -81,5 +87,5 @@
     ! 1.2 initialize output to zero
     !-
-    cn_ind(:,:) = 0.0
+    cn_ind(:,:) = zero
     ! no convertion, just cop
     height_presc_12(1:nvm) = height_presc(1:nvm)
@@ -94,18 +100,24 @@
           IF (natural(j)) THEN
              !------ 2.1.1 natural
-             WHERE (PFTpresent(:,j) .AND.ind(:,j).GT.min_stomate)
-                !-------- 2.1.1.1 calculate individual wood mass
-                woodmass(:) = &
-                     &         (biomass(:,j,isapabove)+biomass(:,j,isapbelow) &
-                     &         +biomass(:,j,iheartabove)+biomass(:,j,iheartbelow))/ind(:,j)
+             !WHERE (PFTpresent(:,j) .AND.ind(:,j).GT.min_stomate)
+             WHERE (PFTpresent(:,j) .AND.woodmass_ind(:,j).GT.min_stomate)
+!!$SZ note that woodmass_ind needs to be defined on the individual, hence
+!!$ biomass*veget_max/ind, not as stated here, correction MERGE
+!!$!-------- 2.1.1.1 calculate individual wood mass
+!!$          woodmass(:) = &
+!!$ &         (biomass(:,j,isapabove)+biomass(:,j,isapbelow) &
+!!$ &         +biomass(:,j,iheartabove)+biomass(:,j,iheartbelow))/ind(:,j)
                 !-------- 2.1.1.2 stem diameter (pipe model)
-                dia(:) = (woodmass(:)/(pipe_density*pi/4.*pipe_tune2)) &
+!!$          dia(:) = (woodmass(:)/(pipe_density*pi/4.*pipe_tune2)) &
+                dia(:) = (woodmass_ind(:,j)/(pipe_density*pi/4.*pipe_tune2)) &
                      &                **(1./(2.+pipe_tune3))
                 !-------- 2.1.1.3 height
                 height(:,j) = pipe_tune2*(dia(:)**pipe_tune3)
-                WHERE (height(:,j) > height_presc_12(j))
-                   dia(:) = (height_presc_12(j)/pipe_tune2)**(1./pipe_tune3)
-                   height(:,j) = height_presc_12(j)
-                ENDWHERE
+!!$SZ: The constraint on height has nothing to do with LPJ (for that purpose there's dia_max
+!!$ cannot see why this is necessary - it also blurrs the output, hence I leave it commented
+!!$                WHERE (height(:,j) > height_presc_12(j))
+!!$                   dia(:) = (height_presc_12(j)/pipe_tune2)**(1./pipe_tune3)
+!!$                   height(:,j) = height_presc_12(j)
+!!$                ENDWHERE
                 !-------- 2.1.1.4 crown area: for large truncs, crown area cannot
                 !--------         exceed a certain value, prescribed through maxdia.
@@ -122,5 +134,5 @@
           WHERE (PFTpresent(:,j))
              !------ 2.2.1 an "individual" is 1 m**2 of grass
-             cn_ind(:,j) = 1.
+             cn_ind(:,j) = un
           ENDWHERE
        ENDIF
@@ -129,9 +141,13 @@
        !       ind and cn_ind are 0 if not present
        !---
-       !SZ isn't this physically inconsistent with the assumptions of sechiba??
-       ! the actual LPJ formulation calculates fpc from maximum LAI, and fpar from actual LAI=veget
-       IF (natural(j).AND.control%ok_dgvm) THEN
-          veget_max(:,j) = ind(:,j) * cn_ind(:,j)
-       ENDIF
+!!$SZ: since now all state variables are defined on veget_max it is very
+!!$ dangerous to change this several times in stomate_lpj, as then GPP, turnover and allocated 
+!!$ biomass are not defined on the same space! Hence, veget_max is now kept constant
+!!$ and updated at the end of stomate_lpj in lpj_cover.f90
+!!$ Eventually, this routine should only be called once at the beginning and the end of stomate_lpj
+!!$ or prefereably cn_ind made a saved state variable!
+!!$    IF (natural(j).AND.control%ok_dgvm) THEN
+!!$      veget_max(:,j) = ind(:,j) * cn_ind(:,j)
+!!$    ENDIF
     ENDDO
     !-------------------
Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/lpj_establish.f90
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/lpj_establish.f90	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/lpj_establish.f90	(revision 257)
@@ -33,8 +33,7 @@
        neighbours, resolution, need_adjacent, herbivores, &
        precip_annual, gdd0, lm_lastyearmax, &
-       cn_ind, lai, avail_tree, avail_grass, &
+       cn_ind, lai, avail_tree, avail_grass,  npp_longterm, &
        leaf_age, leaf_frac, &
-       ind, biomass, age, everywhere, co2_to_bm,veget_max)
-
+       ind, biomass, age, everywhere, co2_to_bm,veget_max, woodmass_ind)
     !
     ! 0 declarations
@@ -74,4 +73,6 @@
     ! space availability for grasses
     REAL(r_std), DIMENSION(npts), INTENT(in)                    :: avail_grass
+    ! longterm NPP, for each PFT (gC/(m**2 of ground))
+    REAL(r_std), DIMENSION(npts,nvm), INTENT(in)                :: npp_longterm
     ! "maximal" coverage fraction of a PFT (LAI -> infinity) on ground 
     REAL(r_std), DIMENSION(npts,nvm), INTENT(inout)            :: veget_max
@@ -94,4 +95,6 @@
     !NV passage 2D
     REAL(r_std), DIMENSION(npts,nvm), INTENT(inout)                 :: co2_to_bm
+    ! woodmass of the individual, needed to calculate crownarea in lpj_crownarea
+    REAL(r_std), DIMENSION(npts,nvm), INTENT(inout)                 :: woodmass_ind
 
     ! 0.3 local
@@ -111,4 +114,6 @@
     ! total natural fpc
     REAL(r_std), DIMENSION(npts)                                :: sumfpc
+    ! total fraction occupied by natural vegetation
+    REAL(r_std), DIMENSION(npts)                                :: fracnat
     ! total woody fpc
     REAL(r_std), DIMENSION(npts)                                :: sumfpc_wood
@@ -129,13 +134,25 @@
     ! woodmass of an individual
     REAL(r_std), DIMENSION(npts)                                :: woodmass
+    ! carbon mass in youngest leaf age class (gC/m**2 PFT)
+    REAL(r_std), DIMENSION(npts)                                :: leaf_mass_young
     ! ratio of hw(above) to total hw, sm(above) to total sm
     REAL(r_std), DIMENSION(npts)                                :: sm_at
     ! reduction factor for establishment if many trees or grasses are present
     REAL(r_std), DIMENSION(npts)                                :: factor
+    ! Total carbon mass for all pools
+    REAL(r_std), DIMENSION(npts)                                :: total_bm_c
+    ! Total sappling biomass for all pools
+    REAL(r_std), DIMENSION(npts)                                :: total_bm_sapl
     ! from how many sides is the grid box invaded
     INTEGER(i_std)                                              :: nfrontx
     INTEGER(i_std)                                              :: nfronty
     ! daily establishment rate is large compared to present number of individuals
-    LOGICAL, DIMENSION(npts)                                   :: many_new
+    !LOGICAL, DIMENSION(npts)                                   :: many_new
+    ! flow due to new individuals
+    !   veget_max after establishment, to get a proper estimate of carbon and nitrogen 
+    REAL(r_std), DIMENSION(npts)                                 :: vn
+    !   lai on each PFT surface 
+    REAL(r_std), DIMENSION(npts)                                 :: lai_ind
+
     ! indices
     INTEGER(i_std)                                              :: i,j,k,m
@@ -161,237 +178,349 @@
     ENDIF
 
-    !
-    ! 2 recalculate fpc
-    !
-
-    !
-    ! 2.1 Only natural part of the grid cell
-    !
-
-    DO j = 2,nvm
-
-       IF ( natural(j) ) THEN
-          DO i = 1, npts
-             IF (lai(i,j) == val_exp) THEN               
-                fpc_nat(i,j) = cn_ind(i,j) * ind(i,j)
-             ELSE
-                fpc_nat(i,j) = cn_ind(i,j) * ind(i,j) * ( 1. - exp( -lai(i,j) * ext_coeff(j) ) )
-             ENDIF
-          ENDDO
-       ELSE
-
-          fpc_nat(:,j) = 0.0
-
-       ENDIF
-
-    ENDDO
-
-    !
-    ! 2.2 total natural fpc on grid
-    !
-
-    sumfpc(:) = SUM( fpc_nat(:,:), DIM=2 )
-
-    !
-    ! 2.3 total woody fpc on grid and number of regenerative tree pfts
-    !
-
-    sumfpc_wood(:) = 0.0
-    spacefight_tree(:) = 0.0
-
-    DO j = 2,nvm
-
-       IF ( tree(j) .AND. natural(j) ) THEN
-
-          ! total woody fpc
-
-          WHERE ( PFTpresent(:,j) )
-             sumfpc_wood(:) = sumfpc_wood(:) + fpc_nat(:,j)
-          ENDWHERE
-
-          ! how many trees are competing? Count a PFT fully only if it is present
-          !   on the whole grid box.
-
-          WHERE ( PFTpresent(:,j) .AND. ( regenerate(:,j) .GT. regenerate_crit ) )
-             spacefight_tree(:) = spacefight_tree(:) + everywhere(:,j)
-          ENDWHERE
-
-       ENDIF
-
-    ENDDO
-
-    !
-    ! 2.4 number of natural grasses
-    !
-
-    spacefight_grass(:) = 0.0
-
-    DO j = 2,nvm
-
-       IF ( .NOT. tree(j) .AND. natural(j) ) THEN
-
-          ! how many grasses are competing? Count a PFT fully only if it is present
-          !   on the whole grid box.
-
-          WHERE ( PFTpresent(:,j) )
-             spacefight_grass(:) = spacefight_grass(:) + everywhere(:,j)
-          ENDWHERE
-
-       ENDIF
-
-    ENDDO
-
-    !
-    ! 3 establishment rate
-    !
-
-    !
-    ! 3.1 maximum establishment rate, based on climate only
-    !
-
-    WHERE ( ( precip_annual(:) .GE. precip_crit ) .AND. ( gdd0(:) .GE. gdd_crit_estab ) )
-
-       estab_rate_max_climate_tree(:) = estab_max_tree
-       estab_rate_max_climate_grass(:) = estab_max_grass
-
-    ELSEWHERE
-
-       estab_rate_max_climate_tree(:) = 0.0
-       estab_rate_max_climate_grass(:) = 0.0
-
-    ENDWHERE
-
-    !
-    ! 3.2 reduce maximum tree establishment rate if many trees present.
-    !     In the original DGVM, this is done using a step function which yields a
-    !     reduction by factor 4 if sumfpc_wood(i) .GT.  fpc_crit - 0.05.
-    !     This can lead to small oscillations (without consequences however).
-    !     Here, a steady linear transition is used between fpc_crit-0.075 and
-    !     fpc_crit-0.025.
-    !
-
-    factor(:) = 1. - establish_scal_fact * ( sumfpc_wood(:) - (fpc_crit - fpc_crit_max) )
-    factor(:) = MAX( 0.25_r_std, MIN( un, factor(:) ) )
-
-    estab_rate_max_tree(:) = estab_rate_max_climate_tree(:) * factor(:)
-
-    !
-    ! 3.3 Modulate grass establishment rate.
-    !     If canopy is not closed (fpc < fpc_crit-0.05), normal establishment.
-    !     If canopy is closed, establishment is reduced by a factor 4.
-    !     Factor is linear between these two bounds.
-    !     This is different from the original DGVM where a step function is
-    !     used at fpc_crit-0.05 (This can lead to small oscillations,
-    !     without consequences however).
-    !
-
-    factor(:) = 1. - establish_scal_fact * ( sumfpc(:) - (fpc_crit - fpc_crit_min) )
-    factor(:) = MAX( 0.25_r_std, MIN( un, factor(:) ) )
-
-    estab_rate_max_grass(:) = estab_rate_max_climate_grass(:) * factor(:)
-
-    !
-    ! 4 do establishment for natural PFTs
-    !
-
-    d_ind(:,:) = 0.0
-
-    DO j = 2,nvm
-
-       ! only for natural PFTs
-
-       IF ( natural(j) ) THEN
-
-          !
-          ! 4.1 PFT expansion across the grid box. Not to be confused with areal
-          !     coverage.
-          !
-
-          IF ( treat_expansion ) THEN
-
-             ! only treat plants that are regenerative and present and still can expand
-
-             DO i = 1, npts
-
-                IF ( PFTpresent(i,j) .AND. &
-                     ( everywhere(i,j) .LT. 1. ) .AND. &
-                     ( regenerate(i,j) .GT. regenerate_crit ) ) THEN
-
-                   ! from how many sides is the grid box invaded (separate x and y directions
-                   ! because resolution may be strongly anisotropic)
-                   !
-                   ! For the moment we only look into 4 direction but that can be extanded (JP) 
-                   !
-                   nfrontx = 0
-                   IF ( neighbours(i,3) .GT. 0 ) THEN
-                      IF ( everywhere(neighbours(i,3),j) .GT. 1.-min_stomate ) nfrontx = nfrontx+1
-                   ENDIF
-                   IF ( neighbours(i,7) .GT. 0 ) THEN
-                      IF ( everywhere(neighbours(i,7),j) .GT. 1.-min_stomate ) nfrontx = nfrontx+1
-                   ENDIF
-
-                   nfronty = 0
-                   IF ( neighbours(i,1) .GT. 0 ) THEN
-                      IF ( everywhere(neighbours(i,1),j) .GT. 1.-min_stomate ) nfronty = nfronty+1
-                   ENDIF
-                   IF ( neighbours(i,5) .GT. 0 ) THEN
-                      IF ( everywhere(neighbours(i,5),j) .GT. 1.-min_stomate ) nfronty = nfronty+1
-                   ENDIF
-
-                   everywhere(i,j) = &
-                        everywhere(i,j) + migrate(j) * dt/one_year * &
-                        ( nfrontx / resolution(i,1) + nfronty / resolution(i,2) )
-
-                   IF ( .NOT. need_adjacent(i,j) ) THEN
-
-                      ! in that case, we also assume that the PFT expands from places within
-                      ! the grid box (e.g., oasis).
-
+
+    IF (control%ok_dgvm) THEN
+       !
+       ! 2 recalculate fpc
+       !
+
+       !
+       ! 2.1 Only natural part of the grid cell
+       !
+
+       fracnat(:) = un
+       do j = 2,nvm
+          IF ( .NOT. natural(j) ) THEN
+             fracnat(:) = fracnat(:) - veget_max(:,j)
+          ENDIF
+       ENDDO
+
+       !
+       ! 2.2 total natural fpc on grid
+       !
+       sumfpc(:) = zero
+       DO j = 2,nvm
+
+          IF ( natural(j) ) THEN
+             WHERE(fracnat(:).GT.min_stomate)
+                WHERE (lai(:,j) == val_exp) 
+                   fpc_nat(:,j) = cn_ind(:,j) * ind(:,j) / fracnat(:)
+                ELSEWHERE
+                   fpc_nat(:,j) = cn_ind(:,j) * ind(:,j) / fracnat(:) & 
+                        * ( 1. - exp( - lm_lastyearmax(:,j) * sla(j) * ext_coeff(j) ) )
+                ENDWHERE
+             ENDWHERE
+
+             WHERE ( PFTpresent(:,j) )
+                sumfpc(:) = sumfpc(:) + fpc_nat(:,j)
+             ENDWHERE
+          ELSE
+
+             fpc_nat(:,j) = zero
+
+          ENDIF
+
+       ENDDO
+
+       !
+       ! 2.3 total woody fpc on grid and number of regenerative tree pfts
+       !
+       
+       sumfpc_wood(:) = zero
+       spacefight_tree(:) = zero
+
+       DO j = 2,nvm
+          
+          IF ( tree(j) .AND. natural(j) ) THEN
+             
+             ! total woody fpc
+             
+             WHERE ( PFTpresent(:,j) )
+                sumfpc_wood(:) = sumfpc_wood(:) + fpc_nat(:,j)
+             ENDWHERE
+             
+             ! how many trees are competing? Count a PFT fully only if it is present
+             !   on the whole grid box.
+             
+             WHERE ( PFTpresent(:,j) .AND. ( regenerate(:,j) .GT. regenerate_crit ) )
+                spacefight_tree(:) = spacefight_tree(:) + everywhere(:,j)
+             ENDWHERE
+             
+          ENDIF
+          
+       ENDDO
+       
+       !
+       ! 2.4 number of natural grasses
+       !
+       
+       spacefight_grass(:) = zero
+       
+       DO j = 2,nvm
+          
+          IF ( .NOT. tree(j) .AND. natural(j) ) THEN
+             
+             ! how many grasses are competing? Count a PFT fully only if it is present
+             !   on the whole grid box.
+             
+             WHERE ( PFTpresent(:,j) )
+                spacefight_grass(:) = spacefight_grass(:) + everywhere(:,j)
+             ENDWHERE
+             
+          ENDIF
+          
+       ENDDO
+       
+       !
+       ! 3 establishment rate
+       !
+       
+       !
+       ! 3.1 maximum establishment rate, based on climate only
+       !
+       
+       WHERE ( ( precip_annual(:) .GE. precip_crit ) .AND. ( gdd0(:) .GE. gdd_crit_estab ) )
+          
+          estab_rate_max_climate_tree(:) = estab_max_tree
+          estab_rate_max_climate_grass(:) = estab_max_grass
+          
+       ELSEWHERE
+          
+          estab_rate_max_climate_tree(:) = zero
+          estab_rate_max_climate_grass(:) = zero
+          
+       ENDWHERE
+    
+       !
+       ! 3.2 reduce maximum tree establishment rate if many trees present.
+       !     In the original DGVM, this is done using a step function which yields a
+       !     reduction by factor 4 if sumfpc_wood(i) .GT.  fpc_crit - 0.05.
+       !     This can lead to small oscillations (without consequences however).
+       !     Here, a steady linear transition is used between fpc_crit-0.075 and
+       !     fpc_crit-0.025.
+       !
+       
+       !factor(:) = 1. - establish_scal_fact * ( sumfpc_wood(:) - (fpc_crit - fpc_crit_max) )
+       !factor(:) = MAX( 0.25_r_std, MIN( un, factor(:) ) )
+       
+       !SZ modified according to Smith et al. 2001, 080806
+       factor(:)=(1.0-exp(-5.0*(1.0-sumfpc_wood(:))))*(1.0-sumfpc_wood(:))
+
+       estab_rate_max_tree(:) = estab_rate_max_climate_tree(:) * factor(:)
+       
+       !
+       ! 3.3 Modulate grass establishment rate.
+       !     If canopy is not closed (fpc < fpc_crit-0.05), normal establishment.
+       !     If canopy is closed, establishment is reduced by a factor 4.
+       !     Factor is linear between these two bounds.
+       !     This is different from the original DGVM where a step function is
+       !     used at fpc_crit-0.05 (This can lead to small oscillations,
+       !     without consequences however).
+       !
+       
+       !factor(:) = 1. - establish_scal_fact * ( sumfpc(:) - (fpc_crit - fpc_crit_min) )
+       !factor(:) = MAX( 0.25_r_std, MIN( un, factor(:) ) )
+       !estab_rate_max_grass(:) = estab_rate_max_climate_grass(:) * factor(:)
+ 
+       !SZ modified to true LPJ formulation, grasses are only allowed in the
+       !fpc fraction not occupied by trees..., 080806
+!NVmodif       estab_rate_max_grass(:)=MAX(0.98-sumfpc(:),zero)
+       estab_rate_max_grass(:)=MAX(MIN(estab_rate_max_climate_grass(:),0.98-sumfpc(:)),zero)
+
+       ! SZ: longterm grass NPP for competition between C4 and C3 grasses
+       !     to avoid equal veget_max, the idea is that more reestablishment
+       !     is possible for the more productive PFT
+       factor(:)=min_stomate
+       DO j = 2,nvm
+          IF ( natural(j) .AND. .NOT.tree(j)) & 
+               factor(:)=factor(:)+npp_longterm(:,j) * &
+               lm_lastyearmax(:,j) * sla(j)
+       ENDDO 
+       !
+       !
+       !
+       ! 4 do establishment for natural PFTs
+       !
+       
+       d_ind(:,:) = zero
+       
+       DO j = 2,nvm
+          
+          ! only for natural PFTs
+          
+          IF ( natural(j) ) THEN
+             
+             !
+             ! 4.1 PFT expansion across the grid box. Not to be confused with areal
+             !     coverage.
+             !
+             
+             IF ( treat_expansion ) THEN
+                
+                ! only treat plants that are regenerative and present and still can expand
+                
+                DO i = 1, npts
+                   
+                   IF ( PFTpresent(i,j) .AND. &
+                        ( everywhere(i,j) .LT. un ) .AND. &
+                        ( regenerate(i,j) .GT. regenerate_crit ) ) THEN
+                      
+                      ! from how many sides is the grid box invaded (separate x and y directions
+                      ! because resolution may be strongly anisotropic)
+                      !
+                      ! For the moment we only look into 4 direction but that can be extanded (JP) 
+                      !
+                      nfrontx = 0
+                      IF ( neighbours(i,3) .GT. 0 ) THEN
+                         IF ( everywhere(neighbours(i,3),j) .GT. 1.-min_stomate ) nfrontx = nfrontx+1
+                      ENDIF
+                      IF ( neighbours(i,7) .GT. 0 ) THEN
+                         IF ( everywhere(neighbours(i,7),j) .GT. 1.-min_stomate ) nfrontx = nfrontx+1
+                      ENDIF
+                      
+                      nfronty = 0
+                      IF ( neighbours(i,1) .GT. 0 ) THEN
+                         IF ( everywhere(neighbours(i,1),j) .GT. 1.-min_stomate ) nfronty = nfronty+1
+                      ENDIF
+                      IF ( neighbours(i,5) .GT. 0 ) THEN
+                         IF ( everywhere(neighbours(i,5),j) .GT. 1.-min_stomate ) nfronty = nfronty+1
+                      ENDIF
+                      
                       everywhere(i,j) = &
                            everywhere(i,j) + migrate(j) * dt/one_year * &
-                           2. * SQRT( pi*everywhere(i,j)/(resolution(i,1)*resolution(i,2)) )
-
+                           ( nfrontx / resolution(i,1) + nfronty / resolution(i,2) )
+                      
+                      IF ( .NOT. need_adjacent(i,j) ) THEN
+                         
+                         ! in that case, we also assume that the PFT expands from places within
+                         ! the grid box (e.g., oasis).
+                         
+                         everywhere(i,j) = &
+                              everywhere(i,j) + migrate(j) * dt/one_year * &
+                              2. * SQRT( pi*everywhere(i,j)/(resolution(i,1)*resolution(i,2)) )
+                         
+                      ENDIF
+                      
+                      everywhere(i,j) = MIN( everywhere(i,j), un )
+                      
                    ENDIF
-
-                   everywhere(i,j) = MIN( everywhere(i,j), un )
-
-                ENDIF
-
-             ENDDO
-
-          ENDIF  ! treat expansion?
-
-          !
-          ! 4.2 establishment rate
-          !     - Is lower if the PFT is only present in a small part of the grid box
-          !       (after its introduction), therefore multiplied by "everywhere".
-          !     - Is divided by the number of PFTs that compete ("spacefight").
-          !     - Is modulated by space availability (avail_tree, avail_grass).
-          !
-
-          IF ( tree(j) ) THEN
-
-             ! 4.2.1 present and regenerative trees
-
-             WHERE ( PFTpresent(:,j) .AND. ( regenerate(:,j) .GT. regenerate_crit ) )
-
-
-                d_ind(:,j) = estab_rate_max_tree(:)*everywhere(:,j)/spacefight_tree(:) * &
-                     avail_tree(:) * dt/one_year
-
-             ENDWHERE
-
-          ELSE
-
-             ! 4.2.2 present and regenerative grasses
-
-             WHERE ( PFTpresent(:,j) .AND. ( regenerate(:,j) .GT. regenerate_crit ) )
-
-                d_ind(:,j) = estab_rate_max_grass(:)*everywhere(:,j)/spacefight_grass(:) * &
-                     avail_grass(:) * dt/one_year
-
-             ENDWHERE
-
-          ENDIF  ! tree/grass
+                   
+                ENDDO
+                
+             ENDIF  ! treat expansion?
+             
+             !
+             ! 4.2 establishment rate
+             !     - Is lower if the PFT is only present in a small part of the grid box
+             !       (after its introduction), therefore multiplied by "everywhere".
+             !     - Is divided by the number of PFTs that compete ("spacefight").
+             !     - Is modulated by space availability (avail_tree, avail_grass).
+             !
+             
+             IF ( tree(j) ) THEN
+                
+                ! 4.2.1 present and regenerative trees
+                
+                WHERE ( PFTpresent(:,j) .AND. ( regenerate(:,j) .GT. regenerate_crit ) )
+                   
+                   
+                   d_ind(:,j) = estab_rate_max_tree(:)*everywhere(:,j)/spacefight_tree(:) * &
+                        avail_tree(:) * dt/one_year
+                   
+                ENDWHERE
+                
+             ELSE
+                
+                ! 4.2.2 present and regenerative grasses
+                
+                WHERE ( PFTpresent(:,j) .AND. ( regenerate(:,j) .GT. regenerate_crit )  & 
+                     .AND.factor(:).GT.min_stomate .AND. spacefight_grass(:).GT. min_stomate) 
+                   
+                   d_ind(:,j) = estab_rate_max_grass(:)*everywhere(:,j)/spacefight_grass(:) * &
+                        MAX(min_stomate,npp_longterm(:,j)*lm_lastyearmax(:,j)*sla(j)/factor(:)) * fracnat(:) * dt/one_year
+                   
+                ENDWHERE
+
+             ENDIF  ! tree/grass
+
+          ENDIF ! if natural
+       ENDDO ! PFTs
+
+    ELSE ! lpj establishment in static case, SZ 080806, account for real LPJ dynamics in 
+       ! prescribed vegetation, i.e. population dynamics within a given area of the 
+       ! grid cell
+
+       d_ind(:,:) = zero
+
+       DO j = 2,nvm
+
+          ! only for natural PFTs
+
+          WHERE(ind(:,j)*cn_ind(:,j).GT.min_stomate)
+             lai_ind(:)=sla(j) * lm_lastyearmax(:,j)/(ind(:,j)*cn_ind(:,j))
+          ELSEWHERE
+             lai_ind(:)= zero
+          ENDWHERE
+
+          IF ( natural(j) .AND. tree(j)) THEN 
+
+             fpc_nat(:,j) =  MIN(1.0,cn_ind(:,j) * ind(:,j) * & 
+                  MAX( ( 1._r_std - exp( - ext_coeff(j) * lai_ind(:) ) ), min_cover ) )
+             !fpc_nat(:,j) = max(fpc_nat(:,j),1.-exp(-0.5*sla(j) * lm_lastyearmax(:,j)))
+
+
+             WHERE (veget_max(:,j).GT.min_stomate.AND.ind(:,j).LE.2.)
+
+                ! only establish into growing stands, ind can become very
+                ! large in the static mode because LAI is very low in poor 
+                ! growing conditions, favouring continuous establishment. To avoid this
+                ! a maximum IND is set. BLARPP: This should be replaced by a 
+                ! better stand density criteria
+                !
+                factor(:)=(1.0-exp(-5.0*(1.0-fpc_nat(:,j))))*(1.0-fpc_nat(:,j))
+
+                estab_rate_max_tree(:) = estab_max_tree * factor(:) 
+                !
+                ! 4 do establishment for natural PFTs
+                !
+                d_ind(:,j) = MAX( zero, estab_rate_max_tree(:) * dt/one_year)
+
+             ENDWHERE
+
+             !SZ: quickfix: to simulate even aged stand, uncomment the following lines...
+             !where (ind(:,j) .LE. min_stomate)
+             !d_ind(:,j) = 0.1 !MAX( 0.0, estab_rate_max_tree(:) * dt/one_year)
+
+             WHERE (veget_max(:,j).GT.min_stomate.AND.ind(:,j).EQ.zero)
+                d_ind(:,j) = ind_0*10.
+                !          elsewhere
+                !d_ind(:,j) =0.0
+             endwhere
+
+          ELSEIF ( natural(j) .AND. .NOT.tree(j)) THEN 
+
+             WHERE (veget_max(:,j).GT.min_stomate)
+
+                fpc_nat(:,j) =  cn_ind(:,j) * ind(:,j) * & 
+                     MAX( ( 1._r_std - exp( - ext_coeff(j) * lai_ind(:) ) ), min_cover )
+
+                d_ind(:,j) = MAX(zero , (1.0-fpc_nat(:,j)) * dt/one_year )
+
+             ENDWHERE
+
+             WHERE (veget_max(:,j).GT.min_stomate.AND.ind(:,j).EQ.zero)
+                d_ind(:,j) = ind_0*10.
+             ENDWHERE
+
+          ENDIF
+
+       ENDDO
+
+    ENDIF ! DGVM OR NOT
+
+    DO j = 2,nvm
+
+       ! only for natural PFTs
+
+       IF ( natural(j) ) THEN
 
           !
@@ -409,12 +538,19 @@
           !
           ! 4.4 be sure that ind*cn_ind does not exceed 1
-          !
-
-          WHERE ( ( d_ind(:,j) .GT. 0.0 ) .AND. &
-               ( (ind(:,j)+d_ind(:,j))*cn_ind(:,j) .GT. 1. ) )
-
-             d_ind(:,j) = MAX( un / cn_ind(:,j) - ind(:,j), zero)
-
-          ENDWHERE
+          !SZ This control is now moved to lpj_cover.f90
+          !SZ
+
+          !The aim is to control for sum(veget)=1., irrespective of ind*cnd (crowns can overlap as long as
+          ! there is enough light
+          !
+          !SZ: This could be part of the dynamic vegetation problem of Orchidee
+          !in conjunction with the wrong formulation of establishment response 
+          !to tree fpc above...
+          !          WHERE ( ( d_ind(:,j) .GT. zero ) .AND. &
+          !                  ( (ind(:,j)+d_ind(:,j))*cn_ind(:,j) .GT. un ) )
+          !
+          !            d_ind(:,j) = MAX( 1._stnd / cn_ind(:,j) - ind(:,j), zero )
+          !
+          !          ENDWHERE
 
           !
@@ -428,51 +564,202 @@
 
           ! compare establishment rate and present number of inidivuals
-          many_new(:) = ( d_ind(:,j) .GT. 0.1 * ind(:,j) )
+          !many_new(:) = ( d_ind(:,j) .GT. 0.1 * ind(:,j) )
 
           ! gives a better vectorization of the VPP
 
-          IF ( ANY( many_new(:) ) ) THEN
-
-             DO k = 1, nparts
-
-                WHERE ( many_new(:) )
-
-                   bm_new(:) = d_ind(:,j) * bm_sapl(j,k) / veget_max (:,j)
-
-                   biomass(:,j,k) = biomass(:,j,k) + bm_new(:)
-
-                   !NV passage 2D
-                   co2_to_bm(:,j) = co2_to_bm(:,j) + bm_new(:) / dt
-
-                ENDWHERE
-
+          !IF ( ANY( many_new(:) ) ) THEN
+
+          ! save old leaf mass to calculate leaf age
+          leaf_mass_young(:) = leaf_frac(:,j,1) * biomass(:,j,ileaf)
+          ! total biomass of existing PFT to limit biomass added from establishment
+          total_bm_c(:) = zero
+
+          DO k = 1, nparts
+             total_bm_c(:)=total_bm_c(:)+biomass(:,j,k)
+          ENDDO
+          IF(control%ok_dgvm) THEN
+             vn(:)=veget_max(:,j)
+          ELSE
+             vn(:)=1.0
+          ENDIF
+          total_bm_sapl(:)=zero
+          DO k = 1, nparts
+             WHERE(d_ind(:,j).GT.min_stomate.AND.vn(:).GT.min_stomate)
+
+                total_bm_sapl(:) = total_bm_sapl(:) + & 
+                     bm_sapl(j,k) * d_ind(:,j) / vn(:)
+             ENDWHERE
+          ENDDO
+
+          IF(control%ok_dgvm) THEN
+             ! SZ calculate new woodmass_ind and veget_max after establishment (needed for correct scaling!)
+             ! essential correction for MERGE!
+             IF(tree(j))THEN
+                DO i=1,npts
+                   IF((d_ind(i,j)+ind(i,j)).GT.min_stomate) THEN
+
+                      IF((total_bm_c(i).LE.min_stomate) .OR. (veget_max(i,j) .LE. min_stomate)) THEN
+
+                         ! new wood mass of PFT
+                         woodmass_ind(i,j) = &
+                              & (((biomass(i,j,isapabove)+biomass(i,j,isapbelow) &
+                              & +biomass(i,j,iheartabove)+biomass(i,j,iheartbelow))*veget_max(i,j)) &
+                              & +(bm_sapl(j,isapabove)+bm_sapl(j,isapbelow) &
+                              & +bm_sapl(j,iheartabove)+bm_sapl(j,iheartbelow))*d_ind(i,j))/(ind(i,j)+d_ind(i,j))
+
+                      ELSE 
+                         ! new biomass is added to the labile pool, hence there is no change in CA associated with establishment
+                         woodmass_ind(i,j) = &
+                              & (biomass(i,j,isapabove)+biomass(i,j,isapbelow) &
+                              & +biomass(i,j,iheartabove)+biomass(i,j,iheartbelow))*veget_max(i,j) &
+                              & /(ind(i,j)+d_ind(i,j))
+
+                      ENDIF
+
+                      ! new diameter of PFT
+                      dia(i) = (woodmass_ind(i,j)/(pipe_density*pi/4.*pipe_tune2)) &
+                           &                **(1./(2.+pipe_tune3))
+
+                      vn(:)=(ind(i,j)+d_ind(i,j))*pipe_tune1*MIN(dia(i),maxdia(j))**pipe_tune_exp_coeff
+
+                   ENDIF
+                ENDDO
+             ELSE ! for grasses, cnd=1, so the above calculation cancels
+                vn(:)=ind(:,j)+d_ind(:,j)
+             ENDIF
+          ELSE ! static
+             DO i=1,npts
+                IF(tree(j).AND.(d_ind(i,j)+ind(i,j)).GT.min_stomate) THEN
+                   IF(total_bm_c(i).LE.min_stomate) THEN
+
+                      ! new wood mass of PFT
+                      woodmass_ind(i,j) = &
+                           & (((biomass(i,j,isapabove)+biomass(i,j,isapbelow) &
+                           & +biomass(i,j,iheartabove)+biomass(i,j,iheartbelow))) &
+                           & +(bm_sapl(j,isapabove)+bm_sapl(j,isapbelow) &
+                           & +bm_sapl(j,iheartabove)+bm_sapl(j,iheartbelow))*d_ind(i,j))/(ind(i,j)+d_ind(i,j))
+
+                   ELSE ! new biomass is added to the labile pool, hence there is no change in CA associated with establishment
+
+                      woodmass_ind(i,j) = &
+                           & (biomass(i,j,isapabove)+biomass(i,j,isapbelow) &
+                           & +biomass(i,j,iheartabove)+biomass(i,j,iheartbelow)) &
+                           & /(ind(i,j)+d_ind(i,j))
+
+                   ENDIF
+                ENDIF
              ENDDO
 
-             ! reset leaf ages. Should do a real calculation like in the npp routine, 
-             ! but this case is rare and not worth messing around.
-
-             WHERE ( many_new(:) )
-                leaf_age(:,j,1) = 0.0
-                leaf_frac(:,j,1) = 1.0
-             ENDWHERE
-
-             DO m = 2, nleafages
-
-                WHERE ( many_new(:) )
-                   leaf_age(:,j,m) = 0.0
-                   leaf_frac(:,j,m) = 0.0
-                ENDWHERE
-
-             ENDDO
-
-          ENDIF   ! establishment rate is large
-
-          WHERE ( d_ind(:,j) .GT. 0.0 )
-
-             ! 4.5.2 age decreases
+             vn(:)=1.0 ! cannot change in static!, and veget_max implicit in d_ind
+
+          ENDIF
+          ! total biomass of PFT added by establishment defined over veget_max ...
+          total_bm_sapl(:)=zero
+          DO k = 1, nparts
+             WHERE(d_ind(:,j).GT.min_stomate.AND.total_bm_c(:).GT.min_stomate.AND.vn(:).GT.min_stomate)
+
+                total_bm_sapl(:) = total_bm_sapl(:) + & 
+                     bm_sapl(j,k) * d_ind(:,j) / vn(:)
+             ENDWHERE
+
+          ENDDO
+
+          DO k = 1, nparts
+
+             bm_new(:)=zero
+
+             ! first ever establishment, C flows
+             WHERE( d_ind(:,j).GT.min_stomate .AND. &
+                  total_bm_c(:).LE.min_stomate .AND. &
+                  vn(:).GT.min_stomate)
+                ! WHERE ( many_new(:) )
+
+                !bm_new(:) = d_ind(:,j) * bm_sapl(j,k) / veget_max (:,j)
+                bm_new(:) = d_ind(:,j) * bm_sapl(j,k) / vn(:)
+
+                biomass(:,j,k) = biomass(:,j,k) + bm_new(:)
+
+                co2_to_bm(:,j) = co2_to_bm(:,j) + bm_new(:) / dt
+
+             ENDWHERE
+
+             ! establishment into existing population, C flows
+             WHERE(d_ind(:,j).GT.min_stomate.AND.total_bm_c(:).GT.min_stomate)
+
+                bm_new(:) = total_bm_sapl(:) * biomass(:,j,k) / total_bm_c(:)
+
+                biomass(:,j,k) = biomass(:,j,k) + bm_new(:)
+                co2_to_bm(:,j) = co2_to_bm(:,j) + bm_new(:) / dt
+
+             ENDWHERE
+          ENDDO
+
+          ! reset leaf ages. Should do a real calculation like in the npp routine, 
+          ! but this case is rare and not worth messing around.
+          ! SZ 080806, added real calculation now, because otherwise leaf_age/leaf_frac
+          ! are not initialised for the calculation of vmax, and hence no growth at all.
+          ! logic follows that of stomate_npp.f90, just that it's been adjusted for the code here
+          !
+          ! 4.5.2 Decrease leaf age in youngest class if new leaf biomass is higher than old one.
+          !
+
+!!$          WHERE ( many_new(:) )
+!!$             leaf_age(:,j,1) = zero
+!!$             leaf_frac(:,j,1) = un
+!!$          ENDWHERE
+!!$
+!!$          DO m = 2, nleafages
+!!$
+!!$             WHERE ( many_new(:) )
+!!$                leaf_age(:,j,m) = zero
+!!$                leaf_frac(:,j,m) = zero
+!!$             ENDWHERE
+!!$
+!!$          ENDDO
+
+          WHERE ( d_ind(:,j) * bm_sapl(j,ileaf) .GT. min_stomate ) 
+
+             leaf_age(:,j,1) = leaf_age(:,j,1) * leaf_mass_young(:) / &
+                  ( leaf_mass_young(:) + d_ind(:,j) * bm_sapl(j,ileaf) )
+
+          ENDWHERE
+
+          !
+          leaf_mass_young(:) = leaf_mass_young(:) + d_ind(:,j) * bm_sapl(j,ileaf)
+
+          !
+          ! new age class fractions (fraction in youngest class increases)
+          !
+
+          ! youngest class: new mass in youngest class divided by total new mass
+
+          WHERE ( biomass(:,j,ileaf) .GT. min_stomate )
+
+             leaf_frac(:,j,1) = leaf_mass_young(:) / biomass(:,j,ileaf)
+
+          ENDWHERE
+
+          ! other classes: old mass in leaf age class divided by new mass
+
+          DO m = 2, nleafages
+
+             WHERE ( biomass(:,j,ileaf) .GT. min_stomate )
+
+                leaf_frac(:,j,m) = leaf_frac(:,j,m) * & 
+                     ( biomass(:,j,ileaf) + d_ind(:,j) * bm_sapl(j,ileaf) ) /  biomass(:,j,ileaf)
+          
+             ENDWHERE
+
+          ENDDO
+
+          !ENDIF   ! establishment rate is large
+
+          WHERE ( d_ind(:,j) .GT. min_stomate )
+
+             ! 4.5.3 age decreases
 
              age(:,j) = age(:,j) * ind(:,j) / ( ind(:,j) + d_ind(:,j) )
 
-             ! 4.5.3 new number of individuals
+             ! 4.5.4 new number of individuals
 
              ind(:,j) = ind(:,j) + d_ind(:,j)
@@ -484,31 +771,39 @@
           !
 
+          !SZ to clarify with Gerhard Krinner: This is theoretically inconsistent because 
+          ! the allocation to sapwood and leaves do not follow the LPJ logic in stomate_alloc.f90
+          ! hence imposing this here not only solves for the uneveness of age (mixing new and average individual)
+          ! but also corrects for the discrepancy between SLAVE and LPJ logic of allocation, thus leads to excess heartwood
+          ! and thus carbon accumulation!
+          ! should be removed.
+
           IF ( tree(j) ) THEN
 
-             sm2(:) = 0.0
-
-             WHERE ( d_ind(:,j) .GT. 0.0 ) 
-
-                ! ratio of above / total sap parts
-                sm_at(:) = biomass(:,j,isapabove) / &
-                     ( biomass(:,j,isapabove) + biomass(:,j,isapbelow) )
-
-                ! woodmass of an individual
-
-                woodmass(:) = &
-                     ( biomass(:,j,isapabove) + biomass(:,j,isapbelow) + &
-                     biomass(:,j,iheartabove) + biomass(:,j,iheartbelow) ) / ind(:,j)
-
-                ! crown area (m**2) depends on stem diameter (pipe model)
-                dia(:) = ( woodmass(:) / ( pipe_density * pi/4. * pipe_tune2 ) ) &
-                     ** ( 1. / ( 2. + pipe_tune3 ) )
-
-                b1(:) = pipe_k1 / ( sla(j) * pipe_density*pipe_tune2 * dia(:)**pipe_tune3 ) * &
-                     ind(:,j)
-                sm2(:) = lm_lastyearmax(:,j) / b1(:)
-
-             ENDWHERE
-
-             WHERE ( ( d_ind(:,j) .GT. 0.0 ) .AND. &
+!!$             sm2(:) = 0.0
+!!$             WHERE ( d_ind(:,j) .GT. 0.0 ) 
+!!$
+!!$                ! ratio of above / total sap parts
+!!$                sm_at(:) = biomass(:,j,isapabove) / &
+!!$                     ( biomass(:,j,isapabove) + biomass(:,j,isapbelow) )
+!!$
+!!$                ! woodmass of an individual
+!!$
+!!$                woodmass(:) = &
+!!$                     ( biomass(:,j,isapabove) + biomass(:,j,isapbelow) + &
+!!$                     biomass(:,j,iheartabove) + biomass(:,j,iheartbelow) ) / ind(:,j)
+!!$
+!!$                ! crown area (m**2) depends on stem diameter (pipe model)
+!!$                dia(:) = ( woodmass(:) / ( pipe_density * pi/4. * pipe_tune2 ) ) &
+!!$                     ** ( 1. / ( 2. + pipe_tune3 ) )
+!!$
+!!$                b1(:) = pipe_k1 / ( sla(j) * pipe_density*pipe_tune2 * dia(:)**pipe_tune3 ) * &
+!!$                     ind(:,j)
+!!$                sm2(:) = lm_lastyearmax(:,j) / b1(:)
+!!$
+!!$             ENDWHERE
+
+             sm2(:)=biomass(:,j,isapabove) + biomass(:,j,isapbelow)
+
+             WHERE ( ( d_ind(:,j) .GT. min_stomate ) .AND. &
                   ( biomass(:,j,isapabove) + biomass(:,j,isapbelow) ) .GT. sm2(:) )
 
@@ -518,6 +813,6 @@
 
                 biomass(:,j,iheartbelow) = biomass(:,j,iheartbelow) + &
-                     ( biomass(:,j,isapbelow) - sm2(:) * (1. - sm_at) )
-                biomass(:,j,isapbelow) = sm2(:) * (1. - sm_at(:))
+                     ( biomass(:,j,isapbelow) - sm2(:) * (un - sm_at) )
+                biomass(:,j,isapbelow) = sm2(:) * (un - sm_at(:))
 
              ENDWHERE
@@ -536,4 +831,6 @@
 
     CALL histwrite (hist_id_stomate, 'IND_ESTAB', itime, d_ind, npts*nvm, horipft_index)
+    CALL histwrite (hist_id_stomate, 'ESTABTREE', itime, estab_rate_max_tree, npts, hori_index)
+    CALL histwrite (hist_id_stomate, 'ESTABGRASS', itime, estab_rate_max_grass, npts, hori_index)
 
     IF (bavard.GE.4) WRITE(numout,*) 'Leaving establish'
Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/lpj_fire.f90
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/lpj_fire.f90	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/lpj_fire.f90	(revision 257)
@@ -99,5 +99,4 @@
     !MM Shilong ??
 !!$    REAL(r_std), PARAMETER                                           :: tau_fire = 365.  ! GKtest
-
     ! fire perturbation
     REAL(r_std), DIMENSION(npts)                                     :: fire_disturb
@@ -273,5 +272,5 @@
        IF(.NOT.disable_fire.AND.natural(j))THEN
           WHERE ( aff(:) .GT. 0.1 )
-             firefrac(:,j) = 1. - ( 1. - aff(:) ) ** (dt/one_year)
+             firefrac(:,j) = un - ( un - aff(:) ) ** (dt/one_year)
           ELSEWHERE
              firefrac(:,j) = aff(:) * dt/one_year
@@ -315,5 +314,5 @@
           ! 4.2.1 Trees: always disturbed
 
-          fire_disturb(:) = ( 1. - resist(j) ) * firefrac(:,j)
+          fire_disturb(:) = ( un - resist(j) ) * firefrac(:,j)
 
        ELSE
@@ -323,5 +322,5 @@
           WHERE ( biomass(:,j,ileaf) .GT. min_stomate )
 
-             fire_disturb(:) = ( 1. - resist(j) ) * firefrac(:,j)
+             fire_disturb(:) = ( un - resist(j) ) * firefrac(:,j)
 
           ELSEWHERE
@@ -353,6 +352,6 @@
              ! 4.3.2 Determine the residue, in gC/m**2 of ground.
 
-             residue(:) = biomass(:,j,k) * fire_disturb(:) * ( 1. - co2frac(k) )
-             !MM in SZ ???        residue(:) = fire_disturb(:) * ( 1. - co2frac(k) )
+             residue(:) = biomass(:,j,k) * fire_disturb(:) * ( un - co2frac(k) )
+             !MM in SZ ???        residue(:) = fire_disturb(:) * ( un - co2frac(k) )
 
              ! 4.3.2.1 determine fraction of black carbon. Only for plant parts above the
@@ -400,5 +399,5 @@
           IF ( .NOT. ( ( .NOT. tree(j) ) .AND. ( ( k.EQ.iroot ) .OR. ( k.EQ.icarbres) ) ) ) THEN
 
-             biomass(:,j,k) = ( 1. - fire_disturb(:) ) * biomass(:,j,k)
+             biomass(:,j,k) = ( un - fire_disturb(:) ) * biomass(:,j,k)
 
           ENDIF
@@ -409,5 +408,5 @@
        !       individuals.
 
-       IF ( control%ok_dgvm .AND. tree(j) ) THEN
+       IF ( (control%ok_dgvm .OR. .NOT.lpj_gap_const_mort) .AND. tree(j) ) THEN
 
           ! fraction of plants that dies each day.
@@ -415,5 +414,5 @@
           firedeath(:,j) = fire_disturb(:) / dt
 
-          ind(:,j) = ( 1. - fire_disturb(:) ) * ind(:,j)
+          ind(:,j) = ( un - fire_disturb(:) ) * ind(:,j)
 
        ENDIF
@@ -440,5 +439,5 @@
 
        litter(:,imetabolic,j,iabove) = litter(:,imetabolic,j,iabove) * &
-            ( 1. - firefrac(:,j) )
+            ( un - firefrac(:,j) )
 
        !
@@ -455,11 +454,20 @@
        co2_fire(:,j) = co2_fire(:,j) + &
             litter(:,istructural,j,iabove) * firefrac(:,j) * &
-            ( 1. - struc_residual(:) )/ dt
+            ( un - struc_residual(:) )/ dt
 
        ! 5.2.3 determine residue (litter that undergoes fire, but is not transformed
        !       into CO2)
 
-       residue(:) = litter(:,istructural,j,iabove) * firefrac(:,j) * &
-            struc_residual(:)
+!NV,MM : We add this test to keep coherence with CMIP5 computations without DGVM.
+!        It has to be removed in trunk version after CMIP5.
+       IF (control%ok_dgvm .OR. .NOT.lpj_gap_const_mort) THEN
+          residue(:) = firefrac(:,j) * struc_residual(:)
+       ELSE
+          residue(:) = litter(:,istructural,j,iabove) * firefrac(:,j) * &
+               struc_residual(:)
+       ENDIF
+
+!       residue(:) = litter(:,istructural,j,iabove) * firefrac(:,j) * &
+!            struc_residual(:)
        !MM in SZ        residue(:) = firefrac(:,j) * struc_residual(:)
 
@@ -482,7 +490,7 @@
 
        litter(:,istructural,j,iabove) = &
-            litter(:,istructural,j,iabove) * ( 1. - firefrac(:,j) ) + &
-            residue(:) * ( 1. - bcfrac(:) )
-       !MM in SZ            residue(:) * ( 1. - bcfrac(:) ) * litter(:,iwoody,j,iabove)
+            litter(:,istructural,j,iabove) * ( un - firefrac(:,j) ) + &
+            residue(:) * ( un - bcfrac(:) )
+       !MM in SZ            residue(:) * ( un - bcfrac(:) ) * litter(:,iwoody,j,iabove)
 
     ENDDO  !  ground
@@ -496,5 +504,5 @@
 
        DO k = 1, nlitt
-          dead_leaves(:,j,k) = dead_leaves(:,j,k) * ( 1. - firefrac(:,j) )
+          dead_leaves(:,j,k) = dead_leaves(:,j,k) * ( un - firefrac(:,j) )
        ENDDO
 
@@ -543,8 +551,6 @@
 
     firefrac_result(:) = &
-!         x(:) * EXP( xm1(:) / ( -.13*xm1(:)*xm1(:)*xm1(:) + .6*xm1(:)*xm1(:) + .8*xm1(:) + .45 ) )
          x(:) * EXP( xm1(:) / ( -firefrac_coeff(4)*xm1(:)*xm1(:)*xm1(:) + firefrac_coeff(3)*xm1(:)*xm1(:) + firefrac_coeff(2)*xm1(:) + firefrac_coeff(1) ) )
 
-
   END FUNCTION firefrac_func
 
Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/lpj_gap.f90
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/lpj_gap.f90	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/lpj_gap.f90	(revision 257)
@@ -39,5 +39,5 @@
   SUBROUTINE gap (npts, dt, &
        npp_longterm, turnover_longterm, lm_lastyearmax, &
-       PFTpresent, biomass, ind, bm_to_litter)
+       PFTpresent, biomass, ind, bm_to_litter, mortality)
 
     !
@@ -68,19 +68,20 @@
     ! biomass taken away (gC/(m**2 of ground))
     REAL(r_std), DIMENSION(npts,nvm,nparts), INTENT(inout)  :: bm_to_litter
+    ! mortality (fraction of trees that is dying per time step), per day in history file
+    REAL(r_std), DIMENSION(npts,nvm),INTENT(out)             :: mortality
 
     ! 0.3 local
 
-    ! which kind of mortality
-    LOGICAL, SAVE                                           :: constant_mortality
     ! biomass increase
     REAL(r_std), DIMENSION(npts)                             :: delta_biomass
+    ! biomass increase
+    REAL(r_std), DIMENSION(npts)                             :: dmortality
     ! vigour
     REAL(r_std), DIMENSION(npts)                             :: vigour
     ! natural availability, based on vigour
     REAL(r_std), DIMENSION(npts)                             :: availability
-    ! mortality (fraction of trees that is dying per time step), per day in history file
-    REAL(r_std), DIMENSION(npts,nvm)                        :: mortality
     ! indices
-    INTEGER(i_std)                                           :: j,k
+    INTEGER(i_std)                                           :: j,k,m
+    REAL(r_std) :: ref_greff
 
     ! =========================================================================
@@ -90,21 +91,12 @@
        firstcall = .FALSE.
 
-       !Config  Key  = LPJ_GAP_CONST_MORT
-       !Config  Desc = constant tree mortality
-       !Config  Def  = y
-       !Config  Help = If yes, then a constant mortality is applied to trees. 
-       !Config         Otherwise, mortality is a function of the trees' 
-       !Config         vigour (as in LPJ).
-
-       constant_mortality = .TRUE.
-       CALL getin_p('LPJ_GAP_CONST_MORT', constant_mortality)     
-       WRITE(numout,*) 'gap: constant mortality:', constant_mortality
-
     ENDIF
 
-    IF (bavard.GE.3) WRITE(numout,*) 'Entering gap'
+    IF (bavard.GE.3) WRITE(numout,*) 'Entering gap',lpj_gap_const_mort
 
     mortality(:,:) = zero
 
+    ref_greff =  0.035
+
     DO j = 2,nvm
 
@@ -117,5 +109,5 @@
           !
 
-          IF ( .NOT. constant_mortality ) THEN
+          IF ( .NOT.  lpj_gap_const_mort  ) THEN
 
              !
@@ -125,14 +117,22 @@
              WHERE ( PFTpresent(:,j) .AND. ( lm_lastyearmax(:,j) .GT. min_stomate ) )
 
+!SZ 080806, changed to LPJ formulation according to Smith et al., 2001 
+
                 ! how much did the tree grow per year?
 
-                delta_biomass(:) = &
-                     MAX( npp_longterm(:,j) - ( turnover_longterm(:,j,ileaf) + &
-                     turnover_longterm(:,j,iroot) + turnover_longterm(:,j,ifruit) ), &
-                     zero )
+!!$                delta_biomass(:) = &
+!!$                     MAX( npp_longterm(:,j) - ( turnover_longterm(:,j,ileaf) + &
+!!$                     turnover_longterm(:,j,iroot) + turnover_longterm(:,j,ifruit) ), &
+!!$                     0._r_std )
+
+            ! note that npp_longterm is now actually longterm growth efficiency (NPP/LAI)
+            ! to be fair to deciduous trees
+             delta_biomass(:) = MAX( npp_longterm(:,j) - ( turnover_longterm(:,j,ileaf) + &
+                  turnover_longterm(:,j,iroot) + turnover_longterm(:,j,ifruit) + & 
+                  turnover_longterm(:,j,isapabove) + turnover_longterm(:,j,isapbelow) ) ,zero)
 
                 ! scale this to the leaf surface of the tree
-
-                vigour(:) = delta_biomass(:) / (lm_lastyearmax(:,j)*sla(j)) / vigour_coeff
+!!$                vigour(:) = delta_biomass(:) / (lm_lastyearmax(:,j)*sla(j)) / vigour_coeff
+             vigour(:) = delta_biomass(:) / (lm_lastyearmax(:,j)*sla(j))
 
              ELSEWHERE
@@ -147,5 +147,9 @@
                 ! low vigour.
 
-                availability(:) = availability_fact / ( 1.+vigour(:)/vigour_ref)
+!SZ 080806, changed to LPJ formulation according to Smith et al., 2001 
+! tuned maximal mortality to 0.05 to get realistic range of avergage age to get ~100 years at GREFF=100
+! for the range of modelled annual NPP
+!!$                availability(:) = min_avail / ( 1.+vigour(:)/vigour_ref )
+                availability(:) = 0.1 / ( 1.+ref_greff*vigour(:) )
 
                 ! Mortality (fraction per time step).
@@ -158,5 +162,6 @@
                 ! approximation ok as availability < 0.02 << 1
 
-                mortality(:,j) = availability(:) * dt/one_year
+                mortality(:,j) = MAX(min_avail,availability(:))  * dt/one_year  
+!!$                mortality(:,j) = availability(:) * dt/one_year
 
              ENDWHERE
@@ -199,7 +204,8 @@
              WHERE ( PFTpresent(:,j) )
 
-                bm_to_litter(:,j,k) = bm_to_litter(:,j,k) + mortality(:,j) * biomass(:,j,k)
-
-                biomass(:,j,k) = biomass(:,j,k) * ( 1. - mortality(:,j) )
+                dmortality(:) =  mortality(:,j) * biomass(:,j,k)
+                bm_to_litter(:,j,k) = bm_to_litter(:,j,k) + dmortality(:)
+                
+                biomass(:,j,k) = biomass(:,j,k) - dmortality(:)
 
              ENDWHERE
@@ -211,12 +217,37 @@
           !
 
-          IF ( control%ok_dgvm ) THEN
-
-             WHERE ( PFTpresent(:,j) )
-
-                ind(:,j) = ind(:,j) * ( 1. - mortality(:,j) )
-
-             ENDWHERE
-
+!SZ 080806, allow changing density in static case when mortality is dynamic
+          IF ( control%ok_dgvm .OR. .NOT.lpj_gap_const_mort) THEN
+
+             WHERE ( PFTpresent(:,j) )
+
+                ind(:,j) = ind(:,j) * ( un - mortality(:,j) )
+
+             ENDWHERE
+
+          ENDIF
+
+       ELSE 
+
+          IF ( .NOT.control%ok_dgvm .AND. .NOT.lpj_gap_const_mort) THEN
+
+             WHERE ( PFTpresent(:,j) .AND. ( npp_longterm(:,j) .LE. 10. ) )
+
+                mortality(:,j) = 1.
+
+             ENDWHERE
+             DO k = 1, nparts
+
+                WHERE ( PFTpresent(:,j) )
+
+                   dmortality(:) =  mortality(:,j) * biomass(:,j,k)
+                   
+                   bm_to_litter(:,j,k) = bm_to_litter(:,j,k) + dmortality(:)
+                   
+                   biomass(:,j,k) = biomass(:,j,k) - dmortality(:)
+
+                ENDWHERE
+             ENDDO
+             
           ENDIF
 
Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/lpj_kill.f90
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/lpj_kill.f90	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/lpj_kill.f90	(revision 257)
@@ -25,5 +25,5 @@
   SUBROUTINE kill (npts, whichroutine, lm_lastyearmax, &
        ind, PFTpresent, cn_ind, biomass, senescence, RIP_time, &
-       lai, age, leaf_age, leaf_frac, &
+       lai, age, leaf_age, leaf_frac, npp_longterm, &
        when_growthinit, everywhere, veget, veget_max, bm_to_litter)
 
@@ -37,5 +37,5 @@
     INTEGER(i_std), INTENT(in)                                       :: npts
     ! message
-    CHARACTER*10, INTENT(in)                                  :: whichroutine
+    CHARACTER(LEN=10), INTENT(in)                                  :: whichroutine
     ! last year's maximum leaf mass, for each PFT (gC/(m**2 of ground))
     REAL(r_std), DIMENSION(npts,nvm), INTENT(in)              :: lm_lastyearmax
@@ -72,4 +72,6 @@
     ! "maximal" coverage fraction of a PFT (LAI -> infinity) on ground
     REAL(r_std), DIMENSION(npts,nvm), INTENT(inout)           :: veget_max
+    ! "long term" net primary productivity (gC/(m**2 of ground)/year)
+    REAL(r_std), DIMENSION(npts,nvm), INTENT(inout)           :: npp_longterm 
     ! conversion of biomass to litter (gC/(m**2 of ground)) / day
     REAL(r_std), DIMENSION(npts,nvm,nparts), INTENT(inout)    :: bm_to_litter
@@ -98,17 +100,36 @@
           ! the "was_killed" business is necessary for a more efficient code on the VPP
 
-          WHERE ( PFTpresent(:,j) .AND. &
-               ( ( ind(:,j) .LT. min_stomate ) .OR. &
-               ( lm_lastyearmax(:,j) .LT. min_stomate ) ) )
-
+          IF ( control%ok_dgvm ) THEN
+             WHERE ( PFTpresent(:,j) .AND. &
+                  ( ( ind(:,j) .LT. min_stomate ) .OR. &
+                  ( lm_lastyearmax(:,j) .LT. min_stomate ) ) )
+             
              was_killed(:) = .TRUE.
-
-          ENDWHERE
+             
+             ENDWHERE
+          
+          ELSE
+             WHERE ( PFTpresent(:,j) .AND. & 
+                  (biomass(:,j,icarbres) .LE.zero .OR. & 
+                  biomass(:,j,iroot).LT.-min_stomate .OR. biomass(:,j,ileaf).LT.-min_stomate ).AND. & 
+                  ind(:,j).GT. zero)
+
+                was_killed(:) = .TRUE.
+
+             ENDWHERE
+
+             IF(.NOT.tree(j).AND..NOT.lpj_gap_const_mort)THEN
+                WHERE ( was_killed(:) )
+
+                   npp_longterm(:,j)=500.
+
+                ENDWHERE
+             ENDIF
+
+          ENDIF
 
           IF ( ANY( was_killed(:) ) ) THEN
 
              WHERE ( was_killed(:) )
-
-                ind(:,j) = 0.0
 
                 bm_to_litter(:,j,ileaf) = bm_to_litter(:,j,ileaf) + biomass(:,j,ileaf)
@@ -123,31 +144,45 @@
                 bm_to_litter(:,j,icarbres) = bm_to_litter(:,j,icarbres) + biomass(:,j,icarbres)
 
-                biomass(:,j,ileaf) = 0.0
-                biomass(:,j,isapabove) = 0.0
-                biomass(:,j,isapbelow) = 0.0
-                biomass(:,j,iheartabove) = 0.0
-                biomass(:,j,iheartbelow) = 0.0
-                biomass(:,j,iroot) = 0.0
-                biomass(:,j,ifruit) = 0.0
-                biomass(:,j,icarbres) = 0.0
-
-                PFTpresent(:,j) = .FALSE.
-
-                cn_ind(:,j) = 0.0
+                biomass(:,j,ileaf) = zero
+                biomass(:,j,isapabove) = zero
+                biomass(:,j,isapbelow) = zero
+                biomass(:,j,iheartabove) = zero
+                biomass(:,j,iheartbelow) = zero
+                biomass(:,j,iroot) = zero
+                biomass(:,j,ifruit) = zero
+                biomass(:,j,icarbres) = zero
+
+             ENDWHERE   ! number of individuals very low
+
+             IF (control%ok_dgvm) THEN
+
+                WHERE ( was_killed(:) )
+                   PFTpresent(:,j) = .FALSE.
+
+                   veget_max(:,j) = zero
+                   
+                   RIP_time(:,j) = zero
+
+                ENDWHERE  ! number of individuals very low
+
+             ENDIF
+
+             WHERE ( was_killed(:) )
+
+                ind(:,j) = zero
+
+                cn_ind(:,j) = zero
 
                 senescence(:,j) = .FALSE.
 
-
-                age(:,j) = 0.0
-
-                when_growthinit(:,j) = undef
-
-                everywhere(:,j) = 0.0
-
-                veget(:,j) = 0.0
-
-                veget_max(:,j) = 0.0
-
-                RIP_time(:,j) = 0.0
+                age(:,j) = zero
+
+                ! SZ: why undef ??? this causes a delay in reestablishment
+                !when_growthinit(:,j) = undef
+                when_growthinit(:,j) = large_value 
+
+                everywhere(:,j) = zero
+
+                veget(:,j) = zero
 
              ENDWHERE   ! number of individuals very low
@@ -157,6 +192,6 @@
                 WHERE ( was_killed(:) )
 
-                   leaf_age(:,j,m) = 0.0 
-                   leaf_frac(:,j,m) = 0.0 
+                   leaf_age(:,j,m) = zero 
+                   leaf_frac(:,j,m) = zero 
 
                 ENDWHERE
Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/lpj_light.f90
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/lpj_light.f90	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/lpj_light.f90	(revision 257)
@@ -14,4 +14,15 @@
 ! Exclude agricultural pfts from competition
 !
+! SZ: added light competition for the static case if the mortality is not 
+!     assumed to be constant.
+! other modifs:
+! -1      FPC is now always calculated from lm_lastyearmax*sla, since the aim of this DGVM is 
+!         to represent community ecology effects; seasonal variations in establishment related to phenology
+!         may be relevant, but beyond the scope of a 1st generation DGVM 
+! -2      problem, if agriculture is present, fpc can never reach 1.0 since natural veget_max < 1.0. To
+!         correct for this, ind must be recalculated to correspond to the natural density...
+!         since ind is 1/m2 grid cell, this can be achived by dividing ind by the agricultural fraction
+
+!
 ! $Header: /home/ssipsl/CVSREP/ORCHIDEE/src_stomate/lpj_light.f90,v 1.8 2009/01/06 15:01:25 ssipsl Exp $
 ! IPSL (2006)
@@ -43,6 +54,6 @@
 
   SUBROUTINE light (npts, dt, &
-       PFTpresent, cn_ind, lai, maxfpc_lastyear, &
-       ind, biomass, veget_lastlight, bm_to_litter)
+       veget_max, fpc_max, PFTpresent, cn_ind, lai, maxfpc_lastyear, &
+       lm_lastyearmax, ind, biomass, veget_lastlight, bm_to_litter, mortality)
 
     !
@@ -64,4 +75,10 @@
     ! last year's maximum fpc for each natural PFT, on ground
     REAL(r_std), DIMENSION(npts,nvm), INTENT(in)             :: maxfpc_lastyear
+    ! last year's maximum leafmass for each natural PFT, on ground
+    REAL(r_std), DIMENSION(npts,nvm), INTENT(in)             :: lm_lastyearmax
+    ! last year's maximum fpc for each natural PFT, on ground
+    REAL(r_std), DIMENSION(npts,nvm), INTENT(in)             :: veget_max
+    ! last year's maximum fpc for each natural PFT, on ground
+    REAL(r_std), DIMENSION(npts,nvm), INTENT(in)             :: fpc_max
 
     ! 0.2 modified fields
@@ -75,11 +92,15 @@
     ! biomass taken away (gC/m**2)
     REAL(r_std), DIMENSION(npts,nvm,nparts), INTENT(inout)   :: bm_to_litter
+    ! fraction of individuals that died this time step
+    REAL(r_std), DIMENSION(npts,nvm), INTENT(inout)          :: mortality
 
     ! 0.3 local
 
     ! index
-    INTEGER(i_std)                                            :: i,j
+    INTEGER(i_std)                                            :: i,j,k,m
     ! total natural fpc
     REAL(r_std), DIMENSION(npts)                              :: sumfpc
+    ! fraction of natural vegetation at grid cell level
+    REAL(r_std), DIMENSION(npts)                              :: fracnat
     ! total natural woody fpc
     REAL(r_std)                                               :: sumfpc_wood
@@ -100,10 +121,16 @@
     ! Fraction of plants that survive
     REAL(r_std), DIMENSION(nvm)                              :: survive
+    ! FPC for static mode
+    REAL(r_std), DIMENSION(npts)                              :: fpc_real
+    ! FPC mortality for static mode
+    REAL(r_std), DIMENSION(npts)                              :: lai_ind
     ! number of grass PFTs present in the grid box
-    INTEGER(i_std)                                            :: num_grass
+!    INTEGER(i_std)                                            :: num_grass
     ! New total grass fpc
     REAL(r_std)                                               :: sumfpc_grass2
     ! fraction of plants that dies each day (1/day)
     REAL(r_std), DIMENSION(npts,nvm)                         :: light_death
+    ! Relative change of number of individuals for trees
+    REAL(r_std)                                               :: fpc_dec
 
     ! =========================================================================
@@ -139,376 +166,461 @@
     ENDIF
 
-    !
-    ! 2 fpc characteristics
-    !
-
-    !
-    ! 2.1 calculate fpc on natural part of grid cell.
-    !
-
-    DO j = 2, nvm
-
-       IF ( natural(j) ) THEN
-
-          ! 2.1.1 natural PFTs
-
-          IF ( tree(j) ) THEN
-
-             ! 2.1.1.1 trees: minimum cover due to stems, branches etc.
-
-             DO i = 1, npts
-                IF (lai(i,j) == val_exp) THEN
-                   fpc_nat(i,j) = cn_ind(i,j) * ind(i,j)
-                ELSE
-                   fpc_nat(i,j) = cn_ind(i,j) * ind(i,j) * &
-                        MAX( ( un - exp( -lai(i,j) * ext_coeff(j) ) ), min_cover )
-                ENDIF
-             ENDDO
+    IF (control%ok_dgvm) THEN
+       !
+       ! 2 fpc characteristics
+       !
+
+       ! 2.0 Only natural part of the grid cell:
+       ! calculate fraction of natural and agricultural (1-fracnat) surface
+
+       fracnat(:) = 1.
+       DO j = 2,nvm
+          IF ( .NOT. natural(j) ) THEN
+             fracnat(:) = fracnat(:) - veget_max(:,j)
+          ENDIF
+       ENDDO
+       !
+       ! 2.1 calculate fpc on natural part of grid cell.
+       !
+       fpc_nat(:,:)=zero
+       fpc_nat(:,ibare_sechiba)=un
+
+       DO j = 2, nvm
+
+          IF ( natural(j) ) THEN
+
+             ! 2.1.1 natural PFTs
+
+             IF ( tree(j) ) THEN
+
+                ! 2.1.1.1 trees: minimum cover due to stems, branches etc.
+
+                !          DO i = 1, npts
+                !             IF (lai(i,j) == val_exp) THEN
+                !                fpc_nat(i,j) = cn_ind(i,j) * ind(i,j)
+                !             ELSE
+                !                fpc_nat(i,j) = cn_ind(i,j) * ind(i,j) * &
+                !                     MAX( ( 1._r_std - exp( -lai(i,j) * ext_coeff(j) ) ), min_cover )
+                !             ENDIF
+                !          ENDDO
+
+                !NV : modif from SZ version : fpc is based on veget_max, not veget.
+                WHERE(fracnat(:).GE.min_stomate)
+                   !            WHERE(LAI(:,j) == val_exp)
+                   !               fpc_nat(:,j) = cn_ind(:,j) * ind(:,j) / fracnat(:)
+                   !            ELSEWHERE
+                   !               fpc_nat(:,j) = cn_ind(:,j) * ind(:,j) / fracnat(:) * &
+                   !                    MAX( ( 1._r_std - exp( - lm_lastyearmax(:,j) * sla(j) * ext_coeff(j) ) ), min_cover )
+                   !            ENDWHERE
+                   fpc_nat(:,j) = cn_ind(:,j) * ind(:,j) / fracnat(:)
+                ENDWHERE
+
+             ELSE
+
+                !NV : modif from SZ version : fpc is based on veget_max, not veget.
+                WHERE(fracnat(:).GE.min_stomate)
+                   !            WHERE(LAI(:,j) == val_exp)
+                   !               fpc_nat(:,j) = cn_ind(:,j) * ind(:,j) / fracnat(:)
+                   !            ELSEWHERE
+                   !               fpc_nat(:,j) = cn_ind(:,j) * ind(:,j) / fracnat(:) * &
+                   !                    ( 1._r_std - exp( - lm_lastyearmax(:,j) * sla(j) * ext_coeff(j) ) )
+                   !            ENDWHERE
+                   fpc_nat(:,j) = cn_ind(:,j) * ind(:,j) / fracnat(:)
+                ENDWHERE
+
+!!$                ! 2.1.1.2 bare ground 
+!!$                IF (j == ibare_sechiba) THEN
+!!$                   fpc_nat(:,j) = cn_ind(:,j) * ind(:,j) 
+!!$
+!!$                   ! 2.1.1.3 grasses
+!!$                ELSE
+!!$                   DO i = 1, npts
+!!$                      IF (lai(i,j) == val_exp) THEN
+!!$                         fpc_nat(i,j) = cn_ind(i,j) * ind(i,j)
+!!$                      ELSE
+!!$                         fpc_nat(i,j) = cn_ind(i,j) * ind(i,j) * &
+!!$                              ( 1._r_std - exp( -lai(i,j) * ext_coeff(j) ) )
+!!$                      ENDIF
+!!$                   ENDDO
+!!$                ENDIF
+
+             ENDIF  ! tree/grass
 
           ELSE
 
-             ! 2.1.1.2 bare ground 
-             IF (j == ibare_sechiba) THEN
-                fpc_nat(:,j) = cn_ind(:,j) * ind(:,j) 
-
-                ! 2.1.1.3 grasses
+             ! 2.1.2 agricultural PFTs: not present on natural part
+
+             fpc_nat(:,j) = zero
+
+          ENDIF    ! natural/agricultural
+
+       ENDDO
+       
+       !
+       ! 2.2 sum natural fpc for every grid point
+       !
+
+       sumfpc(:) = zero
+       DO j = 2,nvm
+          !SZ bug correction MERGE: need to subtract agricultural area!
+          sumfpc(:) = sumfpc(:) + fpc_nat(:,j)
+       ENDDO
+       
+       !
+       ! 3 Light competition
+       !
+       
+       light_death(:,:) = zero
+
+       DO i = 1, npts ! SZ why this loop and not a vector statement ?
+          
+          ! Only if vegetation cover is dense
+          
+          IF ( sumfpc(i) .GT. fpc_crit ) THEN
+             
+             ! fpc change for each pft
+             ! There are two possibilities: either we compare today's fpc with the fpc after the last
+             ! time step, or we compare it to last year's maximum fpc of that PFT. In the first case,
+             ! the fpc increase will be strong for seasonal PFTs at the beginning of the growing season.
+             ! As for trees, the cutback is proportional to this increase, this means that seasonal trees
+             ! will be disadvantaged compared to evergreen trees. In the original LPJ model, with its 
+             ! annual time step, the second method was used (this corresponds to annual_increase=.TRUE.)
+             
+             IF ( annual_increase ) THEN
+                deltafpc(:) = MAX( (fpc_nat(i,:)-maxfpc_lastyear(i,:)), zero )
              ELSE
-                DO i = 1, npts
-                   IF (lai(i,j) == val_exp) THEN
-                      fpc_nat(i,j) = cn_ind(i,j) * ind(i,j)
+                deltafpc(:) = MAX( (fpc_nat(i,:)-veget_lastlight(i,:)), zero )
+             ENDIF
+             
+             ! default: survive
+             
+             survive(:) = 1.0
+             
+             !
+             ! 3.1 determine some characteristics of the fpc distribution
+             !
+             
+             sumfpc_wood = zero
+             sumdelta_fpc_wood = zero
+             maxfpc_wood = zero
+             optpft_wood = 0
+             sumfpc_grass = zero
+             !        num_grass = 0
+             
+             DO j = 2,nvm
+                
+                ! only natural pfts
+                
+                IF ( natural(j) ) THEN
+                   
+                   IF ( tree(j) ) THEN
+                      
+                      ! trees
+                      
+                      ! total woody fpc
+                      
+                      sumfpc_wood = sumfpc_wood + fpc_nat(i,j)
+                      
+                      ! how much did the woody fpc increase
+                      
+                      sumdelta_fpc_wood = sumdelta_fpc_wood + deltafpc(j)
+                      
+                      ! which woody pft is preponderant
+                      
+                      IF ( fpc_nat(i,j) .GT. maxfpc_wood ) THEN
+                         
+                         optpft_wood = j
+                         
+                         maxfpc_wood = fpc_nat(i,j)
+                      
+                      ENDIF
+                   
                    ELSE
-                      fpc_nat(i,j) = cn_ind(i,j) * ind(i,j) * &
-                           ( un - exp( -lai(i,j) * ext_coeff(j) ) )
-                   ENDIF
-                ENDDO
-             ENDIF
-          ENDIF  ! tree/grass
-
-       ELSE
-
-          ! 2.1.2 agricultural PFTs: not present on natural part
-
-          fpc_nat(:,j) = 0.0
-
-       ENDIF    ! natural/agricultural
-
-    ENDDO
-
-    !
-    ! 2.2 sum natural fpc for every grid point
-    !
-
-    sumfpc(:) = zero
-    DO j = 2,nvm
-       !SZ bug correction MERGE: need to subtract agricultural area!
-       sumfpc(:) = sumfpc(:) + fpc_nat(:,j)
-    ENDDO
-
-    !
-    ! 3 Light competition
-    !
-
-    light_death(:,:) = 0.0
-
-    DO i = 1, npts ! SZ why this loop and not a vector statement ?
-
-       ! Only if vegetation cover is dense
-
-       IF ( sumfpc(i) .GT. fpc_crit ) THEN
-
-          ! fpc change for each pft
-          ! There are two possibilities: either we compare today's fpc with the fpc after the last
-          ! time step, or we compare it to last year's maximum fpc of that PFT. In the first case,
-          ! the fpc increase will be strong for seasonal PFTs at the beginning of the growing season.
-          ! As for trees, the cutback is proportional to this increase, this means that seasonal trees
-          ! will be disadvantaged compared to evergreen trees. In the original LPJ model, with its 
-          ! annual time step, the second method was used (this corresponds to annual_increase=.TRUE.)
-
-          IF ( annual_increase ) THEN
-             deltafpc(:) = MAX( (fpc_nat(i,:)-maxfpc_lastyear(i,:)), zero )
-          ELSE
-             deltafpc(:) = MAX( (fpc_nat(i,:)-veget_lastlight(i,:)), zero )
-          ENDIF
-
-          ! default: survive
-
-          survive(:) = 1.0
-
-          !
-          ! 3.1 determine some characteristics of the fpc distribution
-          !
-
-          sumfpc_wood = 0.0
-          sumdelta_fpc_wood = 0.0
-          maxfpc_wood = 0.0
-          optpft_wood = 0
-          sumfpc_grass = 0.0
-          num_grass = 0
-
-          DO j = 2,nvm
-
-             ! only natural pfts
-
-             IF ( natural(j) ) THEN
-
-                IF ( tree(j) ) THEN
-
-                   ! trees
-
-                   ! total woody fpc
-
-                   sumfpc_wood = sumfpc_wood + fpc_nat(i,j)
-
-                   ! how much did the woody fpc increase
-
-                   sumdelta_fpc_wood = sumdelta_fpc_wood + deltafpc(j)
-
-                   ! which woody pft is preponderant
-
-                   IF ( fpc_nat(i,j) .GT. maxfpc_wood ) THEN
-
-                      optpft_wood = j
-
-                      maxfpc_wood = fpc_nat(i,j)
-
-                   ENDIF
-
-                ELSE
-
+                   
                    ! grasses
 
                    ! total (natural) grass fpc
-
+                   
                    sumfpc_grass = sumfpc_grass + fpc_nat(i,j)
-
+                   
                    ! number of grass PFTs present in the grid box
-
-                   IF ( PFTpresent(i,j) ) THEN
-                      num_grass = num_grass + 1
-                   ENDIF
-
+                   
+                   ! IF ( PFTpresent(i,j) ) THEN
+                   !    num_grass = num_grass + 1
+                   ! ENDIF
+                   
                 ENDIF   ! tree or grass
-
+                
              ENDIF   ! natural
-
+             
           ENDDO     ! loop over pfts
-
+          
           !
           ! 3.2 light competition: assume wood outcompetes grass
           !
-
-          IF (sumfpc_wood .GE. fpc_crit ) THEN
-
-             !
-             ! 3.2.1 all allowed natural space is covered by wood:
-             !       cut back trees to fpc_crit.
-             !       Original DGVM: kill grasses. Modified: we let a very
-             !       small fraction of grasses survive.
-             !
-
+          !SZ
+!!$             IF (sumfpc_wood .GE. fpc_crit ) THEN
+          
+          !
+          ! 3.2.1 all allowed natural space is covered by wood:
+          !       cut back trees to fpc_crit.
+          !       Original DGVM: kill grasses. Modified: we let a very
+          !       small fraction of grasses survive.
+          !
+          
+          DO j = 2,nvm
+             
+             ! only present and natural pfts compete
+             
+             IF ( PFTpresent(i,j) .AND. natural(j) ) THEN
+                
+                IF ( tree(j) ) THEN
+                   
+                   !
+                   ! 3.2.1.1 tree
+                   !
+                   
+                   ! no single woody pft is overwhelming
+                   ! (original DGVM: tree_mercy = 0.0 )
+                   ! The reduction rate is proportional to the ratio deltafpc/fpc.
+                   
+                   IF (sumfpc_wood .GE. fpc_crit .AND. fpc_nat(i,j) .GT. min_stomate .AND. & 
+                        sumdelta_fpc_wood .GT. min_stomate) THEN
+                      
+                      ! reduct = MIN( ( ( deltafpc(j)/sumdelta_fpc_wood * &
+                      !     (sumfpc_wood-fpc_crit) ) / fpc_nat(i,j) ), &
+                      !     ( 1._r_std - tree_mercy ) )
+                      reduct = un - MIN((fpc_nat(i,j)-(sumfpc_wood-fpc_crit) & 
+                           * deltafpc(j)/sumdelta_fpc_wood)/fpc_nat(i,j), un )
+                      
+                   ELSE
+                      
+                      ! tree fpc didn't icrease or it started from nothing
+                      
+                      reduct = zero
+                      
+                   ENDIF
+                   
+                   survive(j) = un - reduct
+                   
+                ELSE
+                   
+                   !
+                   ! 3.2.1.2 grass: let a very small fraction survive (the sum of all
+                   !         grass individuals may make up a maximum cover of
+                   !         grass_mercy [for lai -> infinity]).
+                   !         In the original DGVM, grasses were killed in that case,
+                   !         corresponding to grass_mercy = 0.
+                   !
+                   
+                   ! survive(j) = ( grass_mercy / REAL( num_grass,r_std ) ) / ind(i,j)
+                   
+                   ! survive(j) = MIN( 1._r_std, survive(j) 
+                   
+                   IF(sumfpc_grass .GE. 1.0-MIN(fpc_crit,sumfpc_wood).AND. & 
+                        sumfpc_grass.GE.min_stomate) THEN
+                      
+                      fpc_dec=(sumfpc_grass-1.+MIN(fpc_crit,sumfpc_wood))*fpc_nat(i,j)/sumfpc_grass
+                      
+                      reduct=fpc_dec
+                   ELSE 
+                      reduct = zero
+                   ENDIF
+                   survive(j) = ( un -  reduct ) 
+                   
+                ENDIF   ! tree or grass
+                
+             ENDIF     ! pft there and natural
+          
+          ENDDO       ! loop over pfts
+       
+       !SZ
+!!$    ELSE
+!!$       
+!!$       !
+!!$       ! 3.2.2 not too much wood so that grasses can subsist
+!!$       !
+!!$       
+!!$       ! new total grass fpc
+!!$       sumfpc_grass2 = fpc_crit - sumfpc_wood
+!!$       
+!!$       DO j = 2,nvm
+!!$          
+!!$          ! only present and natural PFTs compete
+!!$          
+!!$          IF ( PFTpresent(i,j) .AND. natural(j) ) THEN
+!!$             
+!!$             IF ( tree(j) ) THEN
+!!$                
+!!$                ! no change for trees
+!!$                
+!!$                survive(j) = 1.0
+!!$                
+!!$             ELSE
+!!$                
+!!$                ! grass: fractional loss is the same for all grasses
+!!$                
+!!$                IF ( sumfpc_grass .GT. min_stomate ) THEN
+!!$                   survive(j) = sumfpc_grass2 / sumfpc_grass
+!!$                ELSE
+!!$                   survive(j)=  zero
+!!$                ENDIF
+!!$                
+!!$             ENDIF
+!!$             
+!!$          ENDIF    ! pft there and natural
+!!$          
+!!$       ENDDO       ! loop over pfts
+!!$       
+!!$    ENDIF    ! sumfpc_wood > fpc_crit
+
+             !
+             ! 3.3 update output variables
+             !
+       
              DO j = 2,nvm
-
-                ! only present and natural pfts compete
-
+          
                 IF ( PFTpresent(i,j) .AND. natural(j) ) THEN
-
-                   IF ( tree(j) ) THEN
-
-                      !
-                      ! 3.2.1.1 tree
-                      !
-
-                      IF ( maxfpc_wood .GE. fpc_crit ) THEN
-
-                         ! 3.2.1.1.1 one single woody pft is overwhelming
-
-                         IF ( j .eq. optpft_wood ) THEN
-
-                            ! reduction for this dominant pft
-
-                            reduct = 1. - fpc_crit / fpc_nat(i,j)
-
-                         ELSE
-
-                            ! strongly reduce all other woody pfts
-                            !   (original DGVM: tree_mercy = 0.0 )
-
-                            reduct = 1. - tree_mercy
-
-                         ENDIF   ! pft = dominant woody pft
-
-                      ELSE
-
-                         ! 3.2.1.1.2 no single woody pft is overwhelming
-                         !           (original DGVM: tree_mercy = 0.0 )
-                         !           The reduction rate is proportional to the ratio deltafpc/fpc.
-
-                         IF ( fpc_nat(i,j) .GE. min_stomate ) THEN
-
-                            reduct = MIN( ( ( deltafpc(j)/sumdelta_fpc_wood * &
-                                 (sumfpc_wood-fpc_crit) ) / fpc_nat(i,j) ), &
-                                 ( un - tree_mercy ) )
-
-                         ELSE
-
-                            ! tree fpc didn't icrease or it started from nothing
-
-                            reduct = 0.
-
-                         ENDIF
-
-                      ENDIF   ! maxfpc_wood > fpc_crit
-
-                      survive(j) = 1. - reduct
-
+                   
+                   bm_to_litter(i,j,:) = bm_to_litter(i,j,:) + &
+                        biomass(i,j,:) * ( un - survive(j) )
+                   
+                   biomass(i,j,:) = biomass(i,j,:) * survive(j)
+                   
+                   IF ( control%ok_dgvm ) THEN
+                      ind(i,j) = ind(i,j) * survive(j)
+                   ENDIF
+                   
+                   ! fraction of plants that dies each day. 
+                   ! exact formulation: light_death(i,j) = 1. - survive(j) ** (1/dt)
+                   light_death(i,j) = ( un - survive(j) ) / dt
+                   
+                ENDIF      ! pft there and natural
+                
+             ENDDO        ! loop over pfts
+             
+          ENDIF      ! sumfpc > fpc_crit
+          
+       ENDDO        ! loop over grid points
+       
+       !
+       ! 4 recalculate fpc on natural part of grid cell (for next light competition)
+       !
+       
+       DO j = 2,nvm
+          
+          IF ( natural(j) ) THEN
+             
+             !
+             ! 4.1 natural PFTs
+             !
+             
+             IF ( tree(j) ) THEN
+                
+                ! 4.1.1 trees: minimum cover due to stems, branches etc.
+                
+                DO i = 1, npts
+                   !NVMODIF         
+                   !    IF (lai(i,j) == val_exp) THEN
+                   !                veget_lastlight(i,j) = cn_ind(i,j) * ind(i,j) 
+                   !             ELSE
+                   !                veget_lastlight(i,j) = &
+                   !                     cn_ind(i,j) * ind(i,j) * &
+                   !                     MAX( ( un - exp( -lai(i,j) * ext_coeff(j) ) ), min_cover )
+                   !             ENDIF
+                   !!                veget_lastlight(i,j) = cn_ind(i,j) * ind(i,j) 
+                   IF (lai(i,j) == val_exp) THEN
+                      veget_lastlight(i,j) = cn_ind(i,j) * ind(i,j) 
                    ELSE
-
-                      !
-                      ! 3.2.1.2 grass: let a very small fraction survive (the sum of all
-                      !         grass individuals may make up a maximum cover of
-                      !         grass_mercy [for lai -> infinity]).
-                      !         In the original DGVM, grasses were killed in that case,
-                      !         corresponding to grass_mercy = 0.
-                      !
-
-                      survive(j) = ( grass_mercy / REAL( num_grass,r_std ) ) / ind(i,j)
-
-                      survive(j) = MIN( un, survive(j) )
-
-                   ENDIF   ! tree or grass
-
-                ENDIF     ! pft there and natural
-
-             ENDDO       ! loop over pfts
-
+                      veget_lastlight(i,j) = &
+                           cn_ind(i,j) * ind(i,j) * &
+                           MAX( ( un - EXP( - lm_lastyearmax(i,j) * sla(j) * ext_coeff(j) ) ), min_cover )
+                   ENDIF
+                ENDDO
+                
+             ELSE
+                
+                ! 4.1.2 grasses
+                DO i = 1, npts
+                   !NVMODIF         
+                   !            IF (lai(i,j) == val_exp) THEN
+                   !                veget_lastlight(i,j) = cn_ind(i,j) * ind(i,j) 
+                   !             ELSE
+                   !                veget_lastlight(i,j) = cn_ind(i,j) * ind(i,j) * &
+                   !                     ( un - exp( -lai(i,j) * ext_coeff(j) ) )
+                   !             ENDIF
+                   !!veget_lastlight(i,j) = cn_ind(i,j) * ind(i,j) 
+                   IF (lai(i,j) == val_exp) THEN
+                      veget_lastlight(i,j) = cn_ind(i,j) * ind(i,j) 
+                   ELSE
+                      veget_lastlight(i,j) = cn_ind(i,j) * ind(i,j) * &
+                           ( un - exp( - lm_lastyearmax(i,j) * sla(j) * ext_coeff(j) ) )
+                   ENDIF
+                ENDDO
+             ENDIF    ! tree/grass
+             
           ELSE
-
-             !
-             ! 3.2.2 not too much wood so that grasses can subsist
-             !
-
-             ! new total grass fpc
-             sumfpc_grass2 = fpc_crit - sumfpc_wood
-
-             DO j = 2,nvm
-
-                ! only present and natural PFTs compete
-
-                IF ( PFTpresent(i,j) .AND. natural(j) ) THEN
-
-                   IF ( tree(j) ) THEN
-
-                      ! no change for trees
-
-                      survive(j) = 1.0
-
-                   ELSE
-
-                      ! grass: fractional loss is the same for all grasses
-
-                      IF ( sumfpc_grass .GT. min_stomate ) THEN
-                         survive(j) = sumfpc_grass2 / sumfpc_grass
-                      ELSE
-                         survive(j)=  0.0
-                      ENDIF
-
-                   ENDIF
-
-                ENDIF    ! pft there and natural
-
-             ENDDO       ! loop over pfts
-
-          ENDIF    ! sumfpc_wood > fpc_crit
-
-          !
-          ! 3.3 update output variables
-          !
-
-          DO j = 2,nvm
-
-             IF ( PFTpresent(i,j) .AND. natural(j) ) THEN
-
-                bm_to_litter(i,j,:) = bm_to_litter(i,j,:) + &
-                     biomass(i,j,:) * ( 1. - survive(j) )
-
-                biomass(i,j,:) = biomass(i,j,:) * survive(j)
-
-                IF ( control%ok_dgvm ) THEN
-                   ind(i,j) = ind(i,j) * survive(j)
-                ENDIF
-
-                ! fraction of plants that dies each day. 
-                ! exact formulation: light_death(i,j) = 1. - survive(j) ** (1/dt)
-                light_death(i,j) = ( 1. - survive(j) ) / dt
-
-             ENDIF      ! pft there and natural
-
-          ENDDO        ! loop over pfts
-
-       ENDIF      ! sumfpc > fpc_crit
-
-    ENDDO        ! loop over grid points
-
-    !
-    ! 4 recalculate fpc on natural part of grid cell (for next light competition)
-    !
-
-    DO j = 2,nvm
-
-       IF ( natural(j) ) THEN
-
-          !
-          ! 4.1 natural PFTs
-          !
-
-          IF ( tree(j) ) THEN
-
-             ! 4.1.1 trees: minimum cover due to stems, branches etc.
-
-             DO i = 1, npts
-                IF (lai(i,j) == val_exp) THEN
-                   veget_lastlight(i,j) = cn_ind(i,j) * ind(i,j) 
-                ELSE
-                   veget_lastlight(i,j) = &
-                        cn_ind(i,j) * ind(i,j) * &
-                        MAX( ( un - exp( -lai(i,j) * ext_coeff(j) ) ), min_cover )
-                ENDIF
+             
+             !
+             ! 4.2 agricultural PFTs: not present on natural part
+             !
+             
+             veget_lastlight(:,j) = zero
+             
+          ENDIF      ! natural/agricultural
+          
+       ENDDO
+       
+    ELSE ! static
+       
+       light_death(:,:) = zero
+       
+       DO j = 2, nvm
+          
+          IF ( natural(j) ) THEN
+             
+             ! 2.1.1 natural PFTs, in the one PFT only case there needs to be no special case for grasses,
+             ! neither a redistribution of mortality (delta fpc)
+             
+             WHERE( ind(:,j)*cn_ind(:,j) .GT. min_stomate ) 
+                lai_ind(:)=sla(j) * lm_lastyearmax(:,j) / ( ind(:,j) * cn_ind(:,j) )
+             ELSEWHERE
+                lai_ind(:)=zero
+             ENDWHERE
+             
+             fpc_nat(:,j) =  cn_ind(:,j) * ind(:,j) * & 
+                  MAX( ( 1._r_std - exp( - ext_coeff(j) * lai_ind(:) ) ), min_cover )
+             
+             WHERE(fpc_nat(:,j).GT.fpc_max(:,j))
+                
+                light_death(:,j)=MIN(un,un-fpc_max(:,j)/fpc_nat(:,j)) 
+                
+             ENDWHERE
+             
+             DO k=1,nparts
+                
+                bm_to_litter(:,j,k)=bm_to_litter(:,j,k)+light_death(:,j)*biomass(:,j,k)
+                biomass(:,j,k)=biomass(:,j,k)-light_death(:,j)*biomass(:,j,k)
+                
              ENDDO
-
-          ELSE
-
-             ! 4.1.2 grasses
-             DO i = 1, npts
-                IF (lai(i,j) == val_exp) THEN
-                   veget_lastlight(i,j) = cn_ind(i,j) * ind(i,j) 
-                ELSE
-                   veget_lastlight(i,j) = cn_ind(i,j) * ind(i,j) * &
-                        ( 1. - exp( -lai(i,j) * ext_coeff(j) ) )
-                ENDIF
-             ENDDO
-          ENDIF    ! tree/grass
-
-       ELSE
-
-          !
-          ! 4.2 agricultural PFTs: not present on natural part
-          !
-
-          veget_lastlight(:,j) = 0.0
-
-       ENDIF      ! natural/agricultural
-
-    ENDDO
-
+             ind(:,j)=ind(:,j)-light_death(:,j)*ind(:,j)
+             ! if (j==10) print *,'ind10bis=',ind(:,j),light_death(:,j)*ind(:,j)
+          ENDIF
+       ENDDO
+       
+       light_death(:,:)=light_death(:,:)/dt
+       
+    ENDIF
+    
     !
     ! 5 history
     !
-
+    
     CALL histwrite (hist_id_stomate, 'LIGHT_DEATH', itime, &
          light_death, npts*nvm, horipft_index)
-
+    
     IF (bavard.GE.4) WRITE(numout,*) 'Leaving light'
-
+    
   END SUBROUTINE light
-
+  
 END MODULE lpj_light
Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/lpj_pftinout.f90
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/lpj_pftinout.f90	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/lpj_pftinout.f90	(revision 257)
@@ -33,5 +33,5 @@
   SUBROUTINE pftinout (npts, dt, adapted, regenerate, &
        neighbours, veget, veget_max, &
-       biomass, ind, age, leaf_frac, npp_longterm, lm_lastyearmax, senescence, &
+       biomass, ind, cn_ind, age, leaf_frac, npp_longterm, lm_lastyearmax, senescence, &
        PFTpresent, everywhere, when_growthinit, need_adjacent, RIP_time, &
        co2_to_bm, &
@@ -66,4 +66,6 @@
     ! density of individuals 1/m**2
     REAL(r_std), DIMENSION(npts,nvm), INTENT(inout)           :: ind
+    ! crownarea of individuals m**2
+    REAL(r_std), DIMENSION(npts,nvm), INTENT(in)              :: cn_ind
     ! mean age (years)
     REAL(r_std), DIMENSION(npts,nvm), INTENT(inout)           :: age
@@ -104,5 +106,5 @@
     REAL(r_std), DIMENSION(npts)                               :: avail
     ! indices
-    INTEGER(i_std)                                             :: i,j
+    INTEGER(i_std)                                             :: i,j,m
     ! total woody vegetation cover
     REAL(r_std), DIMENSION(npts)                               :: sumfrac_wood
@@ -111,4 +113,6 @@
     ! we can introduce this PFT
     LOGICAL, DIMENSION(npts)                                  :: can_introduce
+    ! no real need for dimension(ntps) except for vectorisation
+    REAL(r_std), DIMENSION(npts)                               :: fracnat
 
     ! =========================================================================
@@ -132,16 +136,31 @@
     !
 
-    ! need to know total woody vegetation fraction
-
+    ! 2.1 Only natural part of the grid cell
+    !
+    !SZ bug correction MERGE: need to subtract agricultural area!
+    ! fraction of agricultural surface
+    fracnat(:) = 1.
+    do j = 2,nvm
+       IF ( .NOT. natural(j) ) THEN
+          fracnat(:) = fracnat(:) - veget_max(:,j)
+       ENDIF
+    ENDDO
+
+    !
+    ! 2.2 total woody fpc on grid
+    !
     sumfrac_wood(:) = zero
 
     DO j = 2,nvm
-
-       IF ( tree(j) ) THEN
-
-          sumfrac_wood(:) = sumfrac_wood(:) + veget(:,j)
-
+       !SZ problem here: agriculture, not convinced that this representation of LPJ is correct
+       !if agriculture is present, ind must be recalculated to correspond to the natural density...
+       ! since ind is per grid cell, can be achived by discounting for agricultura fraction
+       IF ( natural(j).AND.tree(j) ) THEN
+          WHERE(fracnat(:).GT.min_stomate)
+                sumfrac_wood(:) = sumfrac_wood(:) + cn_ind(:,j) * ind(:,j) / fracnat(:) & 
+                     * ( 1. - exp( - lm_lastyearmax(:,j) * sla(j) * ext_coeff(j) ) )
+                !lai changed to lm_last
+          ENDWHERE
        ENDIF
-
     ENDDO
 
Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/stomate.f90
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/stomate.f90	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/stomate.f90	(revision 257)
@@ -227,10 +227,15 @@
   INTEGER(i_std),ALLOCATABLE,SAVE,DIMENSION(:)  :: nforce
 
+  REAL(r_std),ALLOCATABLE,SAVE,DIMENSION(:)  :: harvest_above_monthly, cflux_prod_monthly
+
+  ! "maximal" coverage fraction of a PFT (LAI -> infinity) on ground 
+  REAL(r_std), ALLOCATABLE,SAVE,DIMENSION(:,:)              :: fpc_max
+
   ! Date and EndOfYear, intialize and update in slowproc
   ! (Now managed in slowproc for land_use)
   ! time step of STOMATE in days
-  REAL(r_std),SAVE                              :: dt_days=0.           ! Time step in days for stomate
+  REAL(r_std),SAVE                              :: dt_days=zero           ! Time step in days for stomate
   ! to check
-  REAL(r_std),SAVE                              :: day_counter=0.       ! count each sechiba (dtradia) time step each day
+  REAL(r_std),SAVE                              :: day_counter=zero       ! count each sechiba (dtradia) time step each day
   ! date (d)
   INTEGER(i_std),SAVE                          :: date=0
@@ -242,4 +247,7 @@
   ! Land cover change flag
   LOGICAL,SAVE                                 :: lcchange=.FALSE.
+  ! Do update of monthly variables ?
+  ! This variable must be .TRUE. once a month
+  LOGICAL, SAVE                                :: EndOfMonth=.FALSE.
   PUBLIC  dt_days, day_counter, date, do_slow, EndOfYear, lcchange
 
@@ -554,9 +562,12 @@
 
     REAL(r_std), DIMENSION(kjpindex)                                   :: vartmp
+    REAL(r_std)      :: net_cflux_prod_monthly_sum   , net_cflux_prod_monthly_tot
+    REAL(r_std)      :: net_harvest_above_monthly_sum, net_harvest_above_monthly_tot
+    REAL(r_std)      :: net_biosp_prod_monthly_sum   , net_biosp_prod_monthly_tot
     !---------------------------------------------------------------------
     ! first of all: store time step in common value
     itime = kjit
 
-    z_soil(0) = 0.
+    z_soil(0) = zero
     z_soil(1:nbdl) = diaglev(1:nbdl)
     DO j=1,nvm
@@ -877,5 +888,5 @@
              ENDIF
 
-             dt_forcesoil = 0.
+             dt_forcesoil = zero
              nparan = nparan+1
              DO WHILE (dt_forcesoil < dt_slow/one_day)
@@ -951,5 +962,5 @@
        l_first_stomate = .FALSE.
        !
-       ! 1.11 retu n
+       ! 1.11 return
        !
        RETURN
@@ -1158,4 +1169,9 @@
     ENDDO
 
+    IF ( day == 1 .AND. sec .LT. dtradia ) THEN
+       EndOfMonth=.TRUE.
+    ELSE
+       EndOfMonth=.FALSE.
+    ENDIF
     !
     ! 5 "daily" variables
@@ -1293,5 +1309,5 @@
 
           CALL StomateLpj &
-               &            (kjpindex, dt_days, EndOfYear, &
+               &            (kjpindex, dt_days, EndOfYear, EndOfMonth, &
                &             neighbours, resolution, &
                &             clay, herbivores, &
@@ -1318,5 +1334,6 @@
                &             t_photo_min, t_photo_opt, t_photo_max,bm_to_litter,&
                &             prod10, prod100, flux10, flux100, veget_cov_max_new,&
-               &             convflux, cflux_prod10, cflux_prod100, harvest_above, lcchange)
+               &             convflux, cflux_prod10, cflux_prod100, harvest_above, lcchange,&
+               &             fpc_max)
 
           !
@@ -1534,12 +1551,15 @@
        !
        co2_flux_monthly(:,:) = co2_flux_monthly(:,:) + co2_flux_daily(:,:)
-       IF ( day == 1 .AND. sec .LT. dtradia ) THEN
+!      Monthly Cumulative fluxes of fluc and harvest
+       harvest_above_monthly(:) = harvest_above_monthly(:) + harvest_above(:)
+       cflux_prod_monthly(:) = cflux_prod_monthly(:) + convflux(:) + cflux_prod10(:) + cflux_prod100(:)
+       IF ( EndOfMonth ) THEN
           IF ( control%ok_stomate ) THEN
-             CALL histwrite (hist_id_stomate, 'CO2FLUX_MONTHLY', itime, &
+             CALL histwrite (hist_id_stomate, 'CO2FLUX', itime, &
                   co2_flux_monthly, kjpindex*nvm, horipft_index)
           ENDIF
 !MM
 ! Si on supprimer le cumul par mois, 
-! il ne faut pas oublié cette modif resolution(:,1)*resolution(:,2)*contfrac(:) 
+! il ne faut pas oublier cette modif resolution(:,1)*resolution(:,2)*contfrac(:) 
           DO j=2, nvm
              co2_flux_monthly(:,j) = co2_flux_monthly(:,j)* &
@@ -1551,15 +1571,37 @@
              DO j=2,nvm
                 net_co2_flux_monthly = net_co2_flux_monthly + &
-                     &  co2_flux_monthly(ji,j)*veget_max(ji,j)
+                     &  co2_flux_monthly(ji,j)*veget_cov_max(ji,j)
              ENDDO
           ENDDO
+!         Total ( land) Cumulative fluxes of fluc and harvest
+          net_cflux_prod_monthly_sum=&
+              &  SUM(cflux_prod_monthly(:)*resolution(:,1)*resolution(:,2)*contfrac(:))*1e-15
+          CALL reduce_sum(net_cflux_prod_monthly_sum,net_cflux_prod_monthly_tot)
+          CALL bcast(net_cflux_prod_monthly_tot)
+
+          net_harvest_above_monthly_sum=&
+             &   SUM(harvest_above_monthly(:)*resolution(:,1)*resolution(:,2)*contfrac(:))*1e-15
+          CALL reduce_sum(net_harvest_above_monthly_sum,net_harvest_above_monthly_tot)
+          CALL bcast(net_harvest_above_monthly_tot)
+
           net_co2_flux_monthly = net_co2_flux_monthly*1e-15
-          WRITE(numout,*) 'net_co2_flux_monthly (Peta gC/month)  = ',net_co2_flux_monthly
-
           CALL reduce_sum(net_co2_flux_monthly,net_co2_flux_monthly_sum)
-          IF ( control%ok_stomate ) THEN
-             CALL histwrite (hist_id_stomate, 'CO2FLUX_MONTHLY_SUM', itime, &
-                  (/ net_co2_flux_monthly /), 1, (/ 1 /) )
-          ENDIF
+          CALL bcast(net_co2_flux_monthly_sum)
+
+          WRITE(numout,9010) 'GLOBAL net_cflux_prod_monthly    (Peta gC/month)  = ',net_cflux_prod_monthly_tot
+          WRITE(numout,9010) 'GLOBAL net_harvest_above_monthly (Peta gC/month)  = ',net_harvest_above_monthly_tot
+          WRITE(numout,9010) 'GLOBAL net_co2_flux_monthly      (Peta gC/month)  = ',net_co2_flux_monthly_sum
+
+!         Calculation of net biospheric production
+          net_biosp_prod_monthly_tot =  &
+             &    ( net_co2_flux_monthly_sum + net_cflux_prod_monthly_tot + net_harvest_above_monthly_tot )
+          WRITE(numout,9010) 'GLOBAL net_biosp_prod_monthly    (Peta gC/month)  = ',net_biosp_prod_monthly_tot
+
+9010  FORMAT(A52,F17.14)
+!!$          IF ( control%ok_stomate ) THEN
+!!$             vartmp(:)=net_co2_flux_monthly_sum
+!!$             CALL histwrite (hist_id_stomate, 'CO2FLUX_MONTHLY_SUM', itime, &
+!!$                  vartmp, kjpindex, hori_index )
+!!$          ENDIF
 !!$          IF (is_root_prc) THEN
 !!$             OPEN( unit=39,              &
@@ -1579,4 +1621,6 @@
 !!$          ENDIF
           co2_flux_monthly(:,:) = zero
+          harvest_above_monthly(:) = zero
+          cflux_prod_monthly(:)    = zero
        ENDIF
        !
@@ -1599,15 +1643,4 @@
 
     ENDIF  ! daily processes?
-    ! CO2FLUX Daily values are saved each dtradia,
-    ! then the value is wrong for the first day without restart.
-    IF ( hist_id > 0 ) THEN
-       CALL histwrite (hist_id, 'CO2FLUX', itime, &
-            co2_flux_daily, kjpindex*nvm, horipft_index)
-    ENDIF
-    IF ( hist2_id > 0 ) THEN
-       CALL histwrite (hist2_id, 'CO2FLUX', itime, &
-            co2_flux_daily, kjpindex*nvm, horipft_index)
-    ENDIF
-
     !
     ! 7 Outputs from Stomate
@@ -1907,4 +1940,8 @@
     ALLOCATE(co2_flux_monthly(kjpindex,nvm),stat=ier)
     l_error = l_error .OR. (ier /= 0)
+    ALLOCATE (cflux_prod_monthly(kjpindex), stat=ier)
+    l_error = l_error .OR. (ier.NE.0)
+    ALLOCATE (harvest_above_monthly(kjpindex), stat=ier)
+    l_error = l_error .OR. (ier.NE.0)
     ALLOCATE(bm_to_litter(kjpindex,nvm,nparts),stat=ier)
     l_error = l_error .OR. (ier /= 0)
@@ -1955,4 +1992,7 @@
     l_error = l_error .OR. (ier.NE.0)
     !
+    ALLOCATE (fpc_max(kjpindex,nvm), stat=ier)
+    l_error = l_error .OR. (ier.NE.0)
+    !
     IF (l_error) THEN
        STOP 'stomate_init: error in memory allocation'
@@ -2028,4 +2068,14 @@
     WRITE(numout,*) &
          &  'expansion across a grid cell is treated: ',treat_expansion
+
+    !Config Key  = LPJ_GAP_CONST_MORT
+    !Config Desc = prescribe mortality if not using DGVM?
+    !Config Def  = y
+    !Config Help = set to TRUE if constant mortality is to be activated
+    !              ignored if DGVM=true!
+    !
+    lpj_gap_const_mort=.TRUE.
+    CALL getin('LPJ_GAP_CONST_MORT', lpj_gap_const_mort)
+    WRITE(numout,*) 'LPJ GAP: constant mortality:', lpj_gap_const_mort
 
     !Config  Key  = HARVEST_AGRI
@@ -2046,5 +2096,9 @@
     co2_flux_daily(:,:) = zero
     co2_flux_monthly(:,:) = zero
-
+    cflux_prod_monthly(:) = zero
+    harvest_above_monthly(:) = zero
+    control_moist_daily(:,:) = zero
+    control_temp_daily(:,:) = zero
+    soilcarbon_input_daily(:,:,:) = zero
 
     ! initialisation of land cover change variables
@@ -2056,4 +2110,6 @@
     cflux_prod10(:) = zero
     cflux_prod100(:)= zero
+
+    fpc_max(:,:)=zero
     !--------------------------
   END SUBROUTINE stomate_init
@@ -2141,4 +2197,6 @@
     IF (ALLOCATED(co2_flux_daily)) DEALLOCATE(co2_flux_daily)
     IF (ALLOCATED(co2_flux_monthly)) DEALLOCATE(co2_flux_monthly)
+    IF (ALLOCATED(harvest_above_monthly)) DEALLOCATE (harvest_above_monthly)
+    IF (ALLOCATED(cflux_prod_monthly)) DEALLOCATE (cflux_prod_monthly)
     IF (ALLOCATED(bm_to_litter)) DEALLOCATE(bm_to_litter)
     IF (ALLOCATED(bm_to_littercalc)) DEALLOCATE(bm_to_littercalc)
@@ -2203,4 +2261,6 @@
     IF ( ALLOCATED (control_temp_daily)) DEALLOCATE (control_temp_daily)
     IF ( ALLOCATED (control_moist_daily)) DEALLOCATE (control_moist_daily)
+
+    IF ( ALLOCATED (fpc_max)) DEALLOCATE (fpc_max)
 
     ! 2. reset l_first
@@ -2265,5 +2325,5 @@
     !-
     ! dummy time step, must be zero
-    REAL(r_std),PARAMETER                        :: dt_0 = 0.
+    REAL(r_std),PARAMETER                        :: dt_0 = zero
     REAL(r_std),DIMENSION(kjpindex,nvm)          :: vcmax
     REAL(r_std),DIMENSION(kjpindex,nvm)          :: vjmax
Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/stomate_alloc.f90
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/stomate_alloc.f90	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/stomate_alloc.f90	(revision 257)
@@ -162,5 +162,5 @@
        ! 1.1.1 soil levels
 
-       z_soil(0) = 0.
+       z_soil(0) = zero
        z_soil(1:nbdl) = diaglev(1:nbdl)
 
@@ -202,6 +202,6 @@
     !
 
-    f_alloc(:,:,:) = 0.0
-    f_alloc(:,:,icarbres) = 1.0
+    f_alloc(:,:,:) = zero
+    f_alloc(:,:,icarbres) = un
     !
     ! 1.3 Convolution of the temperature and humidity profiles with some kind of profile
@@ -212,5 +212,5 @@
 
     ! 1.3.1.1 rpc is an integration constant such that the integral of the root profile is 1.
-    rpc(:) = 1. / ( 1. - EXP( -z_soil(nbdl) / z_nitrogen ) )
+    rpc(:) = un / ( un - EXP( -z_soil(nbdl) / z_nitrogen ) )
 
     ! 1.3.1.2 integrate over the nbdl levels
@@ -229,9 +229,9 @@
 
     ! 1.3.2.1 rpc is an integration constant such that the integral of the root profile is 1.
-    rpc(:) = 1. / ( 1. - EXP( -z_soil(nbdl) / z_nitrogen ) )
+    rpc(:) = un / ( un - EXP( -z_soil(nbdl) / z_nitrogen ) )
 
     ! 1.3.2.2 integrate over the nbdl levels
 
-    h_nitrogen(:) = 0.0
+    h_nitrogen(:) = zero
 
     DO l = 1, nbdl
@@ -251,6 +251,6 @@
     ! mean LAI on natural part
 
-    natveg_tot(:) = 0.0
-    lai_nat(:) = 0.0
+    natveg_tot(:) = zero
+    lai_nat(:) = zero
 
     DO j = 2, nvm
@@ -259,5 +259,5 @@
           veget_max_nat(:,j) = veget_max(:,j)
        ELSE
-          veget_max_nat(:,j) = 0.0
+          veget_max_nat(:,j) = zero
        ENDIF
 
@@ -314,5 +314,5 @@
        !             3/ must be at the beginning of the growing season
 
-       WHERE ( ( biomass(:,j,ileaf) .GT. 0.0 ) .AND. & 
+       WHERE ( ( biomass(:,j,ileaf) .GT. zero ) .AND. & 
             ( .NOT. senescence(:,j) ) .AND. &
             ( lai(:,j) .LT. lai_happy(j) ) .AND. &
@@ -337,5 +337,5 @@
        ELSEWHERE
 
-          transloc_leaf(:) = 0.0
+          transloc_leaf(:) = zero
 
        ENDWHERE
@@ -468,10 +468,10 @@
           ! leaf allocation
 
-          LtoLSR(:) = 1. - RtoLSR(:) - StoLSR(:)
+          LtoLSR(:) = un - RtoLSR(:) - StoLSR(:)
           LtoLSR(:) = MAX( min_LtoLSR, MIN( max_LtoLSR, LtoLSR(:) ) )
 
           ! roots: the rest
 
-          RtoLSR(:) = 1. - LtoLSR(:) - StoLSR(:)
+          RtoLSR(:) = un - LtoLSR(:) - StoLSR(:)
 
        ENDWHERE
@@ -483,5 +483,5 @@
           StoLSR(:) = StoLSR(:) + LtoLSR(:)
 
-          LtoLSR(:) = 0.0
+          LtoLSR(:) = zero
 
        ENDWHERE
@@ -514,7 +514,7 @@
 
                 IF ( ( biomass(i,j,icarbres)*sla(j) ) .LT. 2*lai_max(j) ) THEN
-                   carb_rescale(i) = 1. / ( 1. + ecureuil(j) * ( LtoLSR(i) + RtoLSR(i) ) )
+                   carb_rescale(i) = un / ( un + ecureuil(j) * ( LtoLSR(i) + RtoLSR(i) ) )
                 ELSE
-                   carb_rescale(i) = 1.
+                   carb_rescale(i) = un
                 ENDIF
 
@@ -522,7 +522,7 @@
 
                 f_alloc(i,j,isapabove) = StoLSR(i) * alloc_sap_above(i) * &
-                     ( 1. - f_alloc(i,j,ifruit) ) * carb_rescale(i)
-                f_alloc(i,j,isapbelow) = StoLSR(i) * ( 1. - alloc_sap_above(i) ) * &
-                     ( 1. - f_alloc(i,j,ifruit) ) * carb_rescale(i)
+                     ( un - f_alloc(i,j,ifruit) ) * carb_rescale(i)
+                f_alloc(i,j,isapbelow) = StoLSR(i) * ( un - alloc_sap_above(i) ) * &
+                     ( un - f_alloc(i,j,ifruit) ) * carb_rescale(i)
 
                 f_alloc(i,j,iroot) = RtoLSR(i) * ( 1.-f_alloc(i,j,ifruit) ) * carb_rescale(i)
@@ -530,5 +530,5 @@
                 ! this is equivalent to:
                 ! reserve alloc = ecureuil*(LtoLSR+StoLSR)*(1-fruit_alloc)*carb_rescale
-                f_alloc(i,j,icarbres) = ( 1. - carb_rescale(i) ) * ( 1.-f_alloc(i,j,ifruit) )
+                f_alloc(i,j,icarbres) = ( un - carb_rescale(i) ) * ( 1.-f_alloc(i,j,ifruit) )
 
              ENDIF  ! senescent?
Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/stomate_data.f90
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/stomate_data.f90	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/stomate_data.f90	(revision 257)
@@ -156,5 +156,42 @@
        ! Oct 2010 : replaced by values given by N.Viovy
 
-       IF ( bavard .GE. 1 ) WRITE(numout,*) '       specific leaf area (m**2/gC):', sla(j) !, 12./leaflife(j)
+       ! includes conversion from 
+       !!       sla(j) = 2. * 1e-4 * EXP(5.615 - 0.46 * log(12./leaflife_tab(j)))
+
+       IF ( leaf_tab(j) .EQ. 2 ) THEN
+
+          ! needle leaved tree
+          sla(j) = 2. * ( 10. ** ( 2.29 - 0.4 * LOG10(12./leaflife_tab(j)) ) ) *1e-4
+
+       ELSE
+
+          ! broad leaved tree or grass (Reich et al 1992)
+          sla(j) = 2. * ( 10. ** ( 2.41 - 0.38 * LOG10(12./leaflife_tab(j)) ) ) *1e-4
+
+       ENDIF
+
+!!$      IF ( leaf_tab(j) .EQ. 1 ) THEN
+!!$
+!!$        ! broad leaved tree
+!!$
+!!$        sla(j) = 2. * ( 10. ** ( 2.41 - 0.38 * LOG10(12./leaflife_tab(j)) ) ) *1e-4
+!!$
+!!$      ELSE
+!!$
+!!$        ! needle leaved or grass (Reich et al 1992)
+!!$
+!!$        sla(j) = 2. * ( 10. ** ( 2.29 - 0.4 * LOG10(12./leaflife_tab(j)) ) ) *1e-4
+!!$
+!!$      ENDIF
+!!$
+!!$      IF ( ( leaf_tab(j) .EQ. 2 ) .AND. ( pheno_type_tab(j) .EQ. 2 ) ) THEN
+!!$
+!!$        ! summergreen needle leaf
+!!$
+!!$        sla(j) = 1.25 * sla(j)
+!!$
+!!$      ENDIF
+
+       IF ( bavard .GE. 1 ) WRITE(numout,*) '       specific leaf area (m**2/gC):', sla(j), 12./leaflife_tab(j)
 
        !
@@ -175,5 +212,5 @@
              bm_sapl(j,icarbres) = bm_sapl_carbres * bm_sapl(j,ileaf)
           ELSE
-             bm_sapl(j,icarbres) = 0.0
+             bm_sapl(j,icarbres) = zero
           ENDIF
 
@@ -203,9 +240,9 @@
           bm_sapl(j,icarbres) = init_sapl_mass_carbres *bm_sapl(j,ileaf)
 
-          bm_sapl(j,isapabove) = 0.
-          bm_sapl(j,isapbelow) = 0.
-
-          bm_sapl(j,iheartabove) = 0.
-          bm_sapl(j,iheartbelow) = 0.
+          bm_sapl(j,isapabove) = zero
+          bm_sapl(j,isapbelow) = zero
+
+          bm_sapl(j,iheartabove) = zero
+          bm_sapl(j,iheartbelow) = zero
 
        ENDIF
Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/stomate_io.f90
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/stomate_io.f90	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/stomate_io.f90	(revision 257)
@@ -1730,5 +1730,4 @@
     REAL(r_std),DIMENSION(nbvmax) :: area
     REAL(r_std),DIMENSION(nbvmax) :: tt
-
     REAL(r_std) :: resx, resy
     LOGICAL :: do_again
Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/stomate_lcchange.f90
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/stomate_lcchange.f90	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/stomate_lcchange.f90	(revision 257)
@@ -139,5 +139,5 @@
 
     ! Turnover rates (gC/(m**2 of ground)/day)
-    REAL(r_std), DIMENSION(npts,nvm,nparts), INTENT(out)               :: turnover_daily
+    REAL(r_std), DIMENSION(npts,nvm,nparts), INTENT(inout)               :: turnover_daily
 
     ! 0.4 local
@@ -207,14 +207,14 @@
                    cn_ind(i,j) = cn_sapl(j)
                 ELSE
-                   cn_ind(i,j)=1.0
+                   cn_ind(i,j) = un
                 ENDIF
                 ind(i,j)= delta_veg(j) / cn_ind(i,j)
                 PFTpresent(i,j) = .TRUE.
-                everywhere(i,j) = 1.
+                everywhere(i,j) = un
                 senescence(i,j) = .FALSE.
                 age(i,j) = 0.
 
                 when_growthinit(i,j) = large_value
-                leaf_frac(i,j,1) = 1.0
+                leaf_frac(i,j,1) = un
                 npp_longterm(i,j) = 10.
                 lm_lastyearmax(i,j) = bm_sapl(j,ileaf) * ind(i,j)
@@ -321,8 +321,8 @@
        flux100(i,1)      = 0.01 * prod100(i,0)
        prod100(i,1)      = prod100(i,0)
-!MM=>          IF (prod100(i,1).LT.1.0) prod100(i,1) = 0.0
+!MM=>          IF (prod100(i,1).LT.1.0) prod100(i,1) = zero
 !MM=>stomate_lpj.f90       prod100_total(i)  = prod100_total(i) + prod100(i,1)
-       prod10(i,0)        = 0.0
-       prod100(i,0)       = 0.0 
+       prod10(i,0)        = zero
+       prod100(i,0)       = zero
 
     ENDDO  ! End loop on npts
Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/stomate_litter.f90
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/stomate_litter.f90	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/stomate_litter.f90	(revision 257)
@@ -185,5 +185,5 @@
        !
 
-       z_soil(0) = 0.
+       z_soil(0) = zero
        z_soil(1:nbdl) = diaglev(1:nbdl)
 
@@ -441,5 +441,5 @@
 
     ! 4.2.1 rpc is an integration constant such that the integral of the root profile is 1.
-    rpc(:) = 1. / ( 1. - EXP( -z_soil(nbdl) / z_decomp ) )
+    rpc(:) = un / ( un - EXP( -z_soil(nbdl) / z_decomp ) )
 
     ! 4.2.2 integrate over the nbdl levels
@@ -473,5 +473,5 @@
 
     ! 5.2.1 rpc is an integration constant such that the integral of the root profile is 1.
-    rpc(:) = 1. / ( 1. - EXP( -z_soil(nbdl) / z_decomp ) )
+    rpc(:) = un / ( un - EXP( -z_soil(nbdl) / z_decomp ) )
 
     ! 5.2.2 integrate over the nbdl levels
@@ -514,5 +514,5 @@
           ! to avoid a multiple (for ibelow and iabove) modification of dead_leaves,
           ! we do this test to do this calcul only ones in 1,nlev loop
-          if (l == iabove)  dead_leaves(:,m,istructural) = dead_leaves(:,m,istructural) * ( 1. - fd(:) )
+          if (l == iabove)  dead_leaves(:,m,istructural) = dead_leaves(:,m,istructural) * ( un - fd(:) )
 
           ! 6.1.3 non-lignin fraction of structural litter goes into
Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/stomate_lpj.f90
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/stomate_lpj.f90	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/stomate_lpj.f90	(revision 257)
@@ -39,5 +39,4 @@
   USE stomate_assimtemp
   USE stomate_lcchange
-
   !  USE Write_Field_p
 
@@ -70,5 +69,5 @@
   END SUBROUTINE StomateLpj_clear
 
-  SUBROUTINE StomateLpj (npts, dt_days, EndOfYear, &
+  SUBROUTINE StomateLpj (npts, dt_days, EndOfYear, EndOfMonth, &
        neighbours, resolution, &
        clay, herbivores, &
@@ -94,5 +93,6 @@
        t_photo_min, t_photo_opt, t_photo_max,bm_to_litter, &
        prod10,prod100,flux10, flux100, veget_max_new, &
-       convflux,cflux_prod10,cflux_prod100, harvest_above, lcchange)
+       convflux,cflux_prod10,cflux_prod100, harvest_above, lcchange, &
+       fpc_max)
 
     !
@@ -168,4 +168,6 @@
     ! maintenance respiration of different plant parts (gC/day/m**2 of ground)
     REAL(r_std), DIMENSION(npts,nvm,nparts), INTENT(in)             :: resp_maint_part
+    ! "maximal" coverage fraction of a PFT (LAI -> infinity) on ground 
+    REAL(r_std), DIMENSION(npts,nvm), INTENT(in)                  :: fpc_max
 
     ! 0.2 modified fields
@@ -264,5 +266,5 @@
     REAL(r_std), DIMENSION(npts,nvm), INTENT(inout)                 :: height
     ! fraction of soil covered by dead leaves
-    REAL(r_std), DIMENSION(npts), INTENT(out)                      :: deadleaf_cover
+    REAL(r_std), DIMENSION(npts), INTENT(inout)                      :: deadleaf_cover
     ! Maximum rate of carboxylation
     REAL(r_std), DIMENSION(npts,nvm), INTENT(out)                 :: vcmax
@@ -301,5 +303,6 @@
     ! Do update of yearly variables? This variable must be .TRUE. once a year
     LOGICAL, INTENT(in)                                                :: EndOfYear
-
+    ! Do update of monthly variables ? This variable must be .TRUE. once a month
+    LOGICAL, INTENT(in)                                                :: EndOfMonth
 
     ! 0.4 local
@@ -321,4 +324,6 @@
     ! crown area of individuals (m**2)
     REAL(r_std), DIMENSION(npts,nvm)                               :: cn_ind
+    ! woodmass of individuals (gC)
+    REAL(r_std), DIMENSION(npts,nvm)                               :: woodmass_ind
     ! fraction that goes into plant part
     REAL(r_std), DIMENSION(npts,nvm,nparts)                        :: f_alloc
@@ -337,4 +342,7 @@
     ! "maximal" coverage fraction of a PFT (LAI -> infinity) on ground
     REAL(r_std),DIMENSION(npts,nvm)                                :: veget_max_old
+
+    ! fraction of individual dying this time step
+    REAL(r_std), DIMENSION(npts,nvm)                               :: mortality
 
     REAL(r_std), DIMENSION(npts)                                   :: vartmp
@@ -367,8 +375,36 @@
     bm_to_litter(:,:,:) = zero
     cn_ind(:,:) = zero
+    woodmass_ind(:,:) = zero
     veget_max_old(:,:) = veget_max(:,:)
 
-    !
-    ! 1.3 Prescribe some vegetation characteristics if the vegetation is not dynamic
+    ! 1.3 Calculate some vegetation characteristics
+
+    !
+    ! 1.3.1 Calculate some vegetation characteristics (cn_ind and height) from
+    !     state variables if running DGVM or dynamic mortality in static cover mode
+    !
+    IF ( control%ok_dgvm .OR. .NOT.lpj_gap_const_mort) THEN
+       IF(control%ok_dgvm) THEN
+          WHERE (ind(:,:).GT.min_stomate)
+             woodmass_ind(:,:) = &
+                  ((biomass(:,:,isapabove)+biomass(:,:,isapbelow) &
+                  +biomass(:,:,iheartabove)+biomass(:,:,iheartbelow)) & 
+                  *veget_max(:,:))/ind(:,:)
+          ENDWHERE
+       ELSE
+          WHERE (ind(:,:).GT.min_stomate)
+             woodmass_ind(:,:) = &
+                  (biomass(:,:,isapabove)+biomass(:,:,isapbelow) &
+                  +biomass(:,:,iheartabove)+biomass(:,:,iheartbelow))/ind(:,:)
+          ENDWHERE
+       ENDIF
+
+       CALL crown (npts,  PFTpresent, &
+            ind, biomass, woodmass_ind, &
+            veget_max, cn_ind, height)
+    ENDIF
+
+    !
+    ! 1.3.2 Prescribe some vegetation characteristics if the vegetation is not dynamic
     !     IF the DGVM is not activated, the density of individuals and their crown
     !     areas don't matter, but they should be defined for the case we switch on
@@ -389,5 +425,5 @@
 
     CALL constraints (npts, dt_days, &
-         t2m_month, t2m_min_daily, when_growthinit, &
+         t2m_month, t2m_min_daily,when_growthinit, &
          adapted, regenerate)
 
@@ -404,5 +440,5 @@
        CALL pftinout (npts, dt_days, adapted, regenerate, &
             neighbours, veget, veget_max, &
-            biomass, ind, age, leaf_frac, npp_longterm, lm_lastyearmax, senescence, &
+            biomass, ind, cn_ind, age, leaf_frac, npp_longterm, lm_lastyearmax, senescence, &
             PFTpresent, everywhere, when_growthinit, need_adjacent, RIP_time, &
             co2_to_bm, &
@@ -417,5 +453,5 @@
        CALL kill (npts, 'pftinout  ', lm_lastyearmax, &
             ind, PFTpresent, cn_ind, biomass, senescence, RIP_time, &
-            lai, age, leaf_age, leaf_frac, &
+            lai, age, leaf_age, leaf_frac, npp_longterm, &
             when_growthinit, everywhere, veget, veget_max, bm_to_litter)
 
@@ -423,7 +459,24 @@
        ! 3.3 calculate new crown area and maximum vegetation cover
        !
+       !
+       ! unsure whether this is really required
+       ! - in theory this could ONLY be done at the END of stomate_lpj
+       !
+
+       ! calculate woodmass of individual tree
+       WHERE ((ind(:,:).GT.min_stomate))
+          WHERE  ( veget_max(:,:) .GT. min_stomate)
+             woodmass_ind(:,:) = &
+                  ((biomass(:,:,isapabove)+biomass(:,:,isapbelow) &
+                  +biomass(:,:,iheartabove)+biomass(:,:,iheartbelow))*veget_max(:,:))/ind(:,:)
+          ELSEWHERE
+             woodmass_ind(:,:) =(biomass(:,:,isapabove)+biomass(:,:,isapbelow) &
+                  +biomass(:,:,iheartabove)+biomass(:,:,iheartbelow))/ind(:,:)
+          ENDWHERE
+
+       ENDWHERE
 
        CALL crown (npts, PFTpresent, &
-            ind, biomass, &
+            ind, biomass, woodmass_ind, &
             veget_max, cn_ind, height)
 
@@ -487,10 +540,28 @@
          resp_maint, resp_growth, npp_daily)
 
-    IF ( control%ok_dgvm ) THEN
+    IF ( control%ok_dgvm .OR. .NOT.lpj_gap_const_mort) THEN
+       CALL kill (npts, 'npp       ', lm_lastyearmax,  &
+            ind, PFTpresent, cn_ind, biomass, senescence, RIP_time, &
+            lai, age, leaf_age, leaf_frac, npp_longterm, &
+            when_growthinit, everywhere, veget, veget_max, bm_to_litter)
 
        ! new provisional crown area and maximum vegetation cover after growth
+       IF(control%ok_dgvm) THEN
+          WHERE (ind(:,:).GT.min_stomate)
+             woodmass_ind(:,:) = &
+                  ((biomass(:,:,isapabove)+biomass(:,:,isapbelow) &
+                  +biomass(:,:,iheartabove)+biomass(:,:,iheartbelow)) & 
+                  *veget_max(:,:))/ind(:,:)
+          ENDWHERE
+       ELSE
+          WHERE (ind(:,:).GT.min_stomate)
+             woodmass_ind(:,:) = &
+                  (biomass(:,:,isapabove)+biomass(:,:,isapbelow) &
+                  +biomass(:,:,iheartabove)+biomass(:,:,iheartbelow))/ind(:,:)
+          ENDWHERE
+       ENDIF
 
        CALL crown (npts, PFTpresent, &
-            ind, biomass, &
+            ind, biomass, woodmass_ind,&
             veget_max, cn_ind, height)
 
@@ -513,5 +584,5 @@
        CALL kill (npts, 'fire      ', lm_lastyearmax, &
             ind, PFTpresent, cn_ind, biomass, senescence, RIP_time, &
-            lai, age, leaf_age, leaf_frac, &
+            lai, age, leaf_age, leaf_frac, npp_longterm, &
             when_growthinit, everywhere, veget, veget_max, bm_to_litter)
 
@@ -524,5 +595,5 @@
     CALL gap (npts, dt_days, &
          npp_longterm, turnover_longterm, lm_lastyearmax, &
-         PFTpresent, biomass, ind, bm_to_litter)
+         PFTpresent, biomass, ind, bm_to_litter, mortality)
 
     IF ( control%ok_dgvm ) THEN
@@ -532,5 +603,5 @@
        CALL kill (npts, 'gap       ', lm_lastyearmax, &
             ind, PFTpresent, cn_ind, biomass, senescence, RIP_time, &
-            lai, age, leaf_age, leaf_frac, &
+            lai, age, leaf_age, leaf_frac, npp_longterm, &
             when_growthinit, everywhere, veget, veget_max, bm_to_litter)
 
@@ -570,6 +641,6 @@
 
        CALL light (npts, dt_days, &
-            PFTpresent, cn_ind, lai, maxfpc_lastyear, &
-            ind, biomass, veget_lastlight, bm_to_litter)
+            veget_max, fpc_max, PFTpresent, cn_ind, lai, maxfpc_lastyear, &
+            lm_lastyearmax, ind, biomass, veget_lastlight, bm_to_litter, mortality)
 
        !
@@ -579,5 +650,5 @@
        CALL kill (npts, 'light     ', lm_lastyearmax, &
             ind, PFTpresent, cn_ind, biomass, senescence, RIP_time, &
-            lai, age, leaf_age, leaf_frac, &
+            lai, age, leaf_age, leaf_frac, npp_longterm, &
             when_growthinit, everywhere, veget, veget_max, bm_to_litter)
 
@@ -588,5 +659,5 @@
     !
 
-    IF ( control%ok_dgvm ) THEN
+    IF ( control%ok_dgvm .OR. .NOT.lpj_gap_const_mort ) THEN
 
        !
@@ -597,7 +668,7 @@
             neighbours, resolution, need_adjacent, herbivores, &
             precip_lastyear, gdd0_lastyear, lm_lastyearmax, &
-            cn_ind, lai, avail_tree, avail_grass, &
+            cn_ind, lai, avail_tree, avail_grass, npp_longterm, &
             leaf_age, leaf_frac, &
-            ind, biomass, age, everywhere, co2_to_bm, veget_max)
+            ind, biomass, age, everywhere, co2_to_bm, veget_max, woodmass_ind)
 
        !
@@ -606,5 +677,5 @@
 
        CALL crown (npts, PFTpresent, &
-            ind, biomass, &
+            ind, biomass, woodmass_ind, &
             veget_max, cn_ind, height)
 
@@ -617,5 +688,5 @@
     CALL cover (npts, cn_ind, ind, biomass, &
          veget_max, veget_max_old, veget, &
-         lai, litter, carbon)
+         lai, litter, carbon, turnover_daily, bm_to_litter)
 
     !
@@ -645,8 +716,7 @@
                prod10,prod100,convflux,cflux_prod10,cflux_prod100,leaf_frac,&
                npp_longterm, lm_lastyearmax, litter, carbon)
-
        ENDIF
     ENDIF
-!MM dÃ©placement pour initialisation correcte des grandeurs cumulÃ©es :
+    !MM dÃ©placement pour initialisation correcte des grandeurs cumulÃ©es :
     cflux_prod_total(:) = convflux(:) + cflux_prod10(:) + cflux_prod100(:)
     prod10_total(:)=SUM(prod10,dim=2)
@@ -736,4 +806,9 @@
     CALL histwrite (hist_id_stomate, 'CO2_TAKEN', itime, &
          co2_to_bm, npts*nvm, horipft_index)
+!MM : histdef Ã  construire ! 
+!!$   CALL histwrite (hist_id_stomate, 'CN_IND', itime, &
+!!$                    cn_ind, npts*nvm, horipft_index)
+!!$   CALL histwrite (hist_id_stomate, 'WOODMASS_IND', itime, &
+!!$                    woodmass_ind, npts*nvm, horipft_index)
     ! land cover change
     CALL histwrite (hist_id_stomate, 'CONVFLUX', itime, &
@@ -833,108 +908,140 @@
        vartmp(:)=SUM(tot_live_biomass*veget_max,dim=2)/1e3*contfrac
        CALL histwrite (hist_id_stomate_IPCC, "cVeg", itime, &
-         vartmp, npts, hori_index)
+            vartmp, npts, hori_index)
        vartmp(:)=SUM(tot_litter_carb*veget_max,dim=2)/1e3*contfrac
        CALL histwrite (hist_id_stomate_IPCC, "cLitter", itime, &
-         vartmp, npts, hori_index)
+            vartmp, npts, hori_index)
        vartmp(:)=SUM(tot_soil_carb*veget_max,dim=2)/1e3*contfrac
        CALL histwrite (hist_id_stomate_IPCC, "cSoil", itime, &
-         vartmp, npts, hori_index)
+            vartmp, npts, hori_index)
        vartmp(:)=(prod10_total + prod100_total)/1e3
        CALL histwrite (hist_id_stomate_IPCC, "cProduct", itime, &
-         vartmp, npts, hori_index)
+            vartmp, npts, hori_index)
        vartmp(:)=SUM(lai*veget_max,dim=2)*contfrac
        CALL histwrite (hist_id_stomate_IPCC, "lai", itime, &
-         vartmp, npts, hori_index)
+            vartmp, npts, hori_index)
        vartmp(:)=SUM(gpp_daily*veget_max,dim=2)/1e3/one_day*contfrac
        CALL histwrite (hist_id_stomate_IPCC, "gpp", itime, &
-         vartmp, npts, hori_index)
+            vartmp, npts, hori_index)
        vartmp(:)=SUM((resp_maint+resp_growth)*veget_max,dim=2)/1e3/one_day*contfrac
        CALL histwrite (hist_id_stomate_IPCC, "ra", itime, &
-         vartmp, npts, hori_index)
+            vartmp, npts, hori_index)
        vartmp(:)=SUM(npp_daily*veget_max,dim=2)/1e3/one_day*contfrac
        CALL histwrite (hist_id_stomate_IPCC, "npp", itime, &
-         vartmp, npts, hori_index)
+            vartmp, npts, hori_index)
        vartmp(:)=SUM(resp_hetero*veget_max,dim=2)/1e3/one_day*contfrac
        CALL histwrite (hist_id_stomate_IPCC, "rh", itime, &
-         vartmp, npts, hori_index)
+            vartmp, npts, hori_index)
        vartmp(:)=SUM(co2_fire*veget_max,dim=2)/1e3/one_day*contfrac
        CALL histwrite (hist_id_stomate_IPCC, "fFire", itime, &
-         vartmp, npts, hori_index)
+            vartmp, npts, hori_index)
        vartmp(:)=harvest_above/1e3/one_day*contfrac
        CALL histwrite (hist_id_stomate_IPCC, "fHarvest", itime, &
-         vartmp, npts, hori_index)
+            vartmp, npts, hori_index)
        vartmp(:)=cflux_prod_total/1e3/one_day*contfrac
        CALL histwrite (hist_id_stomate_IPCC, "fLuc", itime, &
-         vartmp, npts, hori_index)
+            vartmp, npts, hori_index)
        vartmp(:)=(SUM((gpp_daily-(resp_maint+resp_growth+resp_hetero)-co2_fire) &
             &        *veget_max,dim=2)-cflux_prod_total-harvest_above)/1e3/one_day*contfrac
        CALL histwrite (hist_id_stomate_IPCC, "nbp", itime, &
-         vartmp, npts, hori_index)
+            vartmp, npts, hori_index)
        vartmp(:)=SUM(tot_bm_to_litter*veget_max,dim=2)/1e3/one_day*contfrac
        CALL histwrite (hist_id_stomate_IPCC, "fVegLitter", itime, &
-         vartmp, npts, hori_index)
+            vartmp, npts, hori_index)
        vartmp(:)=SUM(SUM(soilcarbon_input,dim=2)*veget_max,dim=2)/1e3/one_day*contfrac
        CALL histwrite (hist_id_stomate_IPCC, "fLitterSoil", itime, &
-         vartmp, npts, hori_index)
+            vartmp, npts, hori_index)
        vartmp(:)=SUM(biomass(:,:,ileaf)*veget_max,dim=2)/1e3*contfrac
        CALL histwrite (hist_id_stomate_IPCC, "cLeaf", itime, &
-         vartmp, npts, hori_index)
+            vartmp, npts, hori_index)
        vartmp(:)=SUM((biomass(:,:,isapabove)+biomass(:,:,iheartabove))*veget_max,dim=2)/1e3*contfrac
        CALL histwrite (hist_id_stomate_IPCC, "cWood", itime, &
-         vartmp, npts, hori_index)
+            vartmp, npts, hori_index)
        vartmp(:)=SUM(( biomass(:,:,iroot) + biomass(:,:,isapbelow) + biomass(:,:,iheartbelow) ) &
             &        *veget_max,dim=2)/1e3*contfrac
        CALL histwrite (hist_id_stomate_IPCC, "cRoot", itime, &
-         vartmp, npts, hori_index)
+            vartmp, npts, hori_index)
        vartmp(:)=SUM(( biomass(:,:,icarbres) + biomass(:,:,ifruit))*veget_max,dim=2)/1e3*contfrac
        CALL histwrite (hist_id_stomate_IPCC, "cMisc", itime, &
-         vartmp, npts, hori_index)
+            vartmp, npts, hori_index)
        vartmp(:)=SUM((litter(:,istructural,:,iabove)+litter(:,imetabolic,:,iabove))*veget_max,dim=2)/1e3*contfrac
        CALL histwrite (hist_id_stomate_IPCC, "cLitterAbove", itime, &
-         vartmp, npts, hori_index)
+            vartmp, npts, hori_index)
        vartmp(:)=SUM((litter(:,istructural,:,ibelow)+litter(:,imetabolic,:,ibelow))*veget_max,dim=2)/1e3*contfrac
        CALL histwrite (hist_id_stomate_IPCC, "cLitterBelow", itime, &
-         vartmp, npts, hori_index)
+            vartmp, npts, hori_index)
        vartmp(:)=SUM(carbon(:,iactive,:)*veget_max,dim=2)/1e3*contfrac
        CALL histwrite (hist_id_stomate_IPCC, "cSoilFast", itime, &
-         vartmp, npts, hori_index)
+            vartmp, npts, hori_index)
        vartmp(:)=SUM(carbon(:,islow,:)*veget_max,dim=2)/1e3*contfrac
        CALL histwrite (hist_id_stomate_IPCC, "cSoilMedium", itime, &
-         vartmp, npts, hori_index)
+            vartmp, npts, hori_index)
        vartmp(:)=SUM(carbon(:,ipassive,:)*veget_max,dim=2)/1e3*contfrac
        CALL histwrite (hist_id_stomate_IPCC, "cSoilSlow", itime, &
-         vartmp, npts, hori_index)
+            vartmp, npts, hori_index)
        DO j=1,nvm
           histvar(:,j)=veget_max(:,j)*contfrac(:)*100
        ENDDO
        CALL histwrite (hist_id_stomate_IPCC, "landCoverFrac", itime, &
-         histvar, npts*nvm, horipft_index)
-       vartmp(:)=(veget_max(:,3)+veget_max(:,6)+veget_max(:,8)+veget_max(:,9))*contfrac*100
+            histvar, npts*nvm, horipft_index)
+
+       ! >> DS to be modified for the externalisation
+!       vartmp(:)=(veget_max(:,3)+veget_max(:,6)+veget_max(:,8)+veget_max(:,9))*contfrac*100
+       vartmp(:)=zero
+       DO j=2,nvm
+          IF(is_deciduous(j)) THEN
+             vartmp(:) = vartmp(:) + veget_max(:,j)*contfrac*100
+          ENDIF
+       ENDDO
        CALL histwrite (hist_id_stomate_IPCC, "treeFracPrimDec", itime, &
-          vartmp, npts, hori_index)
-       vartmp(:)=(veget_max(:,2)+veget_max(:,4)+veget_max(:,5)+veget_max(:,7))*contfrac*100
+            vartmp, npts, hori_index)
+       !-
+!       vartmp(:)=(veget_max(:,2)+veget_max(:,4)+veget_max(:,5)+veget_max(:,7))*contfrac*100
+       vartmp(:)=zero
+       DO j=2,nvm
+          IF(is_evergreen(j)) THEN
+             vartmp(:) = vartmp(:) + veget_max(:,j)*contfrac*100
+          ENDIF
+       ENDDO
        CALL histwrite (hist_id_stomate_IPCC, "treeFracPrimEver", itime, &
-         vartmp, npts, hori_index)
-       vartmp(:)=(veget_max(:,10)+veget_max(:,12))*contfrac*100
+            vartmp, npts, hori_index)
+       !-
+!       vartmp(:)=(veget_max(:,10)+veget_max(:,12))*contfrac*100
+       vartmp(:)=zero
+       DO j=2,nvm
+          IF(is_c3(j)) THEN
+             vartmp(:) = vartmp(:) + veget_max(:,j)*contfrac*100
+          ENDIF
+       ENDDO
        CALL histwrite (hist_id_stomate_IPCC, "c3PftFrac", itime, &
-         vartmp, npts, hori_index)
-       vartmp(:)=(veget_max(:,11)+veget_max(:,13))*contfrac*100
+            vartmp, npts, hori_index)
+       !-
+ !      vartmp(:)=(veget_max(:,11)+veget_max(:,13))*contfrac*100
+       vartmp(:)=zero
+       DO j=2,nvm
+          IF(is_c4(j)) THEN
+             vartmp(:) = vartmp(:) + veget_max(:,j)*contfrac*100
+          ENDIF
+       ENDDO
        CALL histwrite (hist_id_stomate_IPCC, "c4PftFrac", itime, &
-         vartmp, npts, hori_index)
+            vartmp, npts, hori_index)
+       !>> End modif
+       
+
        vartmp(:)=SUM(resp_growth*veget_max,dim=2)/1e3/one_day*contfrac
        CALL histwrite (hist_id_stomate_IPCC, "rGrowth", itime, &
-         vartmp, npts, hori_index)
+            vartmp, npts, hori_index)
        vartmp(:)=SUM(resp_maint*veget_max,dim=2)/1e3/one_day*contfrac
        CALL histwrite (hist_id_stomate_IPCC, "rMaint", itime, &
-         vartmp, npts, hori_index)
+            vartmp, npts, hori_index)
        vartmp(:)=SUM(bm_alloc(:,:,ileaf)*veget_max,dim=2)/1e3/one_day*contfrac
        CALL histwrite (hist_id_stomate_IPCC, "nppLeaf", itime, &
-         vartmp, npts, hori_index)
+            vartmp, npts, hori_index)
        vartmp(:)=SUM(bm_alloc(:,:,isapabove)*veget_max,dim=2)/1e3/one_day*contfrac
        CALL histwrite (hist_id_stomate_IPCC, "nppWood", itime, &
-         vartmp, npts, hori_index)
+            vartmp, npts, hori_index)
        vartmp(:)=SUM(( bm_alloc(:,:,isapbelow) + bm_alloc(:,:,iroot) )*veget_max,dim=2)/1e3/one_day*contfrac
        CALL histwrite (hist_id_stomate_IPCC, "nppRoot", itime, &
-         vartmp, npts, hori_index)
+            vartmp, npts, hori_index)
 
        CALL histwrite (hist_id_stomate_IPCC, 'RESOLUTION_X', itime, &
Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/stomate_npp.f90
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/stomate_npp.f90	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/stomate_npp.f90	(revision 257)
@@ -144,5 +144,5 @@
        ! 1.1.1 soil levels
 
-       z_soil(0) = 0.
+       z_soil(0) = zero
        z_soil(1:nbdl) = diaglev(1:nbdl)
 
@@ -175,5 +175,6 @@
 
        ! 1.3.1 rpc is an integration constant such that the integral of the root profile is 1.
-       rpc(:) = 1. / ( 1. - EXP( -z_soil(nbdl) / rprof(:,j) ) )
+
+       rpc(:) = un / ( un - EXP( -z_soil(nbdl) / rprof(:,j) ) )
 
        ! 1.3.2 integrate over the nbdl levels
@@ -243,5 +244,5 @@
           coeff_maint(:,j,k) = &
                MAX( coeff_maint_zero(j,k) * &
-               ( 1. + slope(:) * (t_maint(:,k)-ZeroCelsius) ), zero )
+               ( un + slope(:) * (t_maint(:,k)-ZeroCelsius) ), zero )
 
        ENDDO
@@ -336,5 +337,5 @@
        resp_growth_part(:,:) = frac_growthresp * bm_alloc(:,j,:) / dt
 
-       bm_alloc(:,j,:) = ( 1. - frac_growthresp ) * bm_alloc(:,j,:)
+       bm_alloc(:,j,:) = ( un - frac_growthresp ) * bm_alloc(:,j,:)
 
        !
Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/stomate_phenology.f90
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/stomate_phenology.f90	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/stomate_phenology.f90	(revision 257)
@@ -163,5 +163,5 @@
     !
 
-    allow_initpheno(:,1) = .FALSE. ! Add 02/02/2011 correctio of MM for the 1.9.5-1 version
+    allow_initpheno(:,ibare_sechiba) = .FALSE. 
     DO j = 2,nvm
 
@@ -348,9 +348,9 @@
 
        WHERE ( age_reset(:) )
-          leaf_frac(:,j,1) = 1.0
+          leaf_frac(:,j,1) = un
        ENDWHERE
        DO m = 2, nleafages
           WHERE ( age_reset(:) )
-             leaf_frac(:,j,m) = 0.0
+             leaf_frac(:,j,m) = zero
           ENDWHERE
        ENDDO
@@ -360,5 +360,5 @@
        DO m = 1, nleafages
           WHERE ( age_reset(:) )
-             leaf_age(:,j,m) = 0.0
+             leaf_age(:,j,m) = zero
           ENDWHERE
        ENDDO
@@ -409,11 +409,7 @@
 
     ! signal to start putting leaves on
-    LOGICAL, DIMENSION(npts,nvm), INTENT(out)              :: begin_leaves
+    LOGICAL, DIMENSION(npts,nvm), INTENT(inout)              :: begin_leaves
 
     ! 0.3 local
-
-    ! moisture availability above which moisture tendency doesn't matter
-!    REAL(r_std), PARAMETER                                   :: moiavail_always_tree = 1.0
-!    REAL(r_std), PARAMETER                                   :: moiavail_always_grass = 0.6
 
     REAL(r_std)                                              :: moiavail_always
@@ -543,5 +539,5 @@
 
     ! signal to start putting leaves on
-    LOGICAL, DIMENSION(npts,nvm), INTENT(out)              :: begin_leaves
+    LOGICAL, DIMENSION(npts,nvm), INTENT(inout)              :: begin_leaves
 
     ! 0.3 local
@@ -679,5 +675,5 @@
 
     ! signal to start putting leaves on
-    LOGICAL, DIMENSION(npts,nvm), INTENT(out)              :: begin_leaves
+    LOGICAL, DIMENSION(npts,nvm), INTENT(inout)              :: begin_leaves
 
     ! 0.3 local
@@ -775,5 +771,4 @@
           gdd_crit(i) = pheno_gdd_crit(j,1) + tl(i)*pheno_gdd_crit(j,2) + &
                tl(i)*tl(i)*pheno_gdd_crit(j,3)
-
 
           IF ( ( gdd(i,j) .GE. gdd_crit(i) ) .AND. &
@@ -839,5 +834,5 @@
 
     ! signal to start putting leaves on
-    LOGICAL, DIMENSION(npts,nvm), INTENT(out)              :: begin_leaves
+    LOGICAL, DIMENSION(npts,nvm), INTENT(inout)              :: begin_leaves
 
     ! 0.3 local
@@ -986,5 +981,5 @@
 
     ! signal to start putting leaves on
-    LOGICAL, DIMENSION(npts,nvm), INTENT(out)              :: begin_leaves
+    LOGICAL, DIMENSION(npts,nvm), INTENT(inout)              :: begin_leaves
 
     ! 0.3 local
@@ -1084,5 +1079,5 @@
 
     ! signal to start putting leaves on
-    LOGICAL, DIMENSION(npts,nvm), INTENT(out)              :: begin_leaves
+    LOGICAL, DIMENSION(npts,nvm), INTENT(inout)              :: begin_leaves
 
     ! 0.3 local
Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/stomate_prescribe.f90
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/stomate_prescribe.f90	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/stomate_prescribe.f90	(revision 257)
@@ -19,5 +19,4 @@
   USE pft_parameters
   USE constantes
-
 
   IMPLICIT NONE
@@ -89,5 +88,5 @@
       ! only when the DGVM is not activated or agricultural PFT.
 
-      IF ( ( .NOT. control%ok_dgvm ) .OR. ( .NOT. natural(j) ) ) THEN
+      IF ( ( .NOT. control%ok_dgvm .AND. lpj_gap_const_mort ) .OR. ( .NOT. natural(j) ) ) THEN
 
         !
@@ -95,5 +94,5 @@
         !
 
-        cn_ind(:,j) = 0.0
+        cn_ind(:,j) = zero
 
         IF ( tree(j) ) THEN
@@ -103,9 +102,9 @@
           !
 
-          dia(:) = 0.0
+          dia(:) = zero
 
           DO i = 1, npts
 
-            IF ( veget_max(i,j) .GT. 0.0 ) THEN
+            IF ( veget_max(i,j) .GT. zero ) THEN
 
               ! 1.1.1 calculate total wood mass
@@ -128,5 +127,5 @@
 
                 dia(i) = ( woodmass_ind(i) / ( pipe_density * pi/4. * pipe_tune2 ) ) ** &
-                         ( 1. / ( 2. + pipe_tune3 ) )
+                         ( un / ( 2. + pipe_tune3 ) )
 
                 ! 1.1.5 crown area, provisional
@@ -149,5 +148,5 @@
 
                   dia(i) = ( woodmass_ind(i) / ( pipe_density * pi/4. * pipe_tune2 ) ) ** &
-                           ( 1. / ( 2. + pipe_tune3 ) )
+                           ( un / ( 2. + pipe_tune3 ) )
 
                   ! final crown area
@@ -176,6 +175,6 @@
           !
 
-          WHERE ( veget_max(:,j) .GT. 0.0 )
-            cn_ind(:,j) = 1.0
+          WHERE ( veget_max(:,j) .GT. zero )
+            cn_ind(:,j) = un
           ENDWHERE
 
@@ -186,5 +185,5 @@
         !
 
-        WHERE ( veget_max(:,j) .GT. 0.0 )
+        WHERE ( veget_max(:,j) .GT. zero )
 
           ind(:,j) = veget_max(:,j) / cn_ind(:,j)
@@ -192,5 +191,5 @@
         ELSEWHERE
 
-          ind(:,j) = 0.0
+          ind(:,j) = zero
 
         ENDWHERE
@@ -247,6 +246,6 @@
               IF ( pheno_model(j) .NE. 'none' ) THEN
 
-                biomass(i,j,ileaf) = 0.0
-                leaf_frac(i,j,1) = 0.0
+                biomass(i,j,ileaf) = zero
+                leaf_frac(i,j,1) = zero
 
               ENDIF
@@ -265,6 +264,6 @@
 
               ! set leaf age classes
-              leaf_frac(i,j,:) = 0.0
-              leaf_frac(i,j,1) = 1.0
+              leaf_frac(i,j,:) = zero
+              leaf_frac(i,j,1) = un
 
               ! set time since last beginning of growing season
@@ -279,5 +278,5 @@
             IF ( veget_max(i,j) .GT. min_stomate ) THEN
               PFTpresent(i,j) = .TRUE.
-              everywhere(i,j) = 1.
+              everywhere(i,j) = un
             ENDIF
 
Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/stomate_resp.f90
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/stomate_resp.f90	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/stomate_resp.f90	(revision 257)
@@ -95,5 +95,5 @@
        ! 1.1.1 soil levels
 
-       z_soil(0) = 0.
+       z_soil(0) = zero
        z_soil(1:nbdl) = diaglev(1:nbdl)
 
@@ -116,5 +116,6 @@
 
        ! 1.3.1 rpc is an integration constant such that the integral of the root profile is 1.
-       rpc(:) = 1. / ( 1. - EXP( -z_soil(nbdl) / rprof(:,j) ) )
+
+       rpc(:) = un / ( un - EXP( -z_soil(nbdl) / rprof(:,j) ) )
 
        ! 1.3.2 integrate over the nbdl levels
@@ -174,5 +175,5 @@
           coeff_maint(:,j,k) = &
                MAX( (coeff_maint_zero(j,k)*dt/one_day) * &
-               ( 1. + slope(:) * (t_maint_radia(:,k)-ZeroCelsius) ), zero )
+               ( un + slope(:) * (t_maint_radia(:,k)-ZeroCelsius) ), zero )
 
        ENDDO
@@ -214,7 +215,4 @@
 !!$                                 ( .3*lai(i,j) + 1.4 ) / lai(i,j)
 !!$                         ENDIF
-!!$                   resp_maint_part_radia(i,j,k) = coeff_maint(i,j,k) * biomass(i,j,k) * &
-!!$                        ( .3*lai(i,j) + 1.4*(1.-exp(-.5*lai(i,j))) ) / lai(i,j)
-
                    resp_maint_part_radia(i,j,k) = coeff_maint(i,j,k) * biomass(i,j,k) * &
                         ( maint_resp_min_vmax*lai(i,j) + maint_resp_coeff*(1.-exp(-ext_coeff(j)*lai(i,j))) ) / lai(i,j)
Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/stomate_season.f90
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/stomate_season.f90	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/stomate_season.f90	(revision 257)
@@ -174,15 +174,8 @@
     ! residence time of green tissue (years)
     REAL(r_std), DIMENSION(npts,nvm)                            :: green_age
-
-! ds 04/03    Old formulation for herbivores
-!!$    ! weights
-!!$    REAL(r_std), DIMENSION(npts)                            :: weighttot
-!!$    ! natural long-term leaf NPP ( gC/m**2/year)
-!!$    REAL(r_std), DIMENSION(npts)                            :: nlflong_nat
-!!$    ! residence time of green tissue (years)
-!!$    REAL(r_std), DIMENSION(npts)                            :: green_age
-
     ! herbivore consumption (gC/m**2/day)
     REAL(r_std), DIMENSION(npts)                            :: consumption
+    ! fraction of each gridcell occupied by natural vegetation
+    REAL(r_std), DIMENSION(npts)                            :: fracnat
 
     ! =========================================================================
@@ -225,5 +218,5 @@
 
        ! 1.2.1.1 "monthly"
-!MM PAS PARALLELISE!!
+       !MM PAS PARALLELISE!!
        IF ( ABS( SUM( moiavail_month(:,2:nvm) ) ) .LT. min_stomate ) THEN
 
@@ -277,5 +270,5 @@
 
        ! 1.2.3 "monthly" soil temperatures
-!MM PAS PARALLELISE!!
+       !MM PAS PARALLELISE!!
        IF ( ABS( SUM( tsoil_month(:,:) ) ) .LT. min_stomate ) THEN
 
@@ -464,5 +457,5 @@
     !         detect a beginning of the growing season by declaring it dormant
     !
-!NVMODIF
+    !NVMODIF
     DO j = 2,nvm
        WHERE ( ( gpp_week(:,j) .LT. min_gpp_allowed ) .OR. & 
@@ -470,9 +463,9 @@
             ( ( when_growthinit(:,j) .GT. 2.*one_year ) .AND. &
             ( biomass(:,j,icarbres) .GT. biomass(:,j,ileaf)*4. ) ) )
-!       WHERE ( ( gpp_week(:,j) .EQ. zero ) .OR. & 
-!            ( gpp_week(:,j) .LT. gppfrac_dormance * maxgppweek_lastyear(:,j) ) .OR. &
-!            ( ( when_growthinit(:,j) .GT. 2.*one_year ) .AND. &
-!            ( biomass(:,j,icarbres) .GT. biomass(:,j,ileaf)*4. ) ) )
-          
+       !       WHERE ( ( gpp_week(:,j) .EQ. zero ) .OR. & 
+       !            ( gpp_week(:,j) .LT. gppfrac_dormance * maxgppweek_lastyear(:,j) ) .OR. &
+       !            ( ( when_growthinit(:,j) .GT. 2.*one_year ) .AND. &
+       !            ( biomass(:,j,icarbres) .GT. biomass(:,j,ileaf)*4. ) ) )
+       
           time_lowgpp(:,j) = time_lowgpp(:,j) + dt
           
@@ -816,12 +809,55 @@
     !
 
+    IF(control%ok_dgvm ) THEN
+
+       fracnat(:) = un
+       DO j = 2,nvm
+          IF ( .NOT. natural(j) ) THEN
+             fracnat(:) = fracnat(:) - veget_max(:,j)
+          ENDIF
+       ENDDO
+
+    ENDIF
+
     IF ( control%ok_stomate ) THEN
-
-       DO j = 2,nvm
-          WHERE ( biomass(:,j,ileaf) .GT. lm_thisyearmax(:,j) )
-             lm_thisyearmax(:,j) = biomass(:,j,ileaf)
-          ENDWHERE
-       ENDDO
-
+       IF(control%ok_dgvm ) THEN
+          DO j=2,nvm
+
+             IF ( natural(j) .AND. control%ok_dgvm ) THEN
+
+                WHERE ( fracnat(:) .GT. min_stomate .AND. biomass(:,j,ileaf).GT. lm_lastyearmax(:,j)*0.75 )
+                   maxfpc_lastyear(:,j) = ( maxfpc_lastyear(:,j) * ( one_year/leaflife_tab(j)- dt ) + &
+                        veget(:,j) / fracnat(:) * dt ) / (one_year/leaflife_tab(j))
+                ENDWHERE
+                maxfpc_thisyear(:,j) = maxfpc_lastyear(:,j) ! just to initialise value
+
+             ENDIF
+
+!NV : correct initialization
+!!$             WHERE(biomass(:,j,ileaf).GT. lm_lastyearmax(:,j)*0.75)
+!!$                lm_lastyearmax(:,j) = ( lm_lastyearmax(:,j) * ( one_year/leaflife_tab(j)- dt ) + &
+!!$                     biomass(:,j,ileaf) * dt ) / (one_year/leaflife_tab(j))
+!!$             ENDWHERE
+!!$             lm_thisyearmax(:,j)=lm_lastyearmax(:,j) ! just to initialise value
+             WHERE (lm_thisyearmax(:,j) .GT. min_stomate)
+                WHERE(biomass(:,j,ileaf).GT. lm_thisyearmax(:,j)*0.75)
+                   lm_thisyearmax(:,j) = ( lm_thisyearmax(:,j) * ( one_year/leaflife_tab(j)- dt ) + &
+                        biomass(:,j,ileaf) * dt ) / (one_year/leaflife_tab(j))
+                ENDWHERE
+             ELSEWHERE
+                lm_thisyearmax(:,j) =biomass(:,j,ileaf)
+             ENDWHERE
+
+          ENDDO
+
+       ELSE
+
+          DO j = 2,nvm
+             WHERE ( biomass(:,j,ileaf) .GT. lm_thisyearmax(:,j) )
+                lm_thisyearmax(:,j) = biomass(:,j,ileaf)
+             ENDWHERE
+          ENDDO
+
+       ENDIF
     ELSE
 
@@ -851,12 +887,12 @@
        ! 21.1 replace old values
        !
-!NVMODIF
-      maxmoiavail_lastyear(:,:) = (maxmoiavail_lastyear(:,:)*(tau_climatology-1)+ maxmoiavail_thisyear(:,:))/tau_climatology
-      minmoiavail_lastyear(:,:) = (minmoiavail_lastyear(:,:)*(tau_climatology-1)+ minmoiavail_thisyear(:,:))/tau_climatology
-      maxgppweek_lastyear(:,:) =( maxgppweek_lastyear(:,:)*(tau_climatology-1)+ maxgppweek_thisyear(:,:))/tau_climatology
-!       maxmoiavail_lastyear(:,:) = maxmoiavail_thisyear(:,:)
-!       minmoiavail_lastyear(:,:) = minmoiavail_thisyear(:,:)
-!       maxgppweek_lastyear(:,:) = maxgppweek_thisyear(:,:)
-
+       !NVMODIF
+       maxmoiavail_lastyear(:,:) = (maxmoiavail_lastyear(:,:)*(tau_climatology-1)+ maxmoiavail_thisyear(:,:))/tau_climatology
+       minmoiavail_lastyear(:,:) = (minmoiavail_lastyear(:,:)*(tau_climatology-1)+ minmoiavail_thisyear(:,:))/tau_climatology
+       maxgppweek_lastyear(:,:) =( maxgppweek_lastyear(:,:)*(tau_climatology-1)+ maxgppweek_thisyear(:,:))/tau_climatology
+       !       maxmoiavail_lastyear(:,:) = maxmoiavail_thisyear(:,:)
+       !       minmoiavail_lastyear(:,:) = minmoiavail_thisyear(:,:)
+       !       maxgppweek_lastyear(:,:) = maxgppweek_thisyear(:,:)
+       
        gdd0_lastyear(:) = gdd0_thisyear(:)
 
@@ -909,16 +945,16 @@
        !        fpc_crit.
 
-       ! calculate the sum of maxfpc_lastyear
-       sumfpc_nat(:) = zero
-       DO j = 2,nvm
-          sumfpc_nat(:) = sumfpc_nat(:) + maxfpc_lastyear(:,j)
-       ENDDO
-
-       ! scale so that the new sum is fpc_crit
-       DO j = 2,nvm 
-          WHERE ( sumfpc_nat(:) .GT. fpc_crit )
-             maxfpc_lastyear(:,j) = maxfpc_lastyear(:,j) * (fpc_crit/sumfpc_nat(:))
-          ENDWHERE
-       ENDDO
+!!$       ! calculate the sum of maxfpc_lastyear
+!!$       sumfpc_nat(:) = zero
+!!$       DO j = 2,nvm
+!!$          sumfpc_nat(:) = sumfpc_nat(:) + maxfpc_lastyear(:,j)
+!!$       ENDDO
+!!$
+!!$       ! scale so that the new sum is fpc_crit
+!!$       DO j = 2,nvm 
+!!$          WHERE ( sumfpc_nat(:) .GT. fpc_crit )
+!!$             maxfpc_lastyear(:,j) = maxfpc_lastyear(:,j) * (fpc_crit/sumfpc_nat(:))
+!!$          ENDWHERE
+!!$       ENDDO
 
     ENDIF  ! EndOfYear
@@ -941,56 +977,4 @@
 !!$ nlflong_nat, green_age are pft-dependants
 
-!!$    nlflong_nat(:) = zero
-!!$    weighttot(:) = zero
-!!$    green_age(:) = zero
-!!$    !
-!!$    DO j = 2,nvm
-!!$       !
-!!$       IF ( natural(j) ) THEN
-!!$          !
-!!$          weighttot(:) = weighttot(:) + lm_lastyearmax(:,j)
-!!$          nlflong_nat(:) = nlflong_nat(:) + npp_longterm(:,j) * leaf_frac_hvc
-!!$          !
-!!$          IF ( pheno_model(j) .EQ. 'none' ) THEN
-!!$             green_age(:) = green_age(:) + green_age_ever * lm_lastyearmax(:,j)
-!!$          ELSE
-!!$             green_age(:) = green_age(:) + green_age_dec * lm_lastyearmax(:,j)
-!!$          ENDIF
-!!$          !
-!!$       ENDIF
-!!$       !
-!!$    ENDDO
-!!$    !
-!!$    WHERE ( weighttot(:) .GT. zero )
-!!$       green_age(:) = green_age(:) / weighttot(:)
-!!$    ELSEWHERE
-!!$       green_age(:) = 1.
-!!$    ENDWHERE
-!!$
-!!$    !
-!!$    ! 22.2 McNaughton et al. give herbivore consumption as a function of annual leaf NPP.
-!!$    !      The annual leaf NPP can give us an idea about the edible biomass:
-!!$    !
-!!$
-!!$    DO j = 2,nvm
-!!$       !
-!!$       IF ( natural(j) ) THEN
-!!$          !
-!!$          WHERE ( nlflong_nat(:) .GT. zero )
-!!$             consumption(:) = hvc1 * nlflong_nat(:) ** hvc2
-!!$             herbivores(:,j) = one_year * green_age(:) * nlflong_nat(:) / consumption(:)
-!!$          ELSEWHERE
-!!$             herbivores(:,j) = 100000.
-!!$          ENDWHERE
-!!$          !
-!!$       ELSE
-!!$          !
-!!$          herbivores(:,j) = 100000.
-!!$          !
-!!$       ENDIF
-!!$       !
-!!$    ENDDO
-!!$    herbivores(:,ibare_sechiba) = zero
-
     nlflong_nat(:,:) = zero
     weighttot(:,:) = zero
Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/stomate_soilcarbon.f90
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/stomate_soilcarbon.f90	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/stomate_soilcarbon.f90	(revision 257)
@@ -112,5 +112,4 @@
     frac_carb(:,islow,ipassive) = frac_carb_sp
 
-
     ! 1.1.1.3 from passive pool
 
@@ -118,5 +117,4 @@
     frac_carb(:,ipassive,iactive) = frac_carb_pa
     frac_carb(:,ipassive,islow) = frac_carb_ps
-
 
 
@@ -154,5 +152,5 @@
     !
 
-    resp_hetero_soil(:,:) = 0.0
+    resp_hetero_soil(:,:) = zero
 
     !
@@ -173,5 +171,5 @@
     !
 
-    frac_resp(:,:) = 1. - frac_carb(:,:,iactive) - frac_carb(:,:,islow) - &
+    frac_resp(:,:) = un - frac_carb(:,:,iactive) - frac_carb(:,:,islow) - &
          frac_carb(:,:,ipassive) 
 
@@ -191,9 +189,7 @@
              fluxtot(:,k) = dt/carbon_tau(k) * carbon(:,k,m) * &
                   control_moist(:,ibelow) * control_temp(:,ibelow)
-!!$   DS       ELSEIF ( PFT_name(m)=='          C3           agriculture' ) THEN
           ELSEIF ( (.NOT. natural(m)) .AND. (.NOT. is_c4(m)) ) THEN
              fluxtot(:,k) = dt/carbon_tau(k) * carbon(:,k,m) * &
                   control_moist(:,ibelow) * control_temp(:,ibelow) * flux_tot_coeff(1)
-!!$  DS         ELSEIF ( PFT_name(m)=='          C4           agriculture' ) THEN
           ELSEIF ( (.NOT. natural(m)) .AND. is_c4(m) ) THEN
              fluxtot(:,k) = dt/carbon_tau(k) * carbon(:,k,m) * &
Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/stomate_turnover.f90
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/stomate_turnover.f90	(revision 256)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/stomate_turnover.f90	(revision 257)
@@ -196,5 +196,5 @@
                tl(:)*tl(:) * senescence_temp(j,3)
 
-          WHERE ( ( biomass(:,j,ileaf) .GT. 0.0 ) .AND. &
+          WHERE ( ( biomass(:,j,ileaf) .GT. zero ) .AND. &
                ( leaf_meanage(:,j) .GT. min_leaf_age_for_senescence(j) ) .AND. &
                ( t2m_month(:) .LT. t_crit(:) ) .AND. ( t2m_week(:) .LT. t2m_month(:) ) )
@@ -215,5 +215,5 @@
                nosenescence_hum(j) )
 
-          WHERE ( ( biomass(:,j,ileaf) .GT. 0.0 ) .AND. &
+          WHERE ( ( biomass(:,j,ileaf) .GT. zero ) .AND. &
                ( leaf_meanage(:,j) .GT. min_leaf_age_for_senescence(j) ) .AND. &
                ( moiavail_week(:,j) .LT. moiavail_crit(:) ) )
@@ -240,5 +240,5 @@
 
              ! critical temperature for senescence may depend on long term annual mean temperature
-             WHERE ( ( biomass(:,j,ileaf) .GT. 0.0 ) .AND. &
+             WHERE ( ( biomass(:,j,ileaf) .GT. zero ) .AND. &
                   ( leaf_meanage(:,j) .GT. min_leaf_age_for_senescence(j) ) .AND. &
                   ( ( moiavail_week(:,j) .LT. moiavail_crit(:) ) .OR. &
@@ -319,8 +319,8 @@
              turnover(:,j,ifruit) = biomass(:,j,ifruit) * dt / turnover_time(:,j)
           ELSEWHERE
-             turnover(:,j,ileaf)=0.0
-             turnover(:,j,isapabove) =0.0
-             turnover(:,j,iroot) = 0.0
-             turnover(:,j,ifruit) =0.0
+             turnover(:,j,ileaf)= zero
+             turnover(:,j,isapabove) = zero
+             turnover(:,j,iroot) = zero
+             turnover(:,j,ifruit) = zero
           ENDWHERE
           biomass(:,j,ileaf) = biomass(:,j,ileaf) - turnover(:,j,ileaf)
@@ -364,5 +364,5 @@
 
           DO m = 1, nleafages
-             turnover_rate(:) =0 
+             turnover_rate(:) = zero
              WHERE ( leaf_age(:,j,m) .GT. leaf_age_crit(:,j)/2. )
 
@@ -454,5 +454,5 @@
              leaf_frac(:,j,m) = ( leaf_frac(:,j,m)*lm_old(:) + delta_lm(:,m) ) / biomass(:,j,ileaf)
           ELSEWHERE
-             leaf_frac(:,j,m) = 0.0
+             leaf_frac(:,j,m) = zero
           ENDWHERE
 
@@ -489,5 +489,5 @@
           ! check whether we shed the remaining leaves
 
-          WHERE ( ( biomass(:,j,ileaf) .GT. 0.0 ) .AND. senescence(:,j) .AND. &
+          WHERE ( ( biomass(:,j,ileaf) .GT. zero ) .AND. senescence(:,j) .AND. &
                ( biomass(:,j,ileaf) .LT. (lai_initmin(j) / 2.)/sla(j) )             )
 
@@ -498,12 +498,12 @@
              turnover(:,j,ifruit) = turnover(:,j,ifruit) + biomass(:,j,ifruit)
 
-             biomass(:,j,ileaf) = 0.0
-             biomass(:,j,iroot) = 0.0
-             biomass(:,j,ifruit) = 0.0
+             biomass(:,j,ileaf) = zero
+             biomass(:,j,iroot) = zero
+             biomass(:,j,ifruit) = zero
 
 
 
              ! reset leaf age
-             leaf_meanage(:,j) = 0.0
+             leaf_meanage(:,j) = zero
 
           ENDWHERE
@@ -519,5 +519,5 @@
           ! Shed the remaining leaves if LAI very low.
 
-          WHERE ( ( biomass(:,j,ileaf) .GT. 0.0 ) .AND. senescence(:,j) .AND. &
+          WHERE ( ( biomass(:,j,ileaf) .GT. zero ) .AND. senescence(:,j) .AND. &
                (  biomass(:,j,ileaf) .LT. (lai_initmin(j) / 2.)/sla(j) ))
 
@@ -529,13 +529,13 @@
              turnover(:,j,ifruit) = turnover(:,j,ifruit) + biomass(:,j,ifruit)
 
-             biomass(:,j,ileaf) = 0.0
-             biomass(:,j,isapabove) = 0.0
-             biomass(:,j,iroot) = 0.0
-             biomass(:,j,ifruit) = 0.0
+             biomass(:,j,ileaf) = zero
+             biomass(:,j,isapabove) = zero
+             biomass(:,j,iroot) = zero
+             biomass(:,j,ifruit) = zero
 
 
 
              ! reset leaf age
-             leaf_meanage(:,j) = 0.0
+             leaf_meanage(:,j) = zero
 
           ENDWHERE
@@ -551,6 +551,6 @@
           WHERE ( shed_rest(:) )
 
-             leaf_age(:,j,m) = 0.0
-             leaf_frac(:,j,m) = 0.0
+             leaf_age(:,j,m) = zero
+             leaf_frac(:,j,m) = zero
 
           ENDWHERE
@@ -679,5 +679,5 @@
              hw_new(:) = biomass(:,j,iheartabove) + biomass(:,j,iheartbelow)
 
-             WHERE ( hw_new(:) .GT. 0.0 )
+             WHERE ( hw_new(:) .GT. zero )
 
                 age(:,j) = age(:,j) * hw_old(:)/hw_new(:)
