Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/stomate_season.f90
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/stomate_season.f90	(revision 134)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_stomate/stomate_season.f90	(revision 135)
@@ -166,10 +166,21 @@
     ! sum of natural fpcs
     REAL(r_std), DIMENSION(npts)                            :: sumfpc_nat
+!!$ 01/03/2011 NVuichard, NViovy and DS : correcting herbivores : now  weighttot
+!!$ nlflong_nat, green_age are pft-dependants
     ! weights
-    REAL(r_std), DIMENSION(npts)                            :: weighttot
+    REAL(r_std), DIMENSION(npts,nvm)                            :: weighttot
     ! natural long-term leaf NPP ( gC/m**2/year)
-    REAL(r_std), DIMENSION(npts)                            :: nlflong_nat
+    REAL(r_std), DIMENSION(npts,nvm)                            :: nlflong_nat
     ! residence time of green tissue (years)
-    REAL(r_std), DIMENSION(npts)                            :: green_age
+    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
@@ -927,7 +938,62 @@
     !
 
-    nlflong_nat(:) = zero
-    weighttot(:) = zero
-    green_age(:) = zero
+!!$ 01/03/2011 NVuichard, NViovy and DS : correcting herbivory activity : now  weighttot
+!!$ 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
+    green_age(:,:) = zero
     !
     DO j = 2,nvm
@@ -935,11 +1001,11 @@
        IF ( natural(j) ) THEN
           !
-          weighttot(:) = weighttot(:) + lm_lastyearmax(:,j)
-          nlflong_nat(:) = nlflong_nat(:) + npp_longterm(:,j) * leaf_frac_hvc
+          weighttot(:,j) = lm_lastyearmax(:,j)
+          nlflong_nat(:,j) = npp_longterm(:,j) * leaf_frac_hvc
           !
           IF ( pheno_model(j) .EQ. 'none' ) THEN
-             green_age(:) = green_age(:) + green_age_ever * lm_lastyearmax(:,j)
+             green_age(:,j) = green_age_ever * lm_lastyearmax(:,j)
           ELSE
-             green_age(:) = green_age(:) + green_age_dec * lm_lastyearmax(:,j)
+             green_age(:,j) = green_age_dec * lm_lastyearmax(:,j)
           ENDIF
           !
@@ -948,8 +1014,8 @@
     ENDDO
     !
-    WHERE ( weighttot(:) .GT. zero )
-       green_age(:) = green_age(:) / weighttot(:)
+    WHERE ( weighttot(:,:) .GT. zero )
+       green_age(:,:) = green_age(:,:) / weighttot(:,:)
     ELSEWHERE
-       green_age(:) = 1.
+       green_age(:,:) = un
     ENDWHERE
 
@@ -963,7 +1029,7 @@
        IF ( natural(j) ) THEN
           !
-          WHERE ( nlflong_nat(:) .GT. zero )
-             consumption(:) = hvc1 * nlflong_nat(:) ** hvc2
-             herbivores(:,j) = one_year * green_age(:) * nlflong_nat(:) / consumption(:)
+          WHERE ( nlflong_nat(:,j) .GT. zero )
+             consumption(:) = hvc1 * nlflong_nat(:,j) ** hvc2
+             herbivores(:,j) = one_year * green_age(:,j) * nlflong_nat(:,j) / consumption(:)
           ELSEWHERE
              herbivores(:,j) = 100000.
