Index: LMDZ4/trunk/libf/phylmd/cpl_mod.F90
===================================================================
--- LMDZ4/trunk/libf/phylmd/cpl_mod.F90	(revision 1146)
+++ LMDZ4/trunk/libf/phylmd/cpl_mod.F90	(revision 1279)
@@ -39,5 +39,5 @@
 !*************************************************************************************
 ! variable for coupling period
-  INTEGER, SAVE                             :: nexca
+  INTEGER, SAVE :: nexca
   !$OMP THREADPRIVATE(nexca)
 
@@ -47,10 +47,12 @@
   REAL, ALLOCATABLE, DIMENSION(:,:), SAVE   :: cpl_snow, cpl_evap, cpl_tsol
   !$OMP THREADPRIVATE(cpl_snow,cpl_evap,cpl_tsol)
-  REAL, ALLOCATABLE, DIMENSION(:,:), SAVE   :: cpl_fder, cpl_albe, cpl_taux
-  !$OMP THREADPRIVATE(cpl_fder,cpl_albe,cpl_taux)
+  REAL, ALLOCATABLE, DIMENSION(:,:), SAVE   :: cpl_fder, cpl_albe, cpl_taux, cpl_tauy
+  !$OMP THREADPRIVATE(cpl_fder,cpl_albe,cpl_taux,cpl_tauy)
   REAL, ALLOCATABLE, DIMENSION(:,:), SAVE   :: cpl_windsp
   !$OMP THREADPRIVATE(cpl_windsp)
-  REAL, ALLOCATABLE, DIMENSION(:,:), SAVE   :: cpl_tauy
-  !$OMP THREADPRIVATE(cpl_tauy)
+  REAL, ALLOCATABLE, DIMENSION(:,:), SAVE   :: cpl_taumod
+  !$OMP THREADPRIVATE(cpl_taumod)
+  REAL, ALLOCATABLE, DIMENSION(:,:), SAVE   :: cpl_atm_co2
+  !$OMP THREADPRIVATE(cpl_atm_co2)
   REAL, ALLOCATABLE, DIMENSION(:,:), SAVE   :: cpl_rriv2D, cpl_rcoa2D, cpl_rlic2D
   !$OMP THREADPRIVATE(cpl_rriv2D,cpl_rcoa2D,cpl_rlic2D)
@@ -67,5 +69,6 @@
   REAL, ALLOCATABLE, DIMENSION(:,:), SAVE   :: read_u0, read_v0 ! ocean surface current
   !$OMP THREADPRIVATE(read_u0,read_v0)
-  
+  REAL, ALLOCATABLE, DIMENSION(:,:), SAVE   :: read_co2     ! ocean co2 flux 
+  !$OMP THREADPRIVATE(read_co2)
   INTEGER, ALLOCATABLE, DIMENSION(:), SAVE  :: unity
   !$OMP THREADPRIVATE(unity)
@@ -82,12 +85,11 @@
   REAL, ALLOCATABLE, DIMENSION(:,:,:), SAVE :: cpl_taux2D, cpl_tauy2D
   !$OMP THREADPRIVATE(cpl_taux2D, cpl_tauy2D)
+  REAL, ALLOCATABLE, DIMENSION(:,:,:), SAVE :: cpl_taumod2D
+  !$OMP THREADPRIVATE(cpl_taumod2D)
   REAL, ALLOCATABLE, DIMENSION(:,:), SAVE   :: cpl_windsp2D
   !$OMP THREADPRIVATE(cpl_windsp2D)
-  
-! variable for OPENMP parallelisation
-
-  INTEGER,ALLOCATABLE,DIMENSION(:),SAVE :: knon_omp
-  REAL,ALLOCATABLE,DIMENSION(:,:),SAVE ::  buffer_omp
-  
+  REAL, ALLOCATABLE, DIMENSION(:,:), SAVE   :: cpl_atm_co22D
+  !$OMP THREADPRIVATE(cpl_atm_co22D)
+
 CONTAINS
 !
@@ -95,4 +97,5 @@
 !
   SUBROUTINE cpl_init(dtime, rlon, rlat)
+    USE carbon_cycle_mod, ONLY : carbon_cycle_cpl, fco2_ocn_day
 
     INCLUDE "dimensions.h"
@@ -160,7 +163,9 @@
     ALLOCATE(cpl_taux(klon,2), stat = error)
     sum_error = sum_error + error
+    ALLOCATE(cpl_tauy(klon,2), stat = error)
+    sum_error = sum_error + error
     ALLOCATE(cpl_windsp(klon,2), stat = error)
     sum_error = sum_error + error
-    ALLOCATE(cpl_tauy(klon,2), stat = error)
+    ALLOCATE(cpl_taumod(klon,2), stat = error)
     sum_error = sum_error + error
     ALLOCATE(cpl_rriv2D(iim,jj_nb), stat=error)
@@ -178,9 +183,19 @@
     ALLOCATE(read_alb_sic(iim, jj_nb), stat = error)
     sum_error = sum_error + error
-
     ALLOCATE(read_u0(iim, jj_nb), stat = error)
     sum_error = sum_error + error
     ALLOCATE(read_v0(iim, jj_nb), stat = error)
     sum_error = sum_error + error
+
+    IF (carbon_cycle_cpl) THEN
+       ALLOCATE(read_co2(iim, jj_nb), stat = error)
+       sum_error = sum_error + error
+       ALLOCATE(cpl_atm_co2(klon,2), stat = error)
+       sum_error = sum_error + error
+
+! Allocate variable in carbon_cycle_mod
+       ALLOCATE(fco2_ocn_day(klon), stat = error)
+       sum_error = sum_error + error
+    END IF
 
     IF (sum_error /= 0) THEN
@@ -196,9 +211,4 @@
     ENDDO
 
-!    cpl_sols = 0.   ; cpl_nsol = 0.  ; cpl_rain = 0.   ; cpl_snow = 0.
-!    cpl_evap = 0.   ; cpl_tsol = 0.  ; cpl_fder = 0.   ; cpl_albe = 0.
-!    cpl_taux = 0.   ; cpl_tauy = 0.  ; cpl_rriv2D = 0. ; cpl_rcoa2D = 0.
-!    cpl_rlic2D = 0. ; cpl_windsp = 0.
-
 !*************************************************************************************
 ! Initialize coupling
@@ -207,7 +217,5 @@
     idtime = INT(dtime)
 #ifdef CPP_COUPLE
-!$OMP MASTER    
     CALL inicma
-!$OMP END MASTER
 #endif
 
@@ -237,7 +245,9 @@
        CALL histdef(nidct, 'tmp_lat','tmp_lat', &
             "-",iim, jjm+1, nhoridct, 1, 1, 1, -99, 32, "inst", dtime,dtime)
-       DO jf=1,jpflda2o1 + jpflda2o2
-          CALL histdef(nidct, cl_writ(jf),cl_writ(jf), &
-               "-",iim, jjm+1, nhoridct, 1, 1, 1, -99, 32, "inst", dtime,dtime)
+       DO jf=1,maxsend
+         IF (infosend(i)%action) THEN
+             CALL histdef(nidct, infosend(i)%name ,infosend(i)%name , &
+                "-",iim, jjm+1, nhoridct, 1, 1, 1, -99, 32, "inst", dtime,dtime)
+         ENDIF
        END DO
        CALL histend(nidct)
@@ -248,7 +258,9 @@
             0,zjulian,dtime,nhoridcs,nidcs) 
 ! no vertical axis
-       DO jf=1,jpfldo2a
-          CALL histdef(nidcs, cl_read(jf),cl_read(jf), &
-               "-",iim, jjm+1, nhoridcs, 1, 1, 1, -99, 32, "inst", dtime,dtime)
+       DO jf=1,maxrecv
+         IF (inforecv(i)%action) THEN
+             CALL histdef(nidcs,inforecv(i)%name ,inforecv(i)%name , &
+                "-",iim, jjm+1, nhoridcs, 1, 1, 1, -99, 32, "inst", dtime,dtime)
+         ENDIF
        END DO
        CALL histend(nidcs)
@@ -256,12 +268,4 @@
 
     ENDIF    ! is_sequential
-    
-! OPENMP Initialization
-
-!$OMP MASTER
-  ALLOCATE(knon_omp(0:omp_size-1)) 
-  ALLOCATE(buffer_omp(klon_mpi,0:omp_size-1))       
-!$OMP END MASTER
-!$OMP BARRIER
     
   END SUBROUTINE cpl_init
@@ -278,5 +282,6 @@
     USE surface_data
     USE phys_state_var_mod, ONLY : rlon, rlat
-
+    USE carbon_cycle_mod, ONLY : carbon_cycle_cpl
+    
     INCLUDE "indicesol.h"
     INCLUDE "temps.h"
@@ -300,5 +305,5 @@
     CHARACTER(len = 80)                     :: abort_message
     REAL, DIMENSION(klon)                   :: read_sic1D
-    REAL, DIMENSION(iim,jj_nb,jpfldo2a)     :: tab_read_flds
+    REAL, DIMENSION(iim,jj_nb,maxrecv)      :: tab_read_flds
     REAL, DIMENSION(klon,nbsrf)             :: pctsrf_old
     REAL, DIMENSION(klon_mpi)               :: rlon_mpi, rlat_mpi
@@ -314,5 +319,5 @@
     is_modified=.FALSE.
 
-! Check if right moment to recevie from coupler
+! Check if right moment to receive from coupler
     IF (MOD(itime, nexca) == 1) THEN
        is_modified=.TRUE.
@@ -329,6 +334,8 @@
           ndexcs(:) = 0
           itau_w = itau_phy + itime
-          DO i = 1, jpfldo2a
-             CALL histwrite(nidcs,cl_read(i),itau_w,tab_read_flds(:,:,i),iim*(jjm+1),ndexcs)
+          DO i = 1, maxrecv
+            IF (inforecv(i)%action) THEN
+                CALL histwrite(nidcs,inforecv(i)%name,itau_w,tab_read_flds(:,:,i),iim*(jjm+1),ndexcs)
+            ENDIF
           END DO
        ENDIF
@@ -337,8 +344,8 @@
 ! Save each field in a 2D array. 
 !$OMP MASTER
-       read_sst(:,:)     = tab_read_flds(:,:,1)  ! Sea surface temperature
-       read_sic(:,:)     = tab_read_flds(:,:,2)  ! Sea ice concentration
-       read_alb_sic(:,:) = tab_read_flds(:,:,3)  ! Albedo at sea ice
-       read_sit(:,:)     = tab_read_flds(:,:,4)  ! Sea ice temperature
+       read_sst(:,:)     = tab_read_flds(:,:,idr_sisutw)  ! Sea surface temperature
+       read_sic(:,:)     = tab_read_flds(:,:,idr_icecov)  ! Sea ice concentration
+       read_alb_sic(:,:) = tab_read_flds(:,:,idr_icealw)  ! Albedo at sea ice
+       read_sit(:,:)     = tab_read_flds(:,:,idr_icetem)  ! Sea ice temperature
 !$OMP END MASTER
 
@@ -354,12 +361,19 @@
 ! Transform the currents from cartesian to spheric coordinates
 ! tmp_r0 should be zero
-          CALL geo2atm(iim, jj_nb, tab_read_flds(:,:,5), tab_read_flds(:,:,6), tab_read_flds(:,:,7), &
+          CALL geo2atm(iim, jj_nb, tab_read_flds(:,:,idr_curenx), &
+             tab_read_flds(:,:,idr_cureny), tab_read_flds(:,:,idr_curenz), &
                tmp_lon, tmp_lat, &
                read_u0(:,:), read_v0(:,:), tmp_r0(:,:))
 !$OMP END MASTER
 
-       ELSE
+      ELSE
           read_u0(:,:) = 0.
           read_v0(:,:) = 0.
+      ENDIF
+
+       IF (carbon_cycle_cpl) THEN
+!$OMP MASTER
+           read_co2(:,:) = tab_read_flds(:,:,idr_oceco2) ! CO2 flux
+!$OMP END MASTER
        ENDIF
 
@@ -374,4 +388,5 @@
        DO i = 1, klon
           ! treatment only of points with ocean and/or seaice
+          ! old land-ocean mask can not be changed
           IF (pctsrf_old(i,is_oce) + pctsrf_old(i,is_sic) > 0.) THEN
              pctsrf(i,is_sic) = (pctsrf_old(i,is_oce) + pctsrf_old(i,is_sic)) &
@@ -396,4 +411,5 @@
 ! The temperature is transformed into 1D array with valid points from index 1 to knon.
 !
+    USE carbon_cycle_mod, ONLY : carbon_cycle_cpl, fco2_ocn_day
     INCLUDE "indicesol.h"
 
@@ -411,6 +427,7 @@
 ! Local variables
 !*************************************************************************************
-    INTEGER               :: i
-    REAL, DIMENSION(klon) :: sic_new
+    INTEGER                  :: i
+    INTEGER, DIMENSION(klon) :: index
+    REAL, DIMENSION(klon)    :: sic_new
 
 !*************************************************************************************
@@ -422,4 +439,16 @@
     CALL cpl2gath(read_u0, u0_new, knon, knindex)
     CALL cpl2gath(read_v0, v0_new, knon, knindex)
+
+!*************************************************************************************
+! Transform read_co2 into uncompressed 1D variable fco2_ocn_day added directly in 
+! the module carbon_cycle_mod
+!
+!*************************************************************************************
+    IF (carbon_cycle_cpl) THEN
+       DO i=1,klon
+          index(i)=i
+       END DO
+       CALL cpl2gath(read_co2, fco2_ocn_day, klon, index)
+    END IF
 
 !*************************************************************************************
@@ -499,4 +528,5 @@
 ! (it is done in cpl_send_seaice_fields).
 !
+    USE carbon_cycle_mod, ONLY : carbon_cycle_cpl, co2_send
     INCLUDE "indicesol.h"
     INCLUDE "dimensions.h"
@@ -543,4 +573,6 @@
        cpl_tauy(1:knon,cpl_index) = 0.0
        cpl_windsp(1:knon,cpl_index) = 0.0
+       cpl_taumod(1:knon,cpl_index) = 0.0
+       IF (carbon_cycle_cpl) cpl_atm_co2(1:knon,cpl_index) = 0.0
     ENDIF
        
@@ -571,6 +603,13 @@
             tauy(ig)        / FLOAT(nexca)      
        cpl_windsp(ig,cpl_index) = cpl_windsp(ig,cpl_index) + &
-            windsp(ig)      / FLOAT(nexca) 
-    ENDDO
+            windsp(ig)      / FLOAT(nexca)
+       cpl_taumod(ig,cpl_index) =   cpl_taumod(ig,cpl_index) + &
+          SQRT ( taux(ig)*taux(ig)+tauy(ig)*tauy(ig) ) / FLOAT (nexca)
+
+       IF (carbon_cycle_cpl) THEN
+          cpl_atm_co2(ig,cpl_index) = cpl_atm_co2(ig,cpl_index) + &
+               co2_send(knindex(ig))/ FLOAT(nexca) 
+       END IF
+     ENDDO
 
 !*************************************************************************************
@@ -606,5 +645,12 @@
           ALLOCATE(cpl_windsp2D(iim,jj_nb), stat=error)
           sum_error = sum_error + error
+          ALLOCATE(cpl_taumod2D(iim,jj_nb,2), stat=error)
+          sum_error = sum_error + error
           
+          IF (carbon_cycle_cpl) THEN
+             ALLOCATE(cpl_atm_co22D(iim,jj_nb), stat=error)
+             sum_error = sum_error + error
+          END IF
+
           IF (sum_error /= 0) THEN
              abort_message='Pb allocation variables couplees pour l''ecriture'
@@ -650,5 +696,10 @@
             knon, knindex)
 
-    ENDIF
+       CALL gath2cpl(cpl_taumod(:,cpl_index), cpl_taumod2D(:,:,cpl_index), &
+            knon, knindex)
+
+       IF (carbon_cycle_cpl) &
+            CALL gath2cpl(cpl_atm_co2(:,cpl_index), cpl_atm_co22D(:,:), knon, knindex)
+   ENDIF
 
   END SUBROUTINE cpl_send_ocean_fields
@@ -668,4 +719,5 @@
 ! the coupler.
 !
+    USE carbon_cycle_mod, ONLY : carbon_cycle_cpl
     INCLUDE "indicesol.h"
     INCLUDE "dimensions.h"
@@ -716,4 +768,5 @@
        cpl_taux(1:knon,cpl_index) = 0.0
        cpl_tauy(1:knon,cpl_index) = 0.0
+       cpl_taumod(1:knon,cpl_index) = 0.0
     ENDIF
        
@@ -742,5 +795,7 @@
             taux(ig)        / FLOAT(nexca)
        cpl_tauy(ig,cpl_index) = cpl_tauy(ig,cpl_index) + &
-            tauy(ig)        / FLOAT(nexca)      
+            tauy(ig)        / FLOAT(nexca)     
+       cpl_taumod(ig,cpl_index) = cpl_taumod(ig,cpl_index) + &
+            SQRT ( taux(ig)*taux(ig)+tauy(ig)*tauy(ig) ) / FLOAT(nexca) 
     ENDDO
 
@@ -775,5 +830,12 @@
           ALLOCATE(cpl_windsp2D(iim,jj_nb), stat=error)
           sum_error = sum_error + error
-          
+          ALLOCATE(cpl_taumod2D(iim,jj_nb,2), stat=error)
+          sum_error = sum_error + error
+
+          IF (carbon_cycle_cpl) THEN
+             ALLOCATE(cpl_atm_co22D(iim,jj_nb), stat=error)
+             sum_error = sum_error + error
+          END IF
+
           IF (sum_error /= 0) THEN
              abort_message='Pb allocation variables couplees pour l''ecriture'
@@ -819,4 +881,7 @@
             knon, knindex)
 
+       CALL gath2cpl(cpl_taumod(:,cpl_index), cpl_taumod2D(:,:,cpl_index), &
+            knon, knindex)
+
        ! Send all fields
        CALL cpl_send_all(itime, dtime, pctsrf, lafin, rlon, rlat)
@@ -894,4 +959,5 @@
 ! will be done in cpl_send_seaice_fields.
 !
+
     INCLUDE "dimensions.h"
 
@@ -947,4 +1013,5 @@
 !    
     USE surface_data
+    USE carbon_cycle_mod, ONLY : carbon_cycle_cpl
 ! Some includes
 !*************************************************************************************
@@ -979,5 +1046,5 @@
     REAL, DIMENSION(iim, jj_nb)                          :: tmp_calv
 ! Table with all fields to send to coupler
-    REAL, DIMENSION(iim, jj_nb, jpflda2o1+jpflda2o2)     :: tab_flds
+    REAL, DIMENSION(iim, jj_nb, maxsend)                 :: tab_flds
     REAL, DIMENSION(klon_mpi)                            :: rlon_mpi, rlat_mpi
 
@@ -998,18 +1065,19 @@
 !*************************************************************************************
 !$OMP MASTER
-    tab_flds(:,:,7)  = cpl_windsp2D(:,:)
-    tab_flds(:,:,8)  = cpl_sols2D(:,:,2)
-    tab_flds(:,:,10) = cpl_nsol2D(:,:,2)
-    tab_flds(:,:,12) = cpl_fder2D(:,:,2)
+    tab_flds(:,:,ids_windsp) = cpl_windsp2D(:,:)
+    tab_flds(:,:,ids_shfice) = cpl_sols2D(:,:,2)
+    tab_flds(:,:,ids_nsfice) = cpl_nsol2D(:,:,2)
+    tab_flds(:,:,ids_dflxdt) = cpl_fder2D(:,:,2)
     
     IF (version_ocean=='nemo') THEN
-       tab_flds(:,:,18) = cpl_rriv2D(:,:) + cpl_rcoa2D(:,:)
+       tab_flds(:,:,ids_liqrun) = cpl_rriv2D(:,:) + cpl_rcoa2D(:,:)
+       IF (carbon_cycle_cpl) tab_flds(:,:,ids_atmco2)=cpl_atm_co22D(:,:)
     ELSE IF (version_ocean=='opa8') THEN
-       tab_flds(:,:,9)  = cpl_sols2D(:,:,1)
-       tab_flds(:,:,11) = cpl_nsol2D(:,:,1)
-       tab_flds(:,:,13) = cpl_evap2D(:,:,2)
-       tab_flds(:,:,14) = cpl_evap2D(:,:,1)
-       tab_flds(:,:,17) = cpl_rcoa2D(:,:)
-       tab_flds(:,:,18) = cpl_rriv2D(:,:)
+       tab_flds(:,:,ids_shfoce) = cpl_sols2D(:,:,1)
+       tab_flds(:,:,ids_nsfoce) = cpl_nsol2D(:,:,1)
+       tab_flds(:,:,ids_icevap) = cpl_evap2D(:,:,2)
+       tab_flds(:,:,ids_ocevap) = cpl_evap2D(:,:,1)
+       tab_flds(:,:,ids_runcoa) = cpl_rcoa2D(:,:)
+       tab_flds(:,:,ids_rivflu) = cpl_rriv2D(:,:)
     END IF
 
@@ -1063,9 +1131,5 @@
       ENDIF
       
-      IF (version_ocean=='nemo') THEN
-         tab_flds(:,:,17) = tmp_calv(:,:)
-      ELSE IF (version_ocean=='opa8') THEN
-         tab_flds(:,:,19) = tmp_calv(:,:)
-      END IF
+      tab_flds(:,:,ids_calvin) = tmp_calv(:,:)
 
 !*************************************************************************************
@@ -1078,9 +1142,10 @@
 
        IF (version_ocean=='nemo') THEN
-          tab_flds(:,:,9)  = 0.0
-          tab_flds(:,:,11) = 0.0
-          tab_flds(:,:,13) = 0.0
-          tab_flds(:,:,14) = 0.0
-          tab_flds(:,:,15) = 0.0
+          tab_flds(:,:,ids_shftot)  = 0.0
+          tab_flds(:,:,ids_nsftot) = 0.0
+          tab_flds(:,:,ids_totrai) = 0.0
+          tab_flds(:,:,ids_totsno) = 0.0
+          tab_flds(:,:,ids_toteva) = 0.0
+          tab_flds(:,:,ids_taumod) = 0.0
   
           tmp_taux(:,:)    = 0.0
@@ -1092,30 +1157,33 @@
              tmp_tauy = cpl_tauy2D(:,:,1) * pctsrf2D(:,:,is_oce) / deno(:,:) +    &
                   cpl_tauy2D(:,:,2) * pctsrf2D(:,:,is_sic) / deno(:,:)
+
+             tab_flds(:,:,ids_shftot) = cpl_sols2D(:,:,1) * pctsrf2D(:,:,is_oce) / deno(:,:) +    &
+                  cpl_sols2D(:,:,2) * pctsrf2D(:,:,is_sic) / deno(:,:)
+             tab_flds(:,:,ids_nsftot) = cpl_nsol2D(:,:,1) * pctsrf2D(:,:,is_oce) / deno(:,:) +    &
+                  cpl_nsol2D(:,:,2) * pctsrf2D(:,:,is_sic) / deno(:,:)
+             tab_flds(:,:,ids_totrai) = cpl_rain2D(:,:,1) * pctsrf2D(:,:,is_oce) / deno(:,:) +    &
+                  cpl_rain2D(:,:,2) * pctsrf2D(:,:,is_sic) / deno(:,:)
+             tab_flds(:,:,ids_totsno) = cpl_snow2D(:,:,1) * pctsrf2D(:,:,is_oce) / deno(:,:) +    &
+                  cpl_snow2D(:,:,2) * pctsrf2D(:,:,is_sic) / deno(:,:)
+             tab_flds(:,:,ids_toteva) = cpl_evap2D(:,:,1) * pctsrf2D(:,:,is_oce) / deno(:,:) +    &
+                  cpl_evap2D(:,:,2)  * pctsrf2D(:,:,is_sic) / deno(:,:)
+             tab_flds(:,:,ids_taumod) = cpl_taumod2D(:,:,1) * pctsrf2D(:,:,is_oce) / deno(:,:) +    &
+                  cpl_taumod2D(:,:,2) * pctsrf2D(:,:,is_sic) / deno(:,:)
              
-             tab_flds(:,:,9) = cpl_sols2D(:,:,1) * pctsrf2D(:,:,is_oce) / deno(:,:) +    &
-                  cpl_sols2D(:,:,2) * pctsrf2D(:,:,is_sic) / deno(:,:)
-             tab_flds(:,:,11) = cpl_nsol2D(:,:,1) * pctsrf2D(:,:,is_oce) / deno(:,:) +    &
-                  cpl_nsol2D(:,:,2) * pctsrf2D(:,:,is_sic) / deno(:,:)
-             tab_flds(:,:,13) = cpl_rain2D(:,:,1) * pctsrf2D(:,:,is_oce) / deno(:,:) +    &
-                  cpl_rain2D(:,:,2) * pctsrf2D(:,:,is_sic) / deno(:,:)
-             tab_flds(:,:,14) = cpl_snow2D(:,:,1) * pctsrf2D(:,:,is_oce) / deno(:,:) +    &
-                  cpl_snow2D(:,:,2) * pctsrf2D(:,:,is_sic) / deno(:,:)
-             tab_flds(:,:,15) = cpl_evap2D(:,:,1) * pctsrf2D(:,:,is_oce) / deno(:,:) +    &
-                  cpl_evap2D(:,:,2)  * pctsrf2D(:,:,is_sic) / deno(:,:)
          ENDWHERE
 
-          tab_flds(:,:,16) = cpl_evap2D(:,:,2) 
+          tab_flds(:,:,ids_icevap) = cpl_evap2D(:,:,2) 
           
        ELSE IF (version_ocean=='opa8') THEN
           ! Store fields for rain and snow in tab_flds(:,:,15) and tab_flds(:,:,16)
-          tab_flds(:,:,15) = 0.0
-          tab_flds(:,:,16) = 0.0
+          tab_flds(:,:,ids_totrai) = 0.0
+          tab_flds(:,:,ids_totsno) = 0.0
           tmp_taux(:,:)    = 0.0
           tmp_tauy(:,:)    = 0.0
           ! For all valid grid cells containing some fraction of ocean or sea-ice
           WHERE ( deno(:,:) /= 0 )
-             tab_flds(:,:,15) = cpl_rain2D(:,:,1) * pctsrf2D(:,:,is_oce) / deno(:,:) +    &
+             tab_flds(:,:,ids_totrai) = cpl_rain2D(:,:,1) * pctsrf2D(:,:,is_oce) / deno(:,:) +    &
                   cpl_rain2D(:,:,2) * pctsrf2D(:,:,is_sic) / deno(:,:)
-             tab_flds(:,:,16) = cpl_snow2D(:,:,1) * pctsrf2D(:,:,is_oce) / deno(:,:) +    &
+             tab_flds(:,:,ids_totsno) = cpl_snow2D(:,:,1) * pctsrf2D(:,:,is_oce) / deno(:,:) +    &
                   cpl_snow2D(:,:,2) * pctsrf2D(:,:,is_sic) / deno(:,:)
              
@@ -1163,9 +1231,9 @@
 !$OMP MASTER
     CALL atm2geo (iim, jj_nb, tmp_taux, tmp_tauy, tmp_lon, tmp_lat, &
-         tab_flds(:,:,1), tab_flds(:,:,2), tab_flds(:,:,3) )
-    
-    tab_flds(:,:,4)  = tab_flds(:,:,1)
-    tab_flds(:,:,5)  = tab_flds(:,:,2)
-    tab_flds(:,:,6)  = tab_flds(:,:,3)
+         tab_flds(:,:,ids_tauxxu), tab_flds(:,:,ids_tauyyu), tab_flds(:,:,ids_tauzzu) )
+    
+    tab_flds(:,:,ids_tauxxv)  = tab_flds(:,:,ids_tauxxu)
+    tab_flds(:,:,ids_tauyyv)  = tab_flds(:,:,ids_tauyyu)
+    tab_flds(:,:,ids_tauzzv)  = tab_flds(:,:,ids_tauzzu)
 !$OMP END MASTER
 
@@ -1175,27 +1243,9 @@
 !*************************************************************************************
     IF (is_sequential) THEN
-       CALL histwrite(nidct,cl_writ(8), itau_w,tab_flds(:,:,8), iim*(jjm+1),ndexct)
-       CALL histwrite(nidct,cl_writ(9), itau_w,tab_flds(:,:,9), iim*(jjm+1),ndexct)
-       CALL histwrite(nidct,cl_writ(10),itau_w,tab_flds(:,:,10),iim*(jjm+1),ndexct)
-       CALL histwrite(nidct,cl_writ(11),itau_w,tab_flds(:,:,11),iim*(jjm+1),ndexct)
-       CALL histwrite(nidct,cl_writ(12),itau_w,tab_flds(:,:,12),iim*(jjm+1),ndexct)
-       CALL histwrite(nidct,cl_writ(13),itau_w,tab_flds(:,:,13),iim*(jjm+1),ndexct)
-       CALL histwrite(nidct,cl_writ(14),itau_w,tab_flds(:,:,14),iim*(jjm+1),ndexct)
-       CALL histwrite(nidct,cl_writ(15),itau_w,tab_flds(:,:,15),iim*(jjm+1),ndexct)
-       CALL histwrite(nidct,cl_writ(16),itau_w,tab_flds(:,:,16),iim*(jjm+1),ndexct)
-       CALL histwrite(nidct,cl_writ(17),itau_w,tab_flds(:,:,17),iim*(jjm+1),ndexct)
-       CALL histwrite(nidct,cl_writ(18),itau_w,tab_flds(:,:,18),iim*(jjm+1),ndexct)
-       CALL histwrite(nidct,cl_writ(19),itau_w,tab_flds(:,:,19),iim*(jjm+1),ndexct)
-       CALL histwrite(nidct,cl_writ(1), itau_w,tab_flds(:,:,1), iim*(jjm+1),ndexct)
-       CALL histwrite(nidct,cl_writ(2), itau_w,tab_flds(:,:,2), iim*(jjm+1),ndexct)
-       CALL histwrite(nidct,cl_writ(3), itau_w,tab_flds(:,:,3), iim*(jjm+1),ndexct)
-       CALL histwrite(nidct,cl_writ(4), itau_w,tab_flds(:,:,4), iim*(jjm+1),ndexct)
-       CALL histwrite(nidct,cl_writ(5), itau_w,tab_flds(:,:,5), iim*(jjm+1),ndexct)
-       CALL histwrite(nidct,cl_writ(6), itau_w,tab_flds(:,:,6), iim*(jjm+1),ndexct)
-       CALL histwrite(nidct,cl_writ(7), itau_w,tab_flds(:,:,7), iim*(jjm+1),ndexct)
-       CALL histsync(nidct)
+        DO j=1,maxsend
+          IF (infosend(j)%action) CALL histwrite(nidct,infosend(j)%name, itau_w, &
+             tab_flds(:,:,j),iim*(jjm+1),ndexct)
+        ENDDO
     ENDIF
-
-
 !*************************************************************************************
 ! Send the table of all fields
@@ -1218,6 +1268,12 @@
     DEALLOCATE(cpl_evap2D, cpl_tsol2D, cpl_fder2D, cpl_albe2D, stat=error )
     sum_error = sum_error + error
-    DEALLOCATE(cpl_taux2D, cpl_tauy2D, cpl_windsp2D, stat=error )
-    sum_error = sum_error + error
+    DEALLOCATE(cpl_taux2D, cpl_tauy2D, cpl_windsp2D, cpl_taumod2D, stat=error )
+    sum_error = sum_error + error
+    
+    IF (carbon_cycle_cpl) THEN
+       DEALLOCATE(cpl_atm_co22D, stat=error )
+       sum_error = sum_error + error
+    END IF
+
     IF (sum_error /= 0) THEN
        abort_message='Pb in deallocation of cpl_xxxx2D coupling variables'
@@ -1231,15 +1287,15 @@
   SUBROUTINE cpl2gath(champ_in, champ_out, knon, knindex)
   USE mod_phys_lmdz_para
-! Cette routine ecrit un champ 'gathered' sur la grille 2D pour le passer
-! au coupleur.
+! Cette routine transforme un champs de la grille 2D recu du coupleur sur la grille 
+! 'gathered' (la grille physiq comprime).
 !
 ! 
 ! input:         
-!   champ_in     champ sur la grille gathere        
+!   champ_in     champ sur la grille 2D
 !   knon         nombre de points dans le domaine a traiter
 !   knindex      index des points de la surface a traiter
 !
 ! output:
-!   champ_out    champ sur la grille 2D
+!   champ_out    champ sur la grille 'gatherd'
 !
     INCLUDE "dimensions.h"
