Index: /branches/ORCHIDEE_2_2/ORCHIDEE/src_sechiba/slowproc.f90
===================================================================
--- /branches/ORCHIDEE_2_2/ORCHIDEE/src_sechiba/slowproc.f90	(revision 6144)
+++ /branches/ORCHIDEE_2_2/ORCHIDEE/src_sechiba/slowproc.f90	(revision 6145)
@@ -1656,18 +1656,16 @@
 
 !! ================================================================================================================================
-!! SUBROUTINE   : slowproc_veget
-!!
-!>\BRIEF        Set small fractions to zero and normalize to keep the sum equal 1. Calucate veget and soiltile.
-!!
-!! DESCRIPTION  : Set small fractions to zero and normalize to keep the sum equal 1. Calucate veget and soiltile.
-!! (1) Set veget_max and frac_nobio for fraction smaller than min_vegfrac.
-!! (2) Calculate veget
-!! (3) Calculate totfrac_nobio
-!! (4) Calculate soiltile
-!! (5) Calculate fraclut
-!!
-!! RECENT CHANGE(S): None
-!!
-!! MAIN OUTPUT VARIABLE(S): :: frac_nobio, totfrac_nobio, veget_max, veget, soiltile, fraclut
+!! SUBROUTINE   : slowproc_veget_max_limit
+!!
+!>\BRIEF        Set small fractions of veget_max to zero and normalize to keep the sum equal 1
+!!
+!! DESCRIPTION  : Set small fractions of veget_max to zero and normalize to keep the sum equal 1
+!!
+!! RECENT CHANGE(S): The subroutine was previously a part of slowproc_veget,
+!!    but was separated to be called also from slowproc_readvegetmax in order
+!!    to have limited/normalized vegetation fractions right after its reading
+!!    from the file (added by V.Bastrikov, 15/06/2019)
+!!
+!! MAIN OUTPUT VARIABLE(S): :: frac_nobio, veget_max
 !!
 !! REFERENCE(S) : None
@@ -1677,5 +1675,5 @@
 !_ ================================================================================================================================
 
-  SUBROUTINE slowproc_veget (kjpindex, lai, frac_nobio, totfrac_nobio, veget_max, veget, soiltile, fraclut, nwdFraclut)
+  SUBROUTINE slowproc_veget_max_limit (kjpindex, frac_nobio, veget_max)
     !
     ! 0. Declarations
@@ -1683,5 +1681,4 @@
     ! 0.1 Input variables 
     INTEGER(i_std), INTENT(in)                             :: kjpindex    !! Domain size - terrestrial pixels only
-    REAL(r_std), DIMENSION(kjpindex,nvm), INTENT(in)       :: lai         !! PFT leaf area index (m^{2} m^{-2})
 
     ! 0.2 Modified variables 
@@ -1689,20 +1686,12 @@
     REAL(r_std), DIMENSION(kjpindex,nvm), INTENT(inout)    :: veget_max   !! Maximum fraction of vegetation type including none biological fraction (unitless)
 
-    ! 0.3 Output variables 
-    REAL(r_std), DIMENSION(kjpindex,nvm), INTENT(out)      :: veget       !! Fraction of pixel covered by PFT. Fraction accounts for none-biological land covers (unitless)
-    REAL(r_std),DIMENSION (kjpindex), INTENT (out)         :: totfrac_nobio
-    REAL(r_std), DIMENSION (kjpindex,nstm), INTENT(out)    :: soiltile     !! Fraction of each soil tile within vegtot (0-1, unitless)
-    REAL(r_std), DIMENSION (kjpindex,nlut), INTENT(out)    :: fraclut      !! Fraction of each landuse tile (0-1, unitless)
-    REAL(r_std), DIMENSION (kjpindex,nlut), INTENT(out)    :: nwdFraclut   !! Fraction of non-woody vegetation in each landuse tile (0-1, unitless)
-
     ! 0.4 Local scalar and varaiables 
-    INTEGER(i_std)                                         :: ji, jv, jst !! indices 
-    REAL(r_std)                                            :: SUMveg      
-
-!_ ================================================================================================================================
-    IF (printlev_loc > 8) WRITE(numout,*) 'Entering slowproc_veget'
-
-    !! 1. Set to zero fractions of frac_nobio and veget_max smaller than min_vegfrac
-    !!    Normalize to have the sum equal 1.
+    INTEGER(i_std)                                         :: ji, jv      !! indices 
+    REAL(r_std)                                            :: SUMveg      !! Total vegetation summed across PFTs
+
+!_ ================================================================================================================================
+    IF (printlev_loc >= 3) WRITE(numout,*) 'Entering slowproc_veget_max_limit'
+
+    !! Set to zero fractions of frac_nobio and veget_max smaller than min_vegfrac
     DO ji = 1, kjpindex
        IF ( SUM(frac_nobio(ji,:)) .LT. min_vegfrac ) THEN
@@ -1724,4 +1713,59 @@
     ENDDO
 
+    IF (printlev_loc >= 3) WRITE(numout,*) '  slowproc_veget_max_limit ended'
+
+  END SUBROUTINE slowproc_veget_max_limit
+
+
+!! ================================================================================================================================
+!! SUBROUTINE   : slowproc_veget
+!!
+!>\BRIEF        Set small fractions to zero and normalize to keep the sum equal 1. Calucate veget and soiltile.
+!!
+!! DESCRIPTION  : Set small fractions to zero and normalize to keep the sum equal 1. Calucate veget and soiltile.
+!! (1) Set veget_max and frac_nobio for fraction smaller than min_vegfrac.
+!! (2) Calculate veget
+!! (3) Calculate totfrac_nobio
+!! (4) Calculate soiltile
+!! (5) Calculate fraclut
+!!
+!! RECENT CHANGE(S): None
+!!
+!! MAIN OUTPUT VARIABLE(S): :: frac_nobio, totfrac_nobio, veget_max, veget, soiltile, fraclut
+!!
+!! REFERENCE(S) : None
+!!
+!! FLOWCHART    : None
+!! \n
+!_ ================================================================================================================================
+
+  SUBROUTINE slowproc_veget (kjpindex, lai, frac_nobio, totfrac_nobio, veget_max, veget, soiltile, fraclut, nwdFraclut)
+    !
+    ! 0. Declarations
+    !
+    ! 0.1 Input variables 
+    INTEGER(i_std), INTENT(in)                             :: kjpindex    !! Domain size - terrestrial pixels only
+    REAL(r_std), DIMENSION(kjpindex,nvm), INTENT(in)       :: lai         !! PFT leaf area index (m^{2} m^{-2})
+
+    ! 0.2 Modified variables 
+    REAL(r_std), DIMENSION(kjpindex,nnobio), INTENT(inout) :: frac_nobio  !! Fraction of the mesh which is covered by ice, lakes, ...
+    REAL(r_std), DIMENSION(kjpindex,nvm), INTENT(inout)    :: veget_max   !! Maximum fraction of vegetation type including none biological fraction (unitless)
+
+    ! 0.3 Output variables 
+    REAL(r_std), DIMENSION(kjpindex,nvm), INTENT(out)      :: veget       !! Fraction of pixel covered by PFT. Fraction accounts for none-biological land covers (unitless)
+    REAL(r_std),DIMENSION (kjpindex), INTENT (out)         :: totfrac_nobio
+    REAL(r_std), DIMENSION (kjpindex,nstm), INTENT(out)    :: soiltile     !! Fraction of each soil tile within vegtot (0-1, unitless)
+    REAL(r_std), DIMENSION (kjpindex,nlut), INTENT(out)    :: fraclut      !! Fraction of each landuse tile (0-1, unitless)
+    REAL(r_std), DIMENSION (kjpindex,nlut), INTENT(out)    :: nwdFraclut   !! Fraction of non-woody vegetation in each landuse tile (0-1, unitless)
+
+    ! 0.4 Local scalar and varaiables 
+    INTEGER(i_std)                                         :: ji, jv, jst !! indices 
+
+!_ ================================================================================================================================
+    IF (printlev_loc > 8) WRITE(numout,*) 'Entering slowproc_veget'
+
+    !! 1. Set to zero fractions of frac_nobio and veget_max smaller than min_vegfrac
+    !!    Normalize to have the sum equal 1.
+    CALL slowproc_veget_max_limit(kjpindex, frac_nobio, veget_max)
 
     !! 2. Calculate veget
@@ -2470,4 +2514,8 @@
        ENDIF
     ENDDO
+
+    !! Set to zero fractions of frac_nobio and veget_max smaller than min_vegfrac
+    !! Normalize to have the sum equal 1.
+    CALL slowproc_veget_max_limit(nbpt, frac_nobio_next, veget_next)
 
     ! Write diagnostics
