Index: branches/ORCHIDEE_2_2/ORCHIDEE/src_stomate/stomate.f90
===================================================================
--- branches/ORCHIDEE_2_2/ORCHIDEE/src_stomate/stomate.f90	(revision 6160)
+++ branches/ORCHIDEE_2_2/ORCHIDEE/src_stomate/stomate.f90	(revision 6319)
@@ -430,8 +430,18 @@
                                                                          !! dimension(#pixels,0:100)
 !$OMP THREADPRIVATE(flux100)
+  REAL(r_std),ALLOCATABLE,SAVE,DIMENSION(:,:)    :: co2_flux             !! CO2 flux between atmosphere and biosphere
+                                                                         !! @tex $(gC m^{-2} one_day^{-1})$ @endtex
+!$OMP THREADPRIVATE(co2_flux)
   REAL(r_std),ALLOCATABLE,SAVE,DIMENSION(:)      :: fco2_lu              !! CO2 flux between atmosphere and biosphere from land-use 
                                                                          !! (without forest management)
                                                                          !! @tex $(gC m^{-2} one_day^{-1})$ @endtex
 !$OMP THREADPRIVATE(fco2_lu)
+  REAL(r_std),ALLOCATABLE,SAVE,DIMENSION(:)      :: fco2_wh              !! CO2 Flux to Atmosphere from Wood Harvesting (positive from atm to land)
+                                                                         !! @tex $(gC m^{-2} one_day^{-1})$ @endtex
+!$OMP THREADPRIVATE(fco2_wh)
+  REAL(r_std),ALLOCATABLE,SAVE,DIMENSION(:)      :: fco2_ha              !! CO2 Flux to Atmosphere from Crop Harvesting (positive from atm to land)
+                                                                         !! @tex $(gC m^{-2} one_day^{-1})$ @endtex
+!$OMP THREADPRIVATE(fco2_ha)
+
   REAL(r_std),ALLOCATABLE,SAVE,DIMENSION(:)      :: convflux             !! Release during first year following land cover change 
                                                                          !! (paper, burned, etc...) 
@@ -630,5 +640,6 @@
          contfrac,       totfrac_nobio,     clay,         temp_air,          &
          lai,            veget,             veget_max,                       &
-         co2_flux,       co2_to_bm_radia,   fco2_lu_out,  deadleaf_cover,  assim_param, temp_growth )
+         co2_to_bm_radia,deadleaf_cover,    assim_param,  temp_growth )
+
 
     IMPLICIT NONE
@@ -656,7 +667,6 @@
 
     !! 0.2 Output variables
-    REAL(r_std),DIMENSION(kjpindex,nvm),INTENT(out) :: co2_flux          !! CO2 flux between atmosphere and biosphere
+
     REAL(r_std),DIMENSION(kjpindex,nvm),INTENT(out) :: co2_to_bm_radia   !! virtual gpp flux between atmosphere and biosphere
-    REAL(r_std),DIMENSION(kjpindex),INTENT(out)     :: fco2_lu_out       !! CO2 flux between atmosphere and biosphere from land-use (without forest management)  
     REAL(r_std),DIMENSION(kjpindex),INTENT(out)     :: deadleaf_cover    !! Fraction of soil covered by dead leaves (unitless)
     REAL(r_std),DIMENSION(kjpindex,nvm,npco2),INTENT(out) :: assim_param !! min+max+opt temperatures (K) & vmax for photosynthesis  
@@ -764,5 +774,4 @@
     
     !! 1.4.3.1 Read initial values for STOMATE's variables from the _restart_ file
-    co2_flux(:,:) = zero
 
     ! Get values from _restart_ file. Note that only ::kjpindex, ::index, ::lalo 
@@ -795,5 +804,5 @@
          litterpart, litter, dead_leaves, &
          carbon, lignin_struc,turnover_time,&
-         fco2_lu,&
+         co2_flux, fco2_lu, fco2_wh, fco2_ha, &
          prod10,prod100,flux10, flux100, &
          convflux, cflux_prod10, cflux_prod100, &
@@ -807,7 +816,4 @@
          MatrixV, VectorU, previous_stock, current_stock, assim_param)
     
-    ! Copy module variable fco2_lu into local variable to allow it to be in the argument output list of the subroutine
-    fco2_lu_out(:)=fco2_lu(:)
-
     !! 1.4.5 Check time step
        
@@ -1160,6 +1166,6 @@
 !!
 !! MAIN OUTPUT VARIABLE(S): deadleaf_cover, assim_param, lai, height, veget, 
-!! veget_max, resp_maint, 
-!! resp_hetero,resp_growth, co2_flux, fco2_lu_out.
+!! veget_max, resp_maint, resp_hetero, resp_growth, 
+!! co2_flux_out, fco2_lu_out, fco2_wh_out, fco2_ha_out.
 !!
 !! REFERENCES	: 
@@ -1183,5 +1189,6 @@
        &  veget_max_new, woodharvest, totfrac_nobio_new, fraclut, &
        &  rest_id_stom, hist_id_stom, hist_id_stom_IPCC, &
-       &  co2_flux, fco2_lu_out, resp_maint,resp_hetero,resp_growth,co2_to_bm_radia,temp_growth)
+       &  co2_flux_out, fco2_lu_out, fco2_wh_out, fco2_ha_out, &
+       &  resp_maint, resp_hetero, resp_growth, co2_to_bm_radia, temp_growth)
     
     IMPLICIT NONE
@@ -1236,10 +1243,11 @@
     !! 0.2 Output variables
 
-    REAL(r_std),DIMENSION(kjpindex,nvm),INTENT(out) :: co2_flux          !! CO2 flux between atmosphere and biosphere per 
+    REAL(r_std),DIMENSION(kjpindex,nvm),INTENT(out) :: co2_flux_out      !! CO2 flux between atmosphere and biosphere per 
                                                                          !! average ground area 
                                                                          !! @tex $(gC m^{-2} dt_sechiba^{-1})$ @endtex  
     REAL(r_std),DIMENSION(kjpindex),INTENT(out)     :: fco2_lu_out       !! CO2 flux between atmosphere and biosphere from 
-                                                                         !! land-use (without forest management)  
-                                                                         !! @tex $(gC m^{-2} dt_stomate^{-1})$ @endtex  
+                                                                         !! land-use (without forest management) (gC/m2/dt_stomate)
+    REAL(r_std),DIMENSION(kjpindex),INTENT(out)     :: fco2_wh_out       !! CO2 Flux to Atmosphere from Wood Harvesting (gC/m2/dt_stomate)
+    REAL(r_std),DIMENSION(kjpindex),INTENT(out)     :: fco2_ha_out       !! CO2 Flux to Atmosphere from Crop Harvesting (gC/m2/dt_stomate)
     REAL(r_std),DIMENSION(kjpindex,nvm),INTENT(out) :: resp_maint        !! Maitenance component of autotrophic respiration in 
                                                                          !! @tex $(gC m^{-2} dt_stomate^{-1})$ @endtex 
@@ -1599,13 +1607,16 @@
             &             Tseason, Tmin_spring_time, begin_leaves, onset_date)
        
+
        !! 5.3.2 Calculate the total CO2 flux from land use change
-       fco2_lu(:) = convflux(:) &
-            &             + cflux_prod10(:)  &
-            &             + cflux_prod100(:) &
-            &             + harvest_above(:) &
-            &             + convflux_harvest(:) &
-            &             + cflux_prod10_harvest(:)  &
-            &             + cflux_prod100_harvest(:)
+
+       ! CO2 from land-use change
+       fco2_lu(:) = convflux(:) + cflux_prod10(:) + cflux_prod100(:) 
+
+       ! CO2 from wood harvest
+       fco2_wh(:) = convflux_harvest(:) + cflux_prod10_harvest(:) + cflux_prod100_harvest(:)
        
+       ! CO2 from harvest
+       fco2_ha(:) = harvest_above(:) 
+              
        !! 5.4 Calculate veget and veget_max
        veget_max(:,:) = zero 
@@ -1758,6 +1769,10 @@
        CALL xios_orchidee_send_field("rhSoil",SUM(resp_hetero_soil*veget_cov_max,dim=2)/1e3)
        CALL xios_orchidee_send_field("rhLitter",SUM(resp_hetero_litter*veget_cov_max,dim=2)/1e3)
-       
-
+
+       ! Calculate co2_flux as (-1)*nep_daily*veget_cov_max. 
+       ! This variable will be used for the coupling to LMDZ for ESM configuration.
+       co2_flux(:,:) = (resp_hetero_d(:,:) + resp_maint_d(:,:) + resp_growth_d(:,:) &
+            + co2_fire(:,:) -  gpp_daily(:,:))*veget_cov_max
+      
        IF ( hist_id_stom_IPCC > 0 ) THEN
           vartmp(:) = SUM(nep_daily*veget_cov_max,dim=2)/1e3/one_day*contfrac
@@ -1846,7 +1861,4 @@
   !! 6. Outputs from Stomate
 
-    ! co2_flux receives a value from STOMATE only if STOMATE is activated.
-    ! Otherwise, the calling hydrological module must do this itself.
-
     !! 6.1 Respiration and fluxes
     resp_maint(:,:) = resp_maint_radia(:,:)*veget_cov_max(:,:)
@@ -1856,19 +1868,12 @@
     resp_hetero(:,:) = resp_hetero_radia(:,:)*veget_cov_max(:,:)
     
-    !! 6.2 Derived CO2 fluxes
-    ! CO2 flux in gC m^{-2} s^{-1} (positive towards the atmosphere) is sum of:
-    ! (1) heterotrophic respiration from ground + (2) maintenance respiration 
-    ! from the plants + (3) growth respiration from the plants + (4) co2 
-    ! emissions from fire - (5) co2 taken up in the DGVM to establish 
-    ! saplings - (6) co2 taken up by photosyntyhesis
-    ! co2_to_bm is not included here as it is already encounted in the gpp
-    co2_flux(:,:) = resp_hetero(:,:) + resp_maint(:,:) + resp_growth(:,:) &
-         & + co2_fire(:,:)*veget_cov_max(:,:)*dt_sechiba/one_day &
-         & - gpp(:,:)
-    
     temp_growth(:)=t2m_month(:)-tp_00 
 
-    ! Copy module variable fco2_lu into local variable to allow it to be in the argument output list of the subroutine
+
+    ! Copy module variables into local variables to allow them to be in the argument output list of the subroutine
+    co2_flux_out(:,:)=co2_flux(:,:)
     fco2_lu_out(:)=fco2_lu(:)
+    fco2_wh_out(:)=fco2_wh(:)
+    fco2_ha_out(:)=fco2_ha(:)
 
 
@@ -2123,5 +2128,5 @@
          litterpart, litter, dead_leaves, &
          carbon, lignin_struc,turnover_time,&
-         fco2_lu,&
+         co2_flux, fco2_lu, fco2_wh, fco2_ha, &
          prod10,prod100,flux10, flux100, &
          convflux, cflux_prod10, cflux_prod100, &
@@ -3080,8 +3085,29 @@
     ENDIF
 
+    ALLOCATE (co2_flux(kjpindex,nvm), stat=ier)
+    l_error = l_error .OR. (ier /= 0)
+    IF (l_error) THEN
+       WRITE(numout,*) 'Memory allocation error for co2_flux. We stop. We need kjpindex words',kjpindex,nvm
+       STOP 'stomate_init'
+    ENDIF
+
     ALLOCATE (fco2_lu(kjpindex), stat=ier)
     l_error = l_error .OR. (ier /= 0)
     IF (l_error) THEN
        WRITE(numout,*) 'Memory allocation error for fco2_lu. We stop. We need kjpindex words',kjpindex
+       STOP 'stomate_init'
+    ENDIF
+
+    ALLOCATE (fco2_wh(kjpindex), stat=ier)
+    l_error = l_error .OR. (ier /= 0)
+    IF (l_error) THEN
+       WRITE(numout,*) 'Memory allocation error for fco2_wh. We stop. We need kjpindex words',kjpindex
+       STOP 'stomate_init'
+    ENDIF
+
+    ALLOCATE (fco2_ha(kjpindex), stat=ier)
+    l_error = l_error .OR. (ier /= 0)
+    IF (l_error) THEN
+       WRITE(numout,*) 'Memory allocation error for fco2_ha. We stop. We need kjpindex words',kjpindex
        STOP 'stomate_init'
     ENDIF
@@ -3594,5 +3620,8 @@
     IF ( ALLOCATED (horip11_index)) DEALLOCATE (horip11_index)
     IF ( ALLOCATED (horip101_index)) DEALLOCATE (horip101_index)
+    IF ( ALLOCATED (co2_flux)) DEALLOCATE (co2_flux)
     IF ( ALLOCATED (fco2_lu)) DEALLOCATE (fco2_lu)
+    IF ( ALLOCATED (fco2_wh)) DEALLOCATE (fco2_wh)
+    IF ( ALLOCATED (fco2_ha)) DEALLOCATE (fco2_ha)
     IF ( ALLOCATED (prod10)) DEALLOCATE (prod10)
     IF ( ALLOCATED (prod100)) DEALLOCATE (prod100)
