Index: /branches/ORCHIDEE_EXT/ORCHIDEE/src_sechiba/slowproc.f90
===================================================================
--- /branches/ORCHIDEE_EXT/ORCHIDEE/src_sechiba/slowproc.f90	(revision 142)
+++ /branches/ORCHIDEE_EXT/ORCHIDEE/src_sechiba/slowproc.f90	(revision 143)
@@ -510,4 +510,10 @@
     LOGICAL, PARAMETER                                 :: check = .FALSE.
     !
+    ! DS 15032011 add for replacing SUM(veget_max(ji,nvm-1:nvm 
+    REAL(r_std)    :: sum_veget_max
+    !
+
+
+    !
     ! 1 allocation
     !
@@ -970,31 +976,27 @@
                 ! set to 0 as well
              
- !               IF (agriculture) THEN
- !                 veget_max(:,2:nvm-2) = zero
-!                   DO ji = 1, kjpindex
- !                     veget_max(ji,1) = un - SUM(veget_max(ji,nvm-1:nvm)) &
-!                           - SUM(frac_nobio(ji,:))
-!                   ENDDO
-!                ELSE
-!                   veget_max(:,:) = zero
-!                   DO ji = 1, kjpindex
-!                      veget_max(ji,1) = un  - SUM(frac_nobio(ji,:))
-!                   ENDDO
-!                ENDIF
-
-!$$$ 25/10/10 :: Modif DS & NV :: attention garde t'on la masse de C !!!
+                !$$$ 25/10/10 :: Modif DS & NV :: attention garde t'on la masse de C !!!
+                ! Modif 15/03/2011
+
                 IF (agriculture) THEN
-                   DO j = 2, nvm
-                      WHERE( natural(:)) 
-                       veget_max (:,j) = zero
-                       ENDWHERE
-                   ENDDO
+                   DO jv=2,nvm
+                      IF (natural(jv)) THEN 
+                         veget_max(:,jv)=zero
+                      ELSE
+                         sum_veget_max = zero
+                         DO ji = 1, kjpindex
+                            ! we sum only on the indexes corresponding to the non_natural pfts
+                            sum_veget_max = sum_veget_max + veget_max(ji,jv)
+!                            veget_max(ji,1) = un - SUM(veget_max(ji,jv))-SUM(frac_nobio(ji,:))
+                         ENDDO
+                         veget_max(ji,1) = un - sum_veget_max - SUM(frac_nobio(ji,:))
+                      ENDIF
+                   ENDDO !- end loop nvm
                 ELSE
                    veget_max(:,:) = zero
+                   DO ji = 1, kjpindex
+                      veget_max(ji,1) = un  - SUM(frac_nobio(ji,:))
+                   ENDDO
                 ENDIF
-
-                DO ji = 1, kjpindex
-                   veget_max(ji,1) = un  -  SUM(veget_max(ji,2:nvm)) - SUM(frac_nobio(ji,:))
-                ENDDO
                 !
              ENDIF
@@ -1012,40 +1014,33 @@
                 ! set to 0 as well
                 
-             !   IF (agriculture) THEN
-             !      veget_max(:,2:nvm-2) = zero
-             !      DO ji = 1, kjpindex
-             !         veget_max(ji,1) = un - SUM(veget_max(ji,nvm-1:nvm)) &
-             !              - SUM(frac_nobio(ji,:))
-             !      ENDDO
-             !   ELSE
-             !      veget_max(:,:) = zero
-             !      DO ji = 1, kjpindex
-             !         veget_max(ji,1) = un  - SUM(frac_nobio(ji,:))
-             !      ENDDO
-            !    ENDIF
-                !
-!             ENDIF
-
-!$$$ 25/10/10 :: Modif DS & NV :: attention garde t'on la masse de C !!!
-               IF (agriculture) THEN
-                   DO j = 2, nvm
-                      WHERE( natural(:)) 
-                       veget_max (:,j) = zero
-                     ENDWHERE
-                   ENDDO
+                !$$$ 25/10/10 :: Modif DS & NV :: attention garde t'on la masse de C !!!
+                ! DS : Nouvelle correction 15/03/2011
+                IF (agriculture) THEN
+                   DO jv = 2, nvm
+                      IF (natural(jv)) THEN 
+                         veget_max(:,jv)=zero
+                      ELSE
+                         ! Add 15/03/2011
+                         sum_veget_max = zero
+                         DO ji = 1, kjpindex
+                            sum_veget_max = sum_veget_max + veget_max(ji,jv)
+                         ENDDO                            
+                         veget_max(ji,1) = un - sum_veget_max- SUM(frac_nobio(ji,:))   
+                      ENDIF
+                   ENDDO !- end loop nvm
                 ELSE
                    veget_max(:,:) = zero
-               ENDIF
-
-               DO ji = 1, kjpindex
-                  veget_max(ji,1) = un  -  SUM(veget_max(ji,2:nvm)) - SUM(frac_nobio(ji,:))
-               ENDDO
-            ENDIF
+                   DO ji = 1, kjpindex
+                      veget_max(ji,1) = un  - SUM(frac_nobio(ji,:))
+                   ENDDO
+                ENDIF
+                !
+             ENDIF
              !
           ENDIF
-          !
+             !
        ELSE
-          ! WITH restarts for vegetation and DGVM and NO AGRICULTURE
-          IF ( control%ok_dgvm  ) THEN
+             ! WITH restarts for vegetation and DGVM and NO AGRICULTURE
+             IF ( control%ok_dgvm  ) THEN
              !
              ! If we are dealing with dynamic vegetation then all
@@ -1063,9 +1058,9 @@
 !$$$ 25/10/10 :: Modif DS & NV :: attention garde t'on la masse de C !!!
              IF (.NOT. agriculture) THEN
-                DO j = 2, nvm  
+                DO jv = 2, nvm  
                    DO ji = 1, kjpindex
-                        IF ( .NOT. natural (j))  THEN
-                         veget_max(ji,1) = veget_max(ji,1) + veget_max(ji,j)
-                         veget_max(ji,j) = zero
+                        IF ( .NOT. natural (jv))  THEN
+                         veget_max(ji,1) = veget_max(ji,1) + veget_max(ji,jv)
+                         veget_max(ji,jv) = zero
                         ENDIF  
                    ENDDO
