Index: codes/icosagcm/trunk/make_icosa
===================================================================
--- codes/icosagcm/trunk/make_icosa	(revision 326)
+++ codes/icosagcm/trunk/make_icosa	(revision 327)
@@ -16,4 +16,5 @@
 arch=""
 parallel="none"
+physics="none"
 CPP_KEY="CPP_NONE" 
 ICOSA_LIB=""
@@ -45,4 +46,7 @@
       "-parallel")
 	  parallel=$2 ; parallel_defined="TRUE"; shift ; shift ;;
+
+      "-physics")
+	  physics=$2 ; physics_defined="TRUE"; shift ; shift ;;
 
       "-job")
@@ -119,4 +123,11 @@
 fi
 
+if [[ "$physics" == "lmdz_generic" ]]
+then
+  CPP_KEY="$CPP_KEY CPP_PHYSICS_LMDZ_GENERIC"
+  COMPIL_FFLAGS="$COMPIL_FFLAGS $PHYSICS_INCDIR"
+  ICOSA_LIB="$ICOSA_LIB $PHYSICS_LIBDIR $PHYSICS_LIB"
+fi
+
 if [[ "$with_xios_defined" == "TRUE" ]]
 then
@@ -127,4 +138,5 @@
 
 ICOSA_LIB="$ICOSA_LIB $NETCDF_LIBDIR $NETCDF_LIB $HDF5_LIBDIR $HDF5_LIB"
+
 
 rm -f config.fcm
Index: codes/icosagcm/trunk/src/advect.f90
===================================================================
--- codes/icosagcm/trunk/src/advect.f90	(revision 326)
+++ codes/icosagcm/trunk/src/advect.f90	(revision 327)
@@ -272,5 +272,12 @@
   CALL trace_end("compute_gradq3d3")
   
-  gradq3d_out=gradq3d
+  
+  DO k=1,3
+    DO l = ll_begin,ll_end
+      DO ij=ij_begin,ij_end 
+        gradq3d_out(ij,l,k)=gradq3d(ij,l,k)
+      ENDDO
+    ENDDO
+  ENDDO
   
   CONTAINS
Index: codes/icosagcm/trunk/src/advect_tracer.f90
===================================================================
--- codes/icosagcm/trunk/src/advect_tracer.f90	(revision 326)
+++ codes/icosagcm/trunk/src/advect_tracer.f90	(revision 327)
@@ -95,16 +95,12 @@
 
     CALL send_message(f_u,req_u)
+    CALL send_message(f_wfluxt,req_wfluxt)
+    CALL send_message(f_q,req_q)
+    CALL send_message(f_rhodz,req_rhodz)
+
     CALL wait_message(req_u)
-    CALL send_message(f_wfluxt,req_wfluxt)
     CALL wait_message(req_wfluxt)
-    CALL send_message(f_q,req_q)
     CALL wait_message(req_q)
-    CALL send_message(f_rhodz,req_rhodz)
     CALL wait_message(req_rhodz)
-
-!    CALL wait_message(req_u)
-!    CALL wait_message(req_wfluxt)
-!    CALL wait_message(req_q)
-!    CALL wait_message(req_rhodz)
     
     ! 1/2 vertical transport + back-trajectories
@@ -134,9 +130,7 @@
 
     CALL send_message(f_cc,req_cc)
-    CALL wait_message(req_cc)
 
 
     ! horizontal transport - split in two to place transfer of gradq3d
-!!$OMP BARRIER
     DO k = 1, nqtot
        DO ind=1,ndomain
@@ -148,8 +142,9 @@
           sqrt_leng=f_sqrt_leng(ind)
           CALL compute_gradq3d(q(:,:,k),sqrt_leng,gradq3d,xyz_i,xyz_v)
+
        END DO
 
        CALL send_message(f_gradq3d,req_gradq3d)
-!       CALL wait_message(req_cc)
+       CALL wait_message(req_cc)
        CALL wait_message(req_gradq3d)
 
Index: codes/icosagcm/trunk/src/caldyn_gcm.f90
===================================================================
--- codes/icosagcm/trunk/src/caldyn_gcm.f90	(revision 326)
+++ codes/icosagcm/trunk/src/caldyn_gcm.f90	(revision 327)
@@ -201,17 +201,10 @@
       IF(caldyn_eta==eta_mass) THEN
          CALL send_message(f_ps,req_ps) 
-         CALL wait_message(req_ps)  
       ELSE
          CALL send_message(f_mass,req_mass) 
-         CALL wait_message(req_mass)  
       END IF
 
+    CALL send_message(f_theta_rhodz,req_theta_rhodz) 
     CALL send_message(f_u,req_u)
-    CALL wait_message(req_u)
-    CALL send_message(f_theta_rhodz,req_theta_rhodz) 
-    CALL wait_message(req_theta_rhodz) 
-    
-!    CALL wait_message(req_u)
-!    CALL wait_message(req_theta_rhodz) 
 
     SELECT CASE(caldyn_conserv)
@@ -232,5 +225,5 @@
 
        CALL send_message(f_qu,req_qu)
-       CALL wait_message(req_qu)
+!       CALL wait_message(req_qu)
 
        DO ind=1,ndomain
@@ -364,13 +357,13 @@
 
   IF(caldyn_eta==eta_mass) THEN
-!     CALL wait_message(req_ps)  
+     CALL wait_message(req_ps)  
   ELSE
-!     CALL wait_message(req_mass)
+     CALL wait_message(req_mass)
   END IF
-!  CALL wait_message(req_theta_rhodz) 
+  CALL wait_message(req_theta_rhodz) 
 
   IF(caldyn_eta==eta_mass) THEN ! Compute mass & theta
      DO l = ll_begin,ll_end
-!        CALL test_message(req_u) 
+        CALL test_message(req_u) 
 !DIR$ SIMD
         DO ij=ij_begin_ext,ij_end_ext
@@ -382,5 +375,5 @@
   ELSE ! Compute only theta
      DO l = ll_begin,ll_end
-!        CALL test_message(req_u) 
+        CALL test_message(req_u) 
 !DIR$ SIMD
        DO ij=ij_begin_ext,ij_end_ext
@@ -390,5 +383,5 @@
   END IF
 
-!  CALL wait_message(req_u)   
+  CALL wait_message(req_u)   
   
 !!! Compute shallow-water potential vorticity
@@ -446,15 +439,25 @@
     INTEGER :: i,j,ij,l
     REAL(rstd) :: p_ik, exner_ik
+    INTEGER,SAVE ::ij_omp_begin_ext, ij_omp_end_ext
+!$OMP THREADPRIVATE(ij_omp_begin_ext, ij_omp_end_ext)
+    LOGICAL,SAVE :: first=.TRUE.
+!$OMP THREADPRIVATE(first)
+
 
     CALL trace_start("compute_geopot")
+    
+    IF (first) THEN
+      first=.FALSE.
+      CALL distrib_level(ij_end_ext-ij_begin_ext+1,ij_omp_begin_ext,ij_omp_end_ext)
+      ij_omp_begin_ext=ij_omp_begin_ext+ij_begin_ext-1
+      ij_omp_end_ext=ij_omp_end_ext+ij_begin_ext-1
+    ENDIF
 
     IF(caldyn_eta==eta_mass) THEN
 
 !!! Compute exner function and geopotential
-       IF (is_omp_level_master) THEN ! no openMP on vertical due to dependency
          DO l = 1,llm
-!         !$OMP DO SCHEDULE(STATIC) 
           !DIR$ SIMD
-            DO ij=ij_begin_ext,ij_end_ext         
+            DO ij=ij_omp_begin_ext,ij_omp_end_ext         
                p_ik = ptop + mass_ak(l) + mass_bk(l)*ps(ij) ! FIXME : leave ps for the moment ; change ps to Ms later
                !         p_ik = ptop + g*(mass_ak(l)+ mass_bk(l)*ps(i,j))
@@ -465,5 +468,5 @@
           ENDDO
          ENDDO
-       ENDIF
+!       ENDIF
     ELSE 
        ! We are using a Lagrangian vertical coordinate
@@ -474,48 +477,40 @@
        IF(boussinesq) THEN ! compute only geopotential : pressure pk will be computed in compute_caldyn_horiz
           ! specific volume 1 = dphi/g/rhodz
-         IF (is_omp_level_master) THEN ! no openMP on vertical due to dependency
-           DO l = 1,llm
-!             !$OMP DO SCHEDULE(STATIC) 
-             !DIR$ SIMD
-             DO ij=ij_begin_ext,ij_end_ext         
-                geopot(ij,l+1) = geopot(ij,l) + g*rhodz(ij,l)
-             ENDDO
+!         IF (is_omp_level_master) THEN ! no openMP on vertical due to dependency
+         DO l = 1,llm
+           !DIR$ SIMD
+           DO ij=ij_omp_begin_ext,ij_omp_end_ext         
+              geopot(ij,l+1) = geopot(ij,l) + g*rhodz(ij,l)
            ENDDO
-         ENDIF
+         ENDDO
        ELSE ! non-Boussinesq, compute geopotential and Exner pressure
           ! uppermost layer
-         IF (is_omp_level_master) THEN  ! no openMP on vertical due to dependency
-
+
+         !DIR$ SIMD
+         DO ij=ij_omp_begin_ext,ij_omp_end_ext         
+            pk(ij,llm) = ptop + (.5*g)*rhodz(ij,llm)
+         END DO
+         ! other layers
+         DO l = llm-1, 1, -1
+            !DIR$ SIMD
+            DO ij=ij_omp_begin_ext,ij_omp_end_ext         
+               pk(ij,l) = pk(ij,l+1) + (.5*g)*(rhodz(ij,l)+rhodz(ij,l+1))
+            END DO
+         END DO
+        ! surface pressure (for diagnostics)
+         DO ij=ij_omp_begin_ext,ij_omp_end_ext         
+            ps(ij) = pk(ij,1) + (.5*g)*rhodz(ij,1)
+         END DO
+
+         ! specific volume v = kappa*theta*pi/p = dphi/g/rhodz
+         DO l = 1,llm
            !DIR$ SIMD
-           DO ij=ij_begin_ext,ij_end_ext         
-              pk(ij,llm) = ptop + (.5*g)*rhodz(ij,llm)
-           END DO
-           ! other layers
-           DO l = llm-1, 1, -1
-
-!           !$OMP DO SCHEDULE(STATIC) 
-              !DIR$ SIMD
-              DO ij=ij_begin_ext,ij_end_ext         
-                 pk(ij,l) = pk(ij,l+1) + (.5*g)*(rhodz(ij,l)+rhodz(ij,l+1))
-              END DO
-           END DO
-          ! surface pressure (for diagnostics)
-           DO ij=ij_begin_ext,ij_end_ext         
-              ps(ij) = pk(ij,1) + (.5*g)*rhodz(ij,1)
-           END DO
-
-          ! specific volume v = kappa*theta*pi/p = dphi/g/rhodz
-           DO l = 1,llm
-
-!             !$OMP DO SCHEDULE(STATIC) 
-             !DIR$ SIMD
-              DO ij=ij_begin_ext,ij_end_ext         
-                 p_ik = pk(ij,l)
-                 exner_ik = cpp * (p_ik/preff) ** kappa
-                 geopot(ij,l+1) = geopot(ij,l) + (g*kappa)*rhodz(ij,l)*theta(ij,l)*exner_ik/p_ik 
-                 pk(ij,l) = exner_ik
-              ENDDO
+            DO ij=ij_omp_begin_ext,ij_omp_end_ext         
+               p_ik = pk(ij,l)
+               exner_ik = cpp * (p_ik/preff) ** kappa
+               geopot(ij,l+1) = geopot(ij,l) + (g*kappa)*rhodz(ij,l)*theta(ij,l)*exner_ik/p_ik 
+               pk(ij,l) = exner_ik
             ENDDO
-          ENDIF
+          ENDDO
        END IF
 
@@ -562,5 +557,5 @@
   DO l = ll_begin, ll_end
 !!!  Compute mass and theta fluxes
-!    IF (caldyn_conserv==energy) CALL test_message(req_qu) 
+    IF (caldyn_conserv==energy) CALL test_message(req_qu) 
 !DIR$ SIMD
     DO ij=ij_begin_ext,ij_end_ext         
@@ -602,5 +597,5 @@
     CASE(energy) ! energy-conserving TRiSK
 
-!       CALL wait_message(req_qu)
+       CALL wait_message(req_qu)
 
         DO l=ll_begin,ll_end
@@ -796,6 +791,6 @@
     REAL(rstd),INTENT(INOUT) :: wflux(iim*jjm,llm+1) ! vertical mass flux (kg/m2/s)
     REAL(rstd),INTENT(INOUT) :: wwuu(iim*3*jjm,llm+1)
-    REAL(rstd),INTENT(OUT) :: du(iim*3*jjm,llm)
-    REAL(rstd),INTENT(OUT) :: dtheta_rhodz(iim*jjm,llm)
+    REAL(rstd),INTENT(INOUT) :: du(iim*3*jjm,llm)
+    REAL(rstd),INTENT(INOUT) :: dtheta_rhodz(iim*jjm,llm)
     REAL(rstd),INTENT(OUT) :: dps(iim*jjm)
 
@@ -803,4 +798,18 @@
     INTEGER :: i,j,ij,l
     REAL(rstd) :: p_ik, exner_ik
+    INTEGER,SAVE ::ij_omp_begin, ij_omp_end
+!$OMP THREADPRIVATE(ij_omp_begin, ij_omp_end)
+    LOGICAL,SAVE :: first=.TRUE.
+!$OMP THREADPRIVATE(first)
+
+
+    CALL trace_start("compute_geopot")
+    
+    IF (first) THEN
+      first=.FALSE.
+      CALL distrib_level(ij_end-ij_begin+1,ij_omp_begin,ij_omp_end)
+      ij_omp_begin=ij_omp_begin+ij_begin-1
+      ij_omp_end=ij_omp_end+ij_begin-1
+    ENDIF
 
 !    REAL(rstd) :: wwuu(iim*3*jjm,llm+1) ! tmp var, don't know why but gain 30% on the whole code in opemp
@@ -812,5 +821,5 @@
 !$OMP BARRIER   
 !!! cumulate mass flux convergence from top to bottom
-  IF (is_omp_level_master) THEN
+!  IF (is_omp_level_master) THEN
     DO  l = llm-1, 1, -1
 !    IF (caldyn_conserv==energy) CALL test_message(req_qu) 
@@ -818,9 +827,9 @@
 !!$OMP DO SCHEDULE(STATIC) 
 !DIR$ SIMD
-      DO ij=ij_begin,ij_end         
+      DO ij=ij_omp_begin,ij_omp_end         
           convm(ij,l) = convm(ij,l) + convm(ij,l+1)
       ENDDO
     ENDDO
-  ENDIF
+!  ENDIF
 
 !$OMP BARRIER
Index: codes/icosagcm/trunk/src/checksum.f90
===================================================================
--- codes/icosagcm/trunk/src/checksum.f90	(revision 326)
+++ codes/icosagcm/trunk/src/checksum.f90	(revision 327)
@@ -14,5 +14,5 @@
     TYPE(t_field), POINTER :: field(:)
     INTEGER :: intval(2)
-    INTEGER :: ind,i,j,ij,l
+    INTEGER :: ind,i,j,ij,l,k
     INTEGER :: tot_sum
         
@@ -49,4 +49,20 @@
           ENDDO
         ENDDO
+
+      ELSE IF (field(ind)%ndim==4) THEN
+        
+        DO k=1,size(field(ind)%rval4d,3)
+          DO l=1,size(field(ind)%rval4d,2)
+            DO j=jj_begin,jj_end
+               DO i=ii_begin,ii_end
+                  ij=(j-1)*iim+i
+                  IF (domain(ind)%own(i,j)) THEN
+                    intval=transfer(field(ind)%rval4d(ij,l,k),intval,2)  
+                    tot_sum=tot_sum+intval(1)+intval(2)
+                  ENDIF
+               ENDDO
+            ENDDO
+          ENDDO
+        ENDDO
      
       ENDIF
@@ -56,5 +72,5 @@
     
 !$OMP MASTER
-    PRINT*,"CheckSum Field",field(1)%name,tot_sum
+    PRINT*,"CheckSum Field : ",field(1)%name,tot_sum
 !$OMP END MASTER
   
Index: codes/icosagcm/trunk/src/domain.f90
===================================================================
--- codes/icosagcm/trunk/src/domain.f90	(revision 326)
+++ codes/icosagcm/trunk/src/domain.f90	(revision 327)
@@ -402,7 +402,10 @@
   SUBROUTINE assign_domain
   USE mpipara
+  USE grid_param
   IMPLICIT NONE
     INTEGER :: nb_domain(0:mpi_size-1)
     INTEGER :: rank, ind,ind_glo
+    INTEGER :: block_j,jb,i,j,nd_glo,n,nf
+    LOGICAL :: exit
     
     DO rank=0,mpi_size-1
@@ -415,8 +418,43 @@
     ALLOCATE(domloc_glo_ind(ndomain))
     
+    
+    block_j=sqrt(nsplit_i*nsplit_j*nb_face*1./mpi_size)
+    exit=.FALSE.
+    jb=1
+    i=1
+    j=1
+    ind=1
+    nd_glo=0
     rank=0
-    ind=0
-    DO ind_glo=1,ndomain_glo
-      ind=ind+1
+    DO WHILE (.NOT. exit)
+
+      IF (j==MIN(jb+block_j,nsplit_j*nb_face+1)) THEN
+        j=jb
+        i=i+1
+      ENDIF
+
+      IF (i>nsplit_i) THEN 
+        i=1
+        jb=jb+block_j
+        j=jb
+      ENDIF
+      
+      IF (ind>nb_domain(rank)) THEN
+        rank=rank+1
+        ind=1
+      ENDIF 
+      ind_glo=(j-1)*nsplit_i+i
+
+      nd_glo=nd_glo+1
+      IF (nd_glo==ndomain_glo) THEN
+
+        exit=.TRUE.
+        IF (.NOT. (rank==mpi_size-1 .AND. ind==nb_domain(rank) )) THEN
+          PRINT *, "Distribution problem in assign_domain"
+          STOP
+        ENDIF
+
+      ENDIF
+
       domglo_rank(ind_glo)=rank
       domglo_loc_ind(ind_glo)=ind
@@ -426,9 +464,77 @@
       ENDIF
       
-      IF (ind==nb_domain(rank)) THEN
-        rank=rank+1
-        ind=0
-      ENDIF
+      j=j+1
+      ind=ind+1
+      
     ENDDO
+
+    IF (is_mpi_master) THEN
+   
+      ind_glo=0
+      WRITE(*,'')
+      PRINT*, '      MPI PROCESS DISTRIBUTION'
+      WRITE(*,'')
+      
+      WRITE(*,"(' ')", ADVANCE='NO')
+      DO n=1,nsplit_i*7-1
+        WRITE(*,"('=')", ADVANCE='NO')
+      ENDDO
+      WRITE(*,'')
+
+      DO nf=1,nb_face
+        DO j=1,nsplit_j
+          IF (j>1) THEN
+            WRITE(*,"(' ')", ADVANCE='NO')
+            DO n=1,nsplit_i*7-1
+              WRITE(*,"('-')", ADVANCE='NO')
+            ENDDO
+            WRITE(*,'')
+          ENDIF
+
+          WRITE(*,"('|')", ADVANCE='NO')
+          DO i=1,nsplit_i
+            WRITE(*,"(' ','    ',' |')",ADVANCE='NO')         
+          ENDDO
+          WRITE(*,'')
+
+          WRITE(*,"('|')", ADVANCE='NO')
+          DO i=1,nsplit_i
+            ind_glo=ind_glo+1
+            WRITE(*,"(' ',i4.4  ,' |')",ADVANCE='NO'),domglo_rank(ind_glo)           
+          END DO
+          WRITE(*,'')
+
+          WRITE(*,"('|')", ADVANCE='NO')
+          DO i=1,nsplit_i
+            WRITE(*,"(' ','    ',' |')",ADVANCE='NO')         
+          ENDDO
+          WRITE(*,'')
+
+        ENDDO
+          
+        WRITE(*,"(' ')", ADVANCE='NO')
+        DO n=1,nsplit_i*7-1
+          WRITE(*,"('=')", ADVANCE='NO')
+        ENDDO
+        WRITE(*,'')
+      ENDDO
+    ENDIF
+              
+!    rank=0
+!    ind=0
+!    DO ind_glo=1,ndomain_glo
+!      ind=ind+1
+!      domglo_rank(ind_glo)=rank
+!      domglo_loc_ind(ind_glo)=ind
+!      IF (rank==mpi_rank) THEN 
+!        CALL copy_domain(domain_glo(ind_glo),domain(ind))
+!        domloc_glo_ind(ind)=ind_glo
+!      ENDIF
+!      
+!      IF (ind==nb_domain(rank)) THEN
+!        rank=rank+1
+!        ind=0
+!      ENDIF
+!    ENDDO
 
 !$OMP PARALLEL
Index: codes/icosagcm/trunk/src/etat0.f90
===================================================================
--- codes/icosagcm/trunk/src/etat0.f90	(revision 326)
+++ codes/icosagcm/trunk/src/etat0.f90	(revision 327)
@@ -18,4 +18,5 @@
     USE etat0_dcmip5_mod, ONLY : getin_etat0_dcmip5=>getin_etat0
     USE etat0_williamson_mod, ONLY : getin_etat0_williamson=>getin_etat0
+    USE etat0_temperature_mod, ONLY: getin_etat0_temperature=>getin_etat0
     ! Old interface
     USE etat0_academic_mod, ONLY : etat0_academic=>etat0  
@@ -55,4 +56,7 @@
     CASE ('isothermal')
        CALL getin_etat0_isothermal
+       CALL etat0_collocated(f_phis,f_ps,f_mass,f_theta_rhodz,f_u, f_q)
+    CASE ('temperature_profile')
+       CALL getin_etat0_temperature
        CALL etat0_collocated(f_phis,f_ps,f_mass,f_theta_rhodz,f_u, f_q)
     CASE ('jablonowsky06')
@@ -161,4 +165,5 @@
     USE etat0_dcmip5_mod, ONLY : compute_dcmip5 => compute_etat0
     USE etat0_williamson_mod, ONLY : compute_w91_6 => compute_etat0
+    USE etat0_temperature_mod, ONLY: compute_etat0_temperature => compute_etat0
     IMPLICIT NONE
     REAL(rstd),INTENT(INOUT) :: ps(iim*jjm)
@@ -186,4 +191,7 @@
        CALL compute_etat0_isothermal(iim*jjm, phis, ps, temp_i, ulon_i, ulat_i, q)
        CALL compute_etat0_isothermal(3*iim*jjm, phis_e, ps_e, temp_e, ulon_e, ulat_e, q_e)
+    CASE ('temperature_profile')
+       CALL compute_etat0_temperature(iim*jjm, phis, ps, temp_i, ulon_i, ulat_i, q)
+       CALL compute_etat0_temperature(3*iim*jjm, phis_e, ps_e, temp_e, ulon_e, ulat_e, q_e)
     CASE('jablonowsky06')
        CALL compute_jablonowsky06(iim*jjm,lon_i,lat_i, phis, ps, temp_i, ulon_i, ulat_i)
Index: codes/icosagcm/trunk/src/icosa_gcm.f90
===================================================================
--- codes/icosagcm/trunk/src/icosa_gcm.f90	(revision 326)
+++ codes/icosagcm/trunk/src/icosa_gcm.f90	(revision 327)
@@ -12,4 +12,6 @@
   USE xios_mod
   USE write_field
+  USE physics_mod
+
 !  USE getin_mod
   IMPLICIT NONE
@@ -42,5 +44,9 @@
   CALL output_field_init
   CALL init_timeloop
-  
+!$OMP END PARALLEL
+ 
+  CALL init_physics
+   
+!$OMP PARALLEL  
   CALL timeloop
   CALL switch_omp_no_distrib_level
Index: codes/icosagcm/trunk/src/omp_para.F90
===================================================================
--- codes/icosagcm/trunk/src/omp_para.F90	(revision 326)
+++ codes/icosagcm/trunk/src/omp_para.F90	(revision 327)
@@ -68,5 +68,5 @@
   IMPLICIT NONE
   LOGICAL, INTENT(IN) :: is_mpi_master
-  INTEGER :: ll_nb,i
+  INTEGER :: ll_nb,i,llb,lle
 
 #ifdef CPP_USING_OMP
@@ -77,5 +77,5 @@
 
   IF (using_openmp) THEN    
-!$OMP PARALLEL PRIVATE(ll_nb,i)
+!$OMP PARALLEL PRIVATE(ll_nb,i,llb,lle)
   
 !$OMP MASTER
@@ -123,11 +123,14 @@
     IF (omp_level_rank==omp_level_size-1) is_omp_last_level=.TRUE.
     
-    ll_end=0
+    lle=0
+    
     DO i=0,omp_level_rank
-      ll_begin=ll_end+1
+      llb=lle+1
       ll_nb=llm/omp_level_size
       IF (MOD(llm,omp_level_size)>i) ll_nb=ll_nb+1
-      ll_end=ll_begin+ll_nb-1
+      lle=llb+ll_nb-1
     ENDDO
+    ll_begin=llb
+    ll_end=lle
     
     ll_beginp1=ll_begin
@@ -160,5 +163,4 @@
 
    ELSE
-     is_master=is_mpi_master
      omp_size=1
      omp_level_size=1
@@ -198,4 +200,22 @@
   END SUBROUTINE init_omp_para
 
+  SUBROUTINE distrib_level(size,lbegin,lend)
+  IMPLICIT NONE
+    INTEGER,INTENT(IN)  :: size  
+    INTEGER,INTENT(OUT) :: lbegin  
+    INTEGER,INTENT(OUT) :: lend  
+    INTEGER :: div,rest
+    
+    div=size/omp_level_size
+    rest=MOD(size,omp_level_size)
+    IF (omp_level_rank<rest) THEN
+      lbegin=(div+1)*omp_level_rank+1
+      lend=lbegin+div
+    ELSE
+      lbegin=(div+1)*rest + (omp_level_rank-rest)*div+1
+      lend=lbegin+div-1
+    ENDIF
+  END SUBROUTINE distrib_level
+
 
   SUBROUTINE switch_omp_distrib_level
Index: codes/icosagcm/trunk/src/physics.f90
===================================================================
--- codes/icosagcm/trunk/src/physics.f90	(revision 326)
+++ codes/icosagcm/trunk/src/physics.f90	(revision 327)
@@ -5,5 +5,5 @@
   PRIVATE
 
-  INTEGER, PARAMETER :: phys_none=0, phys_HS94=1, phys_DCMIP=2, phys_LB2012=3
+  INTEGER, PARAMETER :: phys_none=0, phys_HS94=1, phys_DCMIP=2, phys_lmdz_generic=3, phys_LB2012=4 
 
   INTEGER :: phys_type
@@ -26,4 +26,5 @@
     USE physics_dcmip_mod, ONLY : init_physics_dcmip=>init_physics
     USE etat0_venus_mod, ONLY : init_phys_venus=>init_physics
+    USE physics_lmdz_generic_mod, ONLY : init_physics_lmdz_generic=>init_physics
     IMPLICIT NONE
 
@@ -40,4 +41,8 @@
        phys_type = phys_LB2012
        CALL init_phys_venus
+
+    CASE ('phys_lmdz_generic')
+       CALL init_physics_lmdz_generic
+       phys_type=phys_lmdz_generic
     CASE ('dcmip')
        CALL allocate_field(f_dulon,field_t,type_real,llm, name='dulon')
@@ -50,5 +55,5 @@
     CASE DEFAULT
        IF(is_mpi_root) PRINT*, 'init_physics : Bad selector for variable physics <',&
-            TRIM(physics_type), '> options are <none>, <held_suarez>, <Lebonnois2012>, <dcmip>'
+            TRIM(physics_type), '> options are <none>, <held_suarez>, <Lebonnois2012>, <dcmip>, <phys_lmdz_generic>'
        STOP
     END SELECT
@@ -57,7 +62,8 @@
   END SUBROUTINE init_physics
 
-  SUBROUTINE physics(it,f_phis, f_ps, f_theta_rhodz, f_ue, f_q)
-    USE icosa
-    USE physics_interface_mod
+  SUBROUTINE physics(it,f_phis, f_ps, f_theta_rhodz, f_ue, f_wflux, f_q)
+    USE icosa
+    USE physics_interface_mod
+    USE physics_lmdz_generic_mod, ONLY : physics_lmdz_generic => physics
     USE physics_dcmip_mod, ONLY : write_physics_dcmip => write_physics
     USE etat0_heldsz_mod
@@ -69,4 +75,5 @@
     TYPE(t_field),POINTER :: f_theta_rhodz(:)
     TYPE(t_field),POINTER :: f_ue(:)
+    TYPE(t_field),POINTER :: f_wflux(:)
     TYPE(t_field),POINTER :: f_q(:)
     REAL(rstd),POINTER :: phis(:)
@@ -87,4 +94,6 @@
        CASE(phys_HS94)
           CALL held_suarez(f_ps,f_theta_rhodz,f_ue) 
+       CASE (phys_lmdz_generic)
+         CALL physics_lmdz_generic(it ,f_phis, f_ps, f_theta_rhodz, f_ue, f_wflux, f_q)
        CASE(phys_LB2012)
           CALL phys_venus(f_ps,f_theta_rhodz,f_ue) 
Index: codes/icosagcm/trunk/src/restart.f90
===================================================================
--- codes/icosagcm/trunk/src/restart.f90	(revision 326)
+++ codes/icosagcm/trunk/src/restart.f90	(revision 327)
@@ -21,4 +21,5 @@
   USE spherical_geom_mod
   USE transfert_mod
+  USE disvert_mod
  
   IMPLICIT NONE 
@@ -38,5 +39,5 @@
   CHARACTER(LEN=255) :: restart_file_name
   INTEGER,PARAMETER  :: nvert=6
-  INTEGER    ::  ncid, cellId, levId, edgeId,  vertid, lonId, latId, bounds_lonId, bounds_latId, nqId
+  INTEGER    ::  ncid, cellId, levId, edgeId,  vertid, lonId, latId, bounds_lonId, bounds_latId, nqId, levAxisId
   INTEGER    :: ind,ind_glo,i,j,k,nf
   INTEGER    :: status
@@ -91,4 +92,8 @@
       status = NF90_DEF_VAR(ncid,'bounds_lon',NF90_DOUBLE,(/ vertId,cellId /),bounds_lonId)
       status = NF90_DEF_VAR(ncid,'bounds_lat',NF90_DOUBLE,(/ vertId,cellId /),bounds_latId)
+      status = NF90_DEF_VAR(ncid,'lev',NF90_DOUBLE,(/ levId /),levAxisId)
+      status = NF90_PUT_ATT(ncid,levAxisId,"axis","Z")
+      status = NF90_PUT_ATT(ncid,levAxisId,"units","Pa")
+      status = NF90_PUT_ATT(ncid,levAxisId,"positive","down")
       
       DO nf=1,nfield
@@ -97,10 +102,12 @@
           IF (field(1)%ndim==2) THEN
             status = NF90_DEF_VAR(ncid,TRIM(ADJUSTL(field(1)%name)),NF90_DOUBLE,(/ cellId /),fieldId(nf))
+            status = NF90_PUT_ATT(ncid,FieldId(nf),"coordinates","lon lat")
           ELSE IF (field(1)%ndim==3) THEN
             status = NF90_DEF_VAR(ncid,TRIM(ADJUSTL(field(1)%name)),NF90_DOUBLE,(/ cellId, levId /),fieldId(nf))
+            status = NF90_PUT_ATT(ncid,FieldId(nf),"coordinates","lev lon lat")
           ELSE IF (field(1)%ndim==4) THEN
             status = NF90_DEF_VAR(ncid,TRIM(ADJUSTL(field(1)%name)),NF90_DOUBLE,(/ cellId, levId,nqId /),fieldId(nf))
+            status = NF90_PUT_ATT(ncid,FieldId(nf),"coordinates","nq lev lon lat")
           ENDIF
-          status = NF90_PUT_ATT(ncid,FieldId(nf),"coordinates","lon lat")
         ELSE IF (field(1)%field_type==field_U) THEN
           IF (field(1)%ndim==2) THEN
@@ -139,4 +146,5 @@
       status=NF90_PUT_VAR(ncid,bounds_lonId,REAL(bounds_lon,r8),start=(/ 1,1 /),count=(/ nvert,ncell_glo /))
       status=NF90_PUT_VAR(ncid,bounds_latId,REAL(bounds_lat,r8),start=(/ 1,1 /),count=(/ nvert,ncell_glo /))
+      status=NF90_PUT_VAR(ncid,levAxisId,REAL(presnivs,r8),start=(/ 1 /),count=(/ llm /))
     ENDIF
 
Index: codes/icosagcm/trunk/src/time.f90
===================================================================
--- codes/icosagcm/trunk/src/time.f90	(revision 326)
+++ codes/icosagcm/trunk/src/time.f90	(revision 327)
@@ -92,4 +92,5 @@
     itau_physics=1
     CALL getin('itau_physics',itau_physics)
+    if (itau_physics<=0) itau_physics = HUGE(itau_physics)
 
     itau_check_conserv=HUGE(itau_check_conserv)
Index: codes/icosagcm/trunk/src/timeloop_gcm.f90
===================================================================
--- codes/icosagcm/trunk/src/timeloop_gcm.f90	(revision 326)
+++ codes/icosagcm/trunk/src/timeloop_gcm.f90	(revision 327)
@@ -40,4 +40,5 @@
   USE write_field
   USE theta2theta_rhodz_mod
+  USE sponge_mod
   IMPLICIT NONE
 
@@ -111,4 +112,6 @@
            f_psm2 => f_phis
         END IF
+      CASE ('none')
+        nb_stage=0
 
     CASE default
@@ -120,10 +123,9 @@
     CALL init_theta2theta_rhodz
     CALL init_dissip
+    CALL init_sponge
     CALL init_caldyn
     CALL init_guided
     CALL init_advect_tracer
     CALL init_check_conserve
-    CALL init_physics
-    
 
     CALL etat0(f_ps,f_mass,f_phis,f_theta_rhodz,f_u, f_q)
@@ -144,4 +146,5 @@
   USE icosa
   USE dissip_gcm_mod
+  USE sponge_mod
   USE disvert_mod
   USE caldyn_mod
@@ -176,10 +179,8 @@
     INTEGER :: rate_clock
     INTEGER :: l
+    LOGICAL,SAVE :: first_physic=.TRUE.
+!$OMP THREADPRIVATE(first_physic)    
     
-    
-!    CALL write_etat0(f_ps, f_phis,f_theta_rhodz,f_u,f_q) 
-!    CALL read_start(f_ps,f_mass,f_phis,f_theta_rhodz,f_u,f_q) 
-!    CALL write_restart(f_ps,f_mass,f_phis,f_theta_rhodz,f_u,f_q) 
-    
+   
     CALL switch_omp_distrib_level
     CALL caldyn_BC(f_phis, f_wflux) ! set constant values in first/last interfaces
@@ -228,9 +229,4 @@
       CALL wait_message(req_q0) 
 
-!      CALL wait_message(req_ps0)
-!      CALL wait_message(req_mass0)
-!      CALL wait_message(req_theta_rhodz0) 
-!      CALL wait_message(req_u0)
-!      CALL wait_message(req_q0) 
     ENDIF
 
@@ -264,6 +260,4 @@
 
     IF (MOD(it,itau_dissip)==0) THEN
-!         CALL send_message(f_ps,req_ps)
-!         CALL wait_message(req_ps)  
        
        IF(caldyn_eta==eta_mass) THEN
@@ -278,11 +272,12 @@
           END DO
        ENDIF
-!       CALL send_message(f_mass,req_mass)
-!       CALL wait_message(req_mass)  
+
        CALL dissip(f_u,f_du,f_mass,f_phis, f_theta_rhodz,f_dtheta_rhodz)
 
-!       CALL send_message(f_mass,req_mass)
-!       CALL wait_message(req_mass)  
        CALL euler_scheme(.FALSE.)  ! update only u, theta
+       IF (iflag_sponge > 0) THEN
+         CALL sponge(f_u,f_du,f_theta_rhodz,f_dtheta_rhodz)
+         CALL euler_scheme(.FALSE.)  ! update only u, theta
+       ENDIF
     END IF
 
@@ -308,8 +303,16 @@
     END IF
 
-    CALL physics(it,f_phis, f_ps, f_theta_rhodz, f_u,  f_q)
 
     IF (MOD(it,itau_check_conserv)==0) THEN
-      CALL check_conserve(f_ps,f_dps,f_u,f_theta_rhodz,f_phis,it)  
+      CALL check_conserve(f_ps,f_dps,f_u,f_theta_rhodz,f_phis,it) 
+    ENDIF
+     
+    IF (MOD(it,itau_physics)==0) THEN
+      CALL physics(it,f_phis, f_ps, f_theta_rhodz, f_u, f_wflux, f_q)
+
+!$OMP MASTER
+   IF (first_physic) CALL SYSTEM_CLOCK(start_clock)
+!$OMP END MASTER   
+      first_physic=.FALSE.
     ENDIF
     
@@ -354,5 +357,5 @@
           ELSE ! update mass
              mass=f_mass(ind) ; dmass=f_dmass(ind) ;              
-             DO l=1,llm
+             DO l=ll_begin,ll_end
 !$SIMD
                 DO ij=ij_begin,ij_end
@@ -606,34 +609,3 @@
   END SUBROUTINE accumulate_fluxes
   
-!  FUNCTION maxval_i(p)
-!    USE icosa
-!    IMPLICIT NONE
-!    REAL(rstd), DIMENSION(iim*jjm) :: p
-!    REAL(rstd) :: maxval_i
-!    INTEGER :: j, ij
-!    
-!    maxval_i=p((jj_begin-1)*iim+ii_begin)
-!    
-!    DO j=jj_begin-1,jj_end+1
-!       ij=(j-1)*iim
-!       maxval_i = MAX(maxval_i, MAXVAL(p(ij+ii_begin:ij+ii_end)))
-!    END DO
-!  END FUNCTION maxval_i
-
-!  FUNCTION maxval_ik(p)
-!    USE icosa
-!    IMPLICIT NONE
-!    REAL(rstd) :: p(iim*jjm, llm)
-!    REAL(rstd) :: maxval_ik(llm)
-!    INTEGER :: l,j, ij
-!    
-!    DO l=1,llm
-!       maxval_ik(l)=p((jj_begin-1)*iim+ii_begin,l)
-!       DO j=jj_begin-1,jj_end+1
-!          ij=(j-1)*iim
-!          maxval_ik(l) = MAX(maxval_ik(l), MAXVAL(p(ij+ii_begin:ij+ii_end,l)))
-!       END DO
-!    END DO
-!  END FUNCTION maxval_ik
-
 END MODULE timeloop_gcm_mod
Index: codes/icosagcm/trunk/src/trace.F90
===================================================================
--- codes/icosagcm/trunk/src/trace.F90	(revision 326)
+++ codes/icosagcm/trunk/src/trace.F90	(revision 327)
@@ -43,4 +43,5 @@
      
   END SUBROUTINE trace_off
+
     
   SUBROUTINE trace_start(name)
@@ -59,4 +60,5 @@
   END SUBROUTINE trace_start    
 
+
   SUBROUTINE trace_end(name)
   IMPLICIT NONE
@@ -74,4 +76,6 @@
 
   END SUBROUTINE trace_end    
+
+
 
   SUBROUTINE trace_start2(name)
Index: codes/icosagcm/trunk/src/transfert_mpi.f90
===================================================================
--- codes/icosagcm/trunk/src/transfert_mpi.f90	(revision 326)
+++ codes/icosagcm/trunk/src/transfert_mpi.f90	(revision 327)
@@ -159,4 +159,6 @@
       DO j=jj_begin,jj_end
         CALL request_add_point(ind,ii_end+1,j,req_e1_scal,left)
+      ENDDO    
+      DO j=jj_begin,jj_end
         CALL request_add_point(ind,ii_end+1,j-1,req_e1_scal,lup)
       ENDDO    
@@ -169,4 +171,6 @@
       DO j=jj_begin,jj_end
         CALL request_add_point(ind,ii_begin-1,j,req_e1_scal,right)
+      ENDDO   
+      DO j=jj_begin,jj_end
         CALL request_add_point(ind,ii_begin-1,j+1,req_e1_scal,rdown)
       ENDDO   
@@ -213,4 +217,6 @@
       DO j=jj_begin,jj_end
         CALL request_add_point(ind,ii_end+1,j,req_e1_vect,left)
+      ENDDO    
+      DO j=jj_begin,jj_end
         CALL request_add_point(ind,ii_end+1,j-1,req_e1_vect,lup)
       ENDDO    
@@ -223,4 +229,6 @@
       DO j=jj_begin,jj_end
         CALL request_add_point(ind,ii_begin-1,j,req_e1_vect,right)
+      ENDDO   
+      DO j=jj_begin,jj_end
         CALL request_add_point(ind,ii_begin-1,j+1,req_e1_vect,rdown)
       ENDDO   
@@ -1096,6 +1104,7 @@
     INTEGER,POINTER :: sign(:)
     INTEGER :: offset,msize,rank
-
-    CALL trace_start("transfert_mpi")
+    INTEGER :: lbegin, lend
+
+!    CALL trace_start("send_message_mpi")
 
 !$OMP BARRIER
@@ -1192,7 +1201,9 @@
       
         DO ind=1,ndomain
-          IF (.NOT. assigned_domain(ind) .OR. .NOT. is_omp_level_master) CYCLE
+          IF (.NOT. assigned_domain(ind) ) CYCLE
 
           dim3=size(field(ind)%rval3d,2)
+          CALL distrib_level(dim3,lbegin,lend)
+
           rval3d=>field(ind)%rval3d
           req=>message%request(ind)
@@ -1205,7 +1216,10 @@
               ireq=send%ireq
               buffer_r=>message%buffers(ireq)%r
-              offset=send%offset*dim3
-
-              DO d3=1,dim3
+
+              offset=send%offset*dim3 + (lbegin-1)*send%size
+          
+              CALL trace_start("copy_to_buffer")
+
+              DO d3=lbegin,lend
                 DO n=1,send%size
                   buffer_r(n+offset)=rval3d(value(n),d3)
@@ -1213,11 +1227,14 @@
                 offset=offset+send%size
               ENDDO
-
-              IF (mpi_threading_mode==MPI_THREAD_SERIALIZED) THEN
-                !$OMP CRITICAL   
-                CALL MPI_ISEND(buffer_r,send%size*dim3,MPI_REAL8,send%rank,send%tag+1000*message%number,comm_icosa, message%mpi_req(ireq),ierr)
-                !$OMP END CRITICAL
-              ELSE IF (mpi_threading_mode==MPI_THREAD_MULTIPLE) THEN
-                CALL MPI_ISEND(buffer_r,send%size*dim3,MPI_REAL8,send%rank,send%tag+1000*message%number,comm_icosa, message%mpi_req(ireq),ierr)
+              CALL trace_end("copy_to_buffer")
+
+              IF (is_omp_level_master) THEN
+                IF (mpi_threading_mode==MPI_THREAD_SERIALIZED) THEN
+                  !$OMP CRITICAL   
+                  CALL MPI_ISEND(buffer_r,send%size*dim3,MPI_REAL8,send%rank,send%tag+1000*message%number,comm_icosa, message%mpi_req(ireq),ierr)
+                  !$OMP END CRITICAL
+                ELSE IF (mpi_threading_mode==MPI_THREAD_MULTIPLE) THEN
+                  CALL MPI_ISEND(buffer_r,send%size*dim3,MPI_REAL8,send%rank,send%tag+1000*message%number,comm_icosa, message%mpi_req(ireq),ierr)
+                ENDIF
               ENDIF
             ENDIF
@@ -1226,6 +1243,7 @@
          
         DO ind=1,ndomain
-          IF (.NOT. assigned_domain(ind) .OR. .NOT. is_omp_level_master) CYCLE
+          IF (.NOT. assigned_domain(ind) ) CYCLE
           dim3=size(field(ind)%rval3d,2)
+          CALL distrib_level(dim3,lbegin,lend)
           rval3d=>field(ind)%rval3d
           req=>message%request(ind)
@@ -1240,7 +1258,12 @@
               sgn=>recv%sign
 
-              DO n=1,recv%size
-                rval3d(value(n),:)=src_rval3d(src_value(n),:)*sgn(n)
+              CALL trace_start("copy_data")
+
+              DO d3=lbegin,lend
+                DO n=1,recv%size
+                  rval3d(value(n),d3)=src_rval3d(src_value(n),d3)*sgn(n)
+                ENDDO
               ENDDO
+              CALL trace_end("copy_data")
 
             ELSE
@@ -1248,12 +1271,14 @@
               buffer_r=>message%buffers(ireq)%r
  
-              IF (mpi_threading_mode==MPI_THREAD_SERIALIZED) THEN
-                !$OMP CRITICAL
-                CALL MPI_IRECV(buffer_r,recv%size*dim3,MPI_REAL8,recv%rank,recv%tag+1000*message%number,comm_icosa, message%mpi_req(ireq),ierr)
-                !$OMP END CRITICAL
-              ELSE IF (mpi_threading_mode==MPI_THREAD_MULTIPLE) THEN
-                CALL MPI_IRECV(buffer_r,recv%size*dim3,MPI_REAL8,recv%rank,recv%tag+1000*message%number,comm_icosa, message%mpi_req(ireq),ierr)
+              IF (is_omp_level_master) THEN
+                IF (mpi_threading_mode==MPI_THREAD_SERIALIZED) THEN
+                  !$OMP CRITICAL
+                  CALL MPI_IRECV(buffer_r,recv%size*dim3,MPI_REAL8,recv%rank,recv%tag+1000*message%number,comm_icosa, message%mpi_req(ireq),ierr)
+                  !$OMP END CRITICAL
+                ELSE IF (mpi_threading_mode==MPI_THREAD_MULTIPLE) THEN
+                  CALL MPI_IRECV(buffer_r,recv%size*dim3,MPI_REAL8,recv%rank,recv%tag+1000*message%number,comm_icosa, message%mpi_req(ireq),ierr)
+                ENDIF
               ENDIF
-            ENDIF
+            ENDIF  
           ENDDO
         
@@ -1263,7 +1288,8 @@
     
         DO ind=1,ndomain
-          IF (.NOT. assigned_domain(ind) .OR. .NOT. is_omp_level_master ) CYCLE
+          IF (.NOT. assigned_domain(ind) ) CYCLE
 
           dim3=size(field(ind)%rval4d,2)
+          CALL distrib_level(dim3,lbegin,lend)
           dim4=size(field(ind)%rval4d,3)
           rval4d=>field(ind)%rval4d
@@ -1278,8 +1304,10 @@
               ireq=send%ireq
               buffer_r=>message%buffers(ireq)%r
-              offset=send%offset*dim3*dim4
-
+
+              CALL trace_start("copy_to_buffer")
               DO d4=1,dim4
-                DO d3=1,dim3
+                offset=send%offset*dim3*dim4 + dim3*send%size*(d4-1) + (lbegin-1)*send%size
+
+                DO d3=lbegin,lend
                   DO n=1,send%size
                     buffer_r(n+offset)=rval4d(value(n),d3,d4)
@@ -1288,11 +1316,14 @@
                 ENDDO
               ENDDO
-
-              IF (mpi_threading_mode==MPI_THREAD_SERIALIZED) THEN
-                !$OMP CRITICAL
-                CALL MPI_ISEND(buffer_r,send%size*dim3*dim4,MPI_REAL8,send%rank,send%tag+1000*message%number,comm_icosa, message%mpi_req(ireq),ierr)
-                !$OMP END CRITICAL
-              ELSE IF (mpi_threading_mode==MPI_THREAD_MULTIPLE) THEN
-                CALL MPI_ISEND(buffer_r,send%size*dim3*dim4,MPI_REAL8,send%rank,send%tag+1000*message%number,comm_icosa, message%mpi_req(ireq),ierr)
+              CALL trace_end("copy_to_buffer")
+
+              IF (is_omp_level_master) THEN
+                IF (mpi_threading_mode==MPI_THREAD_SERIALIZED) THEN
+                  !$OMP CRITICAL
+                  CALL MPI_ISEND(buffer_r,send%size*dim3*dim4,MPI_REAL8,send%rank,send%tag+1000*message%number,comm_icosa, message%mpi_req(ireq),ierr)
+                  !$OMP END CRITICAL
+                ELSE IF (mpi_threading_mode==MPI_THREAD_MULTIPLE) THEN
+                  CALL MPI_ISEND(buffer_r,send%size*dim3*dim4,MPI_REAL8,send%rank,send%tag+1000*message%number,comm_icosa, message%mpi_req(ireq),ierr)
+                ENDIF
               ENDIF
 
@@ -1302,7 +1333,8 @@
         
         DO ind=1,ndomain
-          IF (.NOT. assigned_domain(ind) .OR. .NOT. is_omp_level_master) CYCLE
+          IF (.NOT. assigned_domain(ind) ) CYCLE
           
           dim3=size(field(ind)%rval4d,2)
+          CALL distrib_level(dim3,lbegin,lend)
           dim4=size(field(ind)%rval4d,3)
           rval4d=>field(ind)%rval4d
@@ -1317,7 +1349,14 @@
               sgn=>recv%sign
 
-              DO n=1,recv%size
-                rval4d(value(n),:,:)=src_rval4d(src_value(n),:,:)*sgn(n)
+              CALL trace_start("copy_data")
+              DO d4=1,dim4
+                DO d3=lbegin,lend
+                  DO n=1,recv%size
+                    rval4d(value(n),d3,d4)=src_rval4d(src_value(n),d3,d4)*sgn(n)
+                  ENDDO
+                ENDDO
               ENDDO
+                
+              CALL trace_end("copy_data")
                    
             ELSE
@@ -1325,12 +1364,13 @@
               ireq=recv%ireq
               buffer_r=>message%buffers(ireq)%r
-              IF (mpi_threading_mode==MPI_THREAD_SERIALIZED) THEN
-                !$OMP CRITICAL           
-                CALL MPI_IRECV(buffer_r,recv%size*dim3*dim4,MPI_REAL8,recv%rank,recv%tag+1000*message%number,comm_icosa, message%mpi_req(ireq),ierr) 
-                !$OMP END CRITICAL
-              ELSE IF (mpi_threading_mode==MPI_THREAD_MULTIPLE) THEN
-                CALL MPI_IRECV(buffer_r,recv%size*dim3*dim4,MPI_REAL8,recv%rank,recv%tag+1000*message%number,comm_icosa, message%mpi_req(ireq),ierr) 
+              IF (is_omp_level_master) THEN
+                IF (mpi_threading_mode==MPI_THREAD_SERIALIZED) THEN
+                 !$OMP CRITICAL           
+                  CALL MPI_IRECV(buffer_r,recv%size*dim3*dim4,MPI_REAL8,recv%rank,recv%tag+1000*message%number,comm_icosa, message%mpi_req(ireq),ierr) 
+                  !$OMP END CRITICAL
+                ELSE IF (mpi_threading_mode==MPI_THREAD_MULTIPLE) THEN
+                  CALL MPI_IRECV(buffer_r,recv%size*dim3*dim4,MPI_REAL8,recv%rank,recv%tag+1000*message%number,comm_icosa, message%mpi_req(ireq),ierr) 
+                ENDIF
               ENDIF
-    
             ENDIF
           ENDDO
@@ -1362,5 +1402,5 @@
     
 !$OMP BARRIER
-    CALL trace_end("transfert_mpi")
+!    CALL trace_end("send_message_mpi")
     
   END SUBROUTINE send_message_mpi
@@ -1402,10 +1442,10 @@
     INTEGER :: ireq,nreq
     INTEGER :: ind,n,l,m,i
-    INTEGER :: dim3,dim4,d3,d4
+    INTEGER :: dim3,dim4,d3,d4,lbegin,lend
     INTEGER :: offset
 
     IF (.NOT. message%pending) RETURN
 
-    CALL trace_start("transfert_mpi")
+!    CALL trace_start("wait_message_mpi")
 
     field=>message%field
@@ -1452,5 +1492,5 @@
         
         DO ind=1,ndomain
-          IF (.NOT. assigned_domain(ind) .OR. .NOT. is_omp_level_master) CYCLE
+          IF (.NOT. assigned_domain(ind) ) CYCLE
 
           rval3d=>field(ind)%rval3d
@@ -1465,11 +1505,26 @@
               
               dim3=size(rval3d,2)
-              offset=recv%offset*dim3
-              DO d3=1,dim3
-                DO n=1,recv%size
-                  rval3d(value(n),d3)=buffer_r(n+offset)*sgn(n)  
+    
+              CALL distrib_level(dim3,lbegin,lend)
+              offset=recv%offset*dim3 + (lbegin-1)*recv%size
+              CALL trace_start("copy_from_buffer")
+              
+              IF (req%vector) THEN
+                DO d3=lbegin,lend
+                  DO n=1,recv%size
+                    rval3d(value(n),d3)=buffer_r(n+offset)*sgn(n)  
+                  ENDDO
+                  offset=offset+recv%size
                 ENDDO
-                offset=offset+recv%size
-              ENDDO  
+              ELSE
+                DO d3=lbegin,lend
+                  DO n=1,recv%size
+                    rval3d(value(n),d3)=buffer_r(n+offset)  
+                  ENDDO
+                  offset=offset+recv%size
+                ENDDO
+              ENDIF
+                
+              CALL trace_end("copy_from_buffer")
             ENDIF
           ENDDO
@@ -1485,5 +1540,5 @@
                 
         DO ind=1,ndomain
-          IF (.NOT. assigned_domain(ind) .OR. .NOT. is_omp_level_master) CYCLE
+          IF (.NOT. assigned_domain(ind) ) CYCLE
 
           rval4d=>field(ind)%rval4d
@@ -1498,8 +1553,10 @@
 
               dim3=size(rval4d,2)
+              CALL distrib_level(dim3,lbegin,lend)
               dim4=size(rval4d,3)
-              offset=recv%offset*dim3*dim4
+              CALL trace_start("copy_from_buffer")
               DO d4=1,dim4
-                DO d3=1,dim3
+                offset=recv%offset*dim3*dim4 + dim3*recv%size*(d4-1) + (lbegin-1)*recv%size
+                DO d3=lbegin,lend
                   DO n=1,recv%size
                     rval4d(value(n),d3,d4)=buffer_r(n+offset)*sgn(n) 
@@ -1508,4 +1565,5 @@
                 ENDDO
               ENDDO
+              CALL trace_end("copy_from_buffer")
             ENDIF
           ENDDO
@@ -1521,5 +1579,5 @@
 !$OMP END MASTER
 
-    CALL trace_end("transfert_mpi")
+!    CALL trace_end("wait_message_mpi")
 !$OMP BARRIER
     
@@ -1728,7 +1786,5 @@
         
   END SUBROUTINE scatter_field
-
-
-   
+  
   SUBROUTINE trace_in
   USE trace
@@ -1752,5 +1808,5 @@
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
-!! -- Les chaine de charactère -- !!
+!! -- Les chaine de charactï¿œre -- !!
 
   SUBROUTINE bcast_mpi_c(var1)
@@ -1949,5 +2005,5 @@
     IF (.NOT. using_mpi) RETURN
 
-    CALL MPI_BCAST(Var,nb,MPI_REAL,mpi_master,comm_icosa,ierr)
+    CALL MPI_BCAST(Var,nb,MPI_REAL8,mpi_master,comm_icosa,ierr)
     
   END SUBROUTINE bcast_mpi_rgen
Index: codes/icosagcm/trunk/src/transfert_omp.f90
===================================================================
--- codes/icosagcm/trunk/src/transfert_omp.f90	(revision 326)
+++ codes/icosagcm/trunk/src/transfert_omp.f90	(revision 327)
@@ -102,5 +102,5 @@
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
-!! -- Les chaine de charactère -- !!
+!! -- Les chaine de charactï¿œre -- !!
 
   SUBROUTINE bcast_omp_c(var)
