Index: /codes/icosagcm/trunk/src/caldyn_gcm.f90
===================================================================
--- /codes/icosagcm/trunk/src/caldyn_gcm.f90	(revision 20)
+++ /codes/icosagcm/trunk/src/caldyn_gcm.f90	(revision 21)
@@ -112,5 +112,5 @@
   REAL(rstd),POINTER :: dtheta_rhodz(:,:)
   REAL(rstd),POINTER :: du(:,:)
-  INTEGER :: ind
+  INTEGER :: ind,ij
 
   
@@ -119,5 +119,5 @@
     CALL transfert_request(f_theta_rhodz,req_i1) 
     CALL transfert_request(f_u,req_e1)
-    CALL transfert_request(f_u,req_e1) 
+!    CALL transfert_request(f_u,req_e1) 
    
 
@@ -136,5 +136,21 @@
       dtheta_rhodz=f_dtheta_rhodz(ind)
       du=f_du(ind)
-      
+!      ij=(jj_end-1-1)*iim+ii_begin
+!      PRINT *,"--> ind=",ind,ij
+!      PRINT *,u(ij+u_right,1)
+!      PRINT *,u(ij+u_rup,1)
+!      PRINT *,u(ij+u_lup,1)
+!      PRINT *,u(ij+u_left,1)
+!      PRINT *,u(ij+u_ldown,1)
+!      PRINT *,u(ij+u_rdown,1)
+
+!      ij=(jj_end-1-1)*iim+ii_end
+!      PRINT *,"--> ind=",ind,ij
+!      PRINT *,u(ij+u_right,1)
+!      PRINT *,u(ij+u_rup,1)
+!      PRINT *,u(ij+u_lup,1)
+!      PRINT *,u(ij+u_left,1)
+!      PRINT *,u(ij+u_ldown,1)
+!      PRINT *,u(ij+u_rdown,1)      
 !$OMP PARALLEL DEFAULT(SHARED)
       CALL compute_caldyn(phis, ps, theta_rhodz, u, dps, dtheta_rhodz, du)
@@ -143,13 +159,14 @@
 
     CALL transfert_request(f_out_u,req_e1)
-    CALL transfert_request(f_out_u,req_e1) 
+!    CALL transfert_request(f_out_u,req_e1) 
 
 !    CALL vorticity(f_u,f_out_z)
-!    CALL kinetic(f_du,f_out)
 
     IF (mod(it,itau_out)==0 ) THEN
       CALL writefield("ps",f_ps)
-!      CALL writefield("dps",f_dps)
+      CALL writefield("dps",f_dps)
 !      CALL writefield("theta_rhodz",f_theta_rhodz)
+!    CALL kinetic(f_u,f_out)
+!      CALL writefield("Ki",f_out)
 !      CALL writefield("dtheta_rhodz",f_dtheta_rhodz)
       CALL vorticity(f_u,f_out_z)
@@ -163,4 +180,5 @@
 !        CALL writefield("Ki",f_out,ind)
 !        CALL writefield("vort",f_out_z,ind)
+!        CALL writefield("dps",f_dps,ind)
 !      ENDDO
 
Index: /codes/icosagcm/trunk/src/domain.f90
===================================================================
--- /codes/icosagcm/trunk/src/domain.f90	(revision 20)
+++ /codes/icosagcm/trunk/src/domain.f90	(revision 21)
@@ -19,4 +19,8 @@
     INTEGER,POINTER  :: assign_i(:,:)
     INTEGER,POINTER  :: assign_j(:,:)
+    INTEGER,POINTER  :: edge_assign_domain(:,:,:)
+    INTEGER,POINTER  :: edge_assign_i(:,:,:)
+    INTEGER,POINTER  :: edge_assign_j(:,:,:)
+    INTEGER,POINTER  :: edge_assign_pos(:,:,:)
     REAL,POINTER     :: xyz(:,:,:)
     REAL,POINTER     :: neighbour(:,:,:,:)
@@ -71,6 +75,6 @@
     ind=0
     DO nf=1,nb_face
-      DO nj=1,nsplit_i
-        DO ni=1,nsplit_j
+      DO nj=1,nsplit_j
+        DO ni=1,nsplit_i
           ind=ind+1
           d=>domain(ind)
@@ -85,4 +89,10 @@
           ENDIF
           d%ii_end_glo=d%ii_begin_glo+d%ii_nb-1
+ 
+          IF (ni/=nsplit_i) THEN 
+            d%ii_nb=d%ii_nb+1
+            d%ii_end_glo=d%ii_end_glo+1
+          ENDIF
+         
         
           quotient=(jjm_glo/nsplit_j)
@@ -95,6 +105,12 @@
             d%jj_begin_glo=(quotient+1)*rest+(nj-1-rest) * quotient+1
           ENDIF
-
           d%jj_end_glo=d%jj_begin_glo+d%jj_nb-1
+
+          IF (nj/=nsplit_j) THEN 
+            d%jj_nb=d%jj_nb+1
+            d%jj_end_glo=d%jj_end_glo+1
+          ENDIF
+
+
           d%iim=d%ii_nb+2*halo
           d%jjm=d%jj_nb+2*halo
@@ -107,4 +123,8 @@
           ALLOCATE(d%assign_i(d%iim,d%jjm))
           ALLOCATE(d%assign_j(d%iim,d%jjm))
+          ALLOCATE(d%edge_assign_domain(0:5,d%iim,d%jjm))
+          ALLOCATE(d%edge_assign_i(0:5,d%iim,d%jjm))
+          ALLOCATE(d%edge_assign_j(0:5,d%iim,d%jjm))
+          ALLOCATE(d%edge_assign_pos(0:5,d%iim,d%jjm))
           ALLOCATE(d%delta(d%iim,d%jjm))
           ALLOCATE(d%xyz(3,d%iim,d%jjm))
@@ -123,8 +143,9 @@
   USE metric
   IMPLICIT NONE
-    INTEGER :: ind_d,ind,ind2
+    INTEGER :: ind_d,ind,ind2,e
     INTEGER :: nf
     INTEGER :: i,j,k,ii,jj
     TYPE(t_domain),POINTER :: d
+    INTEGER :: delta
      
     
@@ -137,4 +158,5 @@
           jj=d%jj_begin_glo-d%jj_begin+j
           ind=vertex_glo(ii,jj,nf)%ind
+          delta=vertex_glo(ii,jj,nf)%delta
           IF (cell_glo(ind)%assign_face==nf) THEN 
             cell_glo(ind)%assign_domain=ind_d
@@ -142,7 +164,14 @@
             cell_glo(ind)%assign_j=j
           ENDIF
+          IF ( i+1 <= d%ii_end ) CALL assign_edge(ind_d,ind,i,j,delta,0)
+          IF ( j+1 <= d%jj_end ) CALL assign_edge(ind_d,ind,i,j,delta,1)
+          IF ( i-1 >= d%ii_begin .AND. j+1<=d%jj_end ) CALL assign_edge(ind_d,ind,i,j,delta,2)
+          IF ( i-1 >= d%ii_begin ) CALL assign_edge(ind_d,ind,i,j,delta,3)
+          IF ( j-1 >= d%jj_begin ) CALL assign_edge(ind_d,ind,i,j,delta,4)
+          IF ( i+1 <= d%ii_end .AND. j-1 >=d%jj_begin ) CALL assign_edge(ind_d,ind,i,j,delta,5)
         ENDDO
       ENDDO
     ENDDO
+    
     
     DO ind_d=1,ndomain
@@ -157,4 +186,5 @@
           d%assign_i(i,j)=cell_glo(ind)%assign_i
           d%assign_j(i,j)=cell_glo(ind)%assign_j
+          delta=vertex_glo(ii,jj,nf)%delta
           d%delta(i,j)=vertex_glo(ii,jj,nf)%delta
           DO k=0,5
@@ -162,4 +192,9 @@
             d%neighbour(:,k,i,j)=cell_glo(ind2)%xyz(:)
             d%ne(k,i,j)=vertex_glo(ii,jj,nf)%ne(k)
+            e=cell_glo(ind)%edge(MOD(k+delta+6,6))
+            d%edge_assign_domain(k,i,j)=edge_glo(e)%assign_domain
+            d%edge_assign_i(k,i,j)=edge_glo(e)%assign_i
+            d%edge_assign_j(k,i,j)=edge_glo(e)%assign_j
+            d%edge_assign_pos(k,i,j)=edge_glo(e)%assign_pos
           ENDDO
           d%xyz(:,i,j)=cell_glo(ind)%xyz(:)
@@ -171,5 +206,19 @@
         ENDDO
       ENDDO
-    ENDDO    
+    ENDDO
+
+  CONTAINS
+
+    SUBROUTINE assign_edge(ind_d,ind,i,j,delta,k)
+      INTEGER :: ind_d,ind,i,j,delta,k
+      INTEGER :: e
+      e=cell_glo(ind)%edge(MOD(k+delta+6,6))
+      edge_glo(e)%assign_domain=ind_d
+      edge_glo(e)%assign_i=i
+      edge_glo(e)%assign_j=j
+      edge_glo(e)%assign_pos=k
+!      PRINT*,"Assign_edge",ind_d,ind,i,j,k,e
+     END  SUBROUTINE assign_edge
+         
   END SUBROUTINE assign_cell
 
Index: /codes/icosagcm/trunk/src/geometry.f90
===================================================================
--- /codes/icosagcm/trunk/src/geometry.f90	(revision 20)
+++ /codes/icosagcm/trunk/src/geometry.f90	(revision 21)
@@ -257,5 +257,5 @@
     REAL(rstd) :: surf_v(6)
     REAL(rstd) :: vect(3,6)
-    REAL(rstd) :: centr(6)
+    REAL(rstd) :: centr(3)
     REAL(rstd) :: vet(3),vep(3)
     INTEGER :: ind,i,j,k,n
Index: /codes/icosagcm/trunk/src/metric.f90
===================================================================
--- /codes/icosagcm/trunk/src/metric.f90	(revision 20)
+++ /codes/icosagcm/trunk/src/metric.f90	(revision 21)
@@ -25,4 +25,8 @@
    INTEGER :: e1
    INTEGER :: e2
+   INTEGER :: assign_domain
+   INTEGER :: assign_i
+   INTEGER :: assign_j
+   INTEGER :: assign_pos
   END TYPE t_edge_glo
     
Index: /codes/icosagcm/trunk/src/timeloop_gcm.f90
===================================================================
--- /codes/icosagcm/trunk/src/timeloop_gcm.f90	(revision 20)
+++ /codes/icosagcm/trunk/src/timeloop_gcm.f90	(revision 21)
@@ -90,5 +90,5 @@
   CALL init_caldyn(dt)
   CALL init_guided(dt)
-  CALL init_advect_tracer(dt)
+!  CALL init_advect_tracer(dt)
   
   CALL etat0(f_ps,f_phis,f_theta_rhodz,f_u, f_q)
@@ -99,5 +99,5 @@
     CALL guided(it,f_ps,f_theta_rhodz,f_u,f_q)
     CALL caldyn(it,f_phis,f_ps,f_theta_rhodz,f_u, f_dps, f_dtheta_rhodz, f_du)
-    CALL advect_tracer(f_ps,f_u,f_q)
+!    CALL advect_tracer(f_ps,f_u,f_q)
     
     SELECT CASE (TRIM(scheme))
@@ -116,5 +116,6 @@
 
       CASE default
-        PRINT*,'Bad selector for variable scheme : <', TRIM(scheme),"> options are <euler>, <leapfrog>, <leapfrog_matsuno>, <adam_bashforth>" 
+        PRINT*,'Bad selector for variable scheme : <', TRIM(scheme),             &
+               ' > options are <euler>, <leapfrog>, <leapfrog_matsuno>, <adam_bashforth>'
         STOP
         
Index: /codes/icosagcm/trunk/src/transfert.f90
===================================================================
--- /codes/icosagcm/trunk/src/transfert.f90	(revision 20)
+++ /codes/icosagcm/trunk/src/transfert.f90	(revision 21)
@@ -227,24 +227,26 @@
       ELSE IF (req%type_field==field_u) THEN
         IF (.NOT. PRESENT(pos)) STOP 'argument request_add_point non conforme'
-        
-        src_domain=domain(ind)%assign_domain(i,j)
+
+        src_domain=domain(ind)%edge_assign_domain(pos-1,i,j)
         src_iim=domain(src_domain)%iim
-        src_i=domain(ind)%assign_i(i,j)
-        src_j=domain(ind)%assign_j(i,j)
+        src_i=domain(ind)%edge_assign_i(pos-1,i,j)
+        src_j=domain(ind)%edge_assign_j(pos-1,i,j)
         src_n=(src_j-1)*src_iim+src_i
         src_delta=domain(ind)%delta(i,j)
         
-        src_pos=MOD(pos-1+src_delta+6,6)+1
-        
+!        src_pos=MOD(pos-1+src_delta+6,6)+1
+        src_pos=domain(ind)%edge_assign_pos(pos-1,i,j)+1
+                
         req%target_ind(req%size)=(j-1)*d%iim+i+d%u_pos(pos)
         req%src_domain(req%size)=src_domain
         req%src_ind(req%size)=src_n+domain(src_domain)%u_pos(src_pos)
 
-        req%target_i(req%size)=i
-        req%target_j(req%size)=j
-        req%src_i(req%size)=domain(ind)%assign_i(i,j)
-        req%src_j(req%size)=domain(ind)%assign_j(i,j)
-        
-!        PRINT *,ind,i,j,"src_delta",src_delta
+!        req%target_i(req%size)=i
+!        req%target_j(req%size)=j
+!        req%src_i(req%size)=domain(ind)%assign_i(i,j)
+!        req%src_j(req%size)=domain(ind)%assign_j(i,j)
+        
+!        PRINT *,"1--->",ind,i,j,pos
+!        PRINT *,"2--->",src_domain,src_i,src_j,src_pos
 
       ELSE IF (req%type_field==field_z) THEN
Index: /codes/icosagcm/trunk/src/wind.f90
===================================================================
--- /codes/icosagcm/trunk/src/wind.f90	(revision 20)
+++ /codes/icosagcm/trunk/src/wind.f90	(revision 21)
@@ -18,10 +18,11 @@
         DO i=ii_begin,ii_end
           ij=(j-1)*iim+i
-          ucenter(ij,:,l)=1/Ai(ij)*(  ne(ij,right)*ue(ij+u_right,l)*le(ij+u_right)*((xyz_v(ij+z_rdown,:)+xyz_i(ij+z_rup,:))/2  -centroid(ij,:))   &
-                                    + ne(ij,rup)*ue(ij+u_rup,l)*le(ij+u_rup)*((xyz_v(ij+z_rup,:)+xyz_i(ij+z_up,:))/2-centroid(ij,:))             &
-                                    + ne(ij,lup)*ue(ij+u_lup,l)*le(ij+u_lup)*((xyz_v(ij+z_up,:)+xyz_i(ij+z_lup,:))/2-centroid(ij,:))             &
-                                    + ne(ij,left)*ue(ij+u_left,l)*le(ij+u_left)*((xyz_i(ij+z_lup,:)+xyz_i(ij+z_ldown,:))/2-centroid(ij,:))       &
-                                    + ne(ij,ldown)*ue(ij+u_ldown,l)*le(ij+u_ldown)*((xyz_i(ij+z_ldown,:)+xyz_i(ij+z_down,:))/2-centroid(ij,:))   &
-                                    + ne(ij,rdown)*ue(ij+u_rdown,l)*le(ij+u_rdown)*((xyz_i(ij+z_down,:)+xyz_i(ij+z_rdown,:))/2-centroid(ij,:)) )
+          ucenter(ij,:,l)=1/Ai(ij)*                                                                                                &
+                        ( ne(ij,right)*ue(ij+u_right,l)*le(ij+u_right)*((xyz_v(ij+z_rdown,:)+xyz_i(ij+z_rup,:))/2  -centroid(ij,:))&
+                         + ne(ij,rup)*ue(ij+u_rup,l)*le(ij+u_rup)*((xyz_v(ij+z_rup,:)+xyz_i(ij+z_up,:))/2-centroid(ij,:))          &
+                         + ne(ij,lup)*ue(ij+u_lup,l)*le(ij+u_lup)*((xyz_v(ij+z_up,:)+xyz_i(ij+z_lup,:))/2-centroid(ij,:))          &
+                         + ne(ij,left)*ue(ij+u_left,l)*le(ij+u_left)*((xyz_i(ij+z_lup,:)+xyz_i(ij+z_ldown,:))/2-centroid(ij,:))    &
+                         + ne(ij,ldown)*ue(ij+u_ldown,l)*le(ij+u_ldown)*((xyz_i(ij+z_ldown,:)+xyz_i(ij+z_down,:))/2-centroid(ij,:))&
+                         + ne(ij,rdown)*ue(ij+u_rdown,l)*le(ij+u_rdown)*((xyz_i(ij+z_down,:)+xyz_i(ij+z_rdown,:))/2-centroid(ij,:)))
         ENDDO
       ENDDO
Index: /codes/icosagcm/trunk/src/write_field.f90
===================================================================
--- /codes/icosagcm/trunk/src/write_field.f90	(revision 20)
+++ /codes/icosagcm/trunk/src/write_field.f90	(revision 21)
@@ -154,5 +154,6 @@
             ENDDO
           ENDDO
-          status=NF90_PUT_VAR(FieldId(Index),FieldVarId(index)%nc_id(1),Field_val2d,start=(/ ncell,FieldIndex(Index) /),count=(/n,1 /))
+          status=NF90_PUT_VAR(FieldId(Index),FieldVarId(index)%nc_id(1),Field_val2d,  &
+                              start=(/ ncell,FieldIndex(Index) /),count=(/n,1 /))
           DEALLOCATE(field_val2d)
         ELSE IF (field(ind)%ndim==3) THEN
@@ -238,5 +239,6 @@
           ENDDO
 
-          status=NF90_PUT_VAR(FieldId(Index),FieldVarId(index)%nc_id(1),Field_val2d,start=(/ ncell,FieldIndex(Index) /),count=(/n,1 /))
+          status=NF90_PUT_VAR(FieldId(Index),FieldVarId(index)%nc_id(1),                       &
+                              Field_val2d,start=(/ ncell,FieldIndex(Index) /),count=(/n,1 /))
           DEALLOCATE(field_val2d)
 
@@ -397,5 +399,6 @@
         ELSE IF (Field(ind_b)%ndim==4) THEN
           DO i=1,FieldVarId(NbField)%size
-            status = NF90_DEF_VAR(ncid,TRIM(ADJUSTL(name))//int2str(i),NF90_DOUBLE,(/ ncellId,dim3id,timeId /),FieldVarId(NbField)%nc_id(i))
+            status = NF90_DEF_VAR(ncid,TRIM(ADJUSTL(name))//int2str(i),NF90_DOUBLE,(/ ncellId,dim3id,timeId /),  &
+                                  FieldVarId(NbField)%nc_id(i))
             status = NF90_PUT_ATT(ncid,FieldVarId(NbField)%nc_id(i),"coordinates","lon lat")
           ENDDO        
@@ -504,5 +507,6 @@
         ELSE IF (Field(ind_b)%ndim==4) THEN
           DO q=1,FieldVarId(NbField)%size
-            status = NF90_DEF_VAR(ncid,TRIM(ADJUSTL(name)//int2str(q)),NF90_DOUBLE,(/ ncellId,dim3id,timeId /),FieldVarId(NbField)%nc_id(q))
+            status = NF90_DEF_VAR(ncid,TRIM(ADJUSTL(name)//int2str(q)),NF90_DOUBLE,             &
+                                  (/ ncellId,dim3id,timeId /),FieldVarId(NbField)%nc_id(q))
             status = NF90_PUT_ATT(ncid,FieldVarId(NbField)%nc_id(q),"coordinates","lon lat")
           ENDDO        
