Index: codes/icosagcm/trunk/src/caldyn_gcm.f90
===================================================================
--- codes/icosagcm/trunk/src/caldyn_gcm.f90	(revision 265)
+++ codes/icosagcm/trunk/src/caldyn_gcm.f90	(revision 266)
@@ -300,6 +300,6 @@
 !            f_buf_i, f_buf_v, f_buf_u3d, f_buf_ulon, f_buf_ulat, f_buf_s, f_buf_p)
        CALL un2ulonlat(f_u, f_buf_ulon, f_buf_ulat)
-       CALL writefield("ulon",f_buf_ulon)
-       CALL writefield("ulat",f_buf_ulat)
+       CALL output_field("ulon",f_buf_ulon)
+       CALL output_field("ulat",f_buf_ulat)
 
        CALL output_field("ps",f_ps)
Index: codes/icosagcm/trunk/src/check_conserve.f90
===================================================================
--- codes/icosagcm/trunk/src/check_conserve.f90	(revision 265)
+++ codes/icosagcm/trunk/src/check_conserve.f90	(revision 266)
@@ -71,5 +71,5 @@
     IF (is_mpi_root) THEN 
 !$OMP MASTER       
-       IF ( it == 0  ) Then 
+       IF ( it == itau0  ) Then 
           ztot0 = ztot
           mtot0 = mtot
Index: codes/icosagcm/trunk/src/disvert_apbp.f90
===================================================================
--- codes/icosagcm/trunk/src/disvert_apbp.f90	(revision 265)
+++ codes/icosagcm/trunk/src/disvert_apbp.f90	(revision 266)
@@ -57,4 +57,6 @@
       ENDIF
     ENDDO
+    
+    CLOSE(unit)
 !$OMP END MASTER
     IF (omp_in_parallel()) THEN
@@ -74,8 +76,8 @@
       WRITE(*,*) "bp()=",bp
       WRITE(*,*) "Approximative mid-layer pressure, assuming a surface pressure preff=",preff," Pa"
-      WRITE(*,*) "and approximative mid-layer height, assuming an atmospheric scale height of ",scaleheight/1000," (km)"
+      WRITE(*,*) "and approximative mid-layer height, assuming an atmospheric scale height of ",scale_height/1000," (km)"
       DO l=1,llm
-        WRITE(*,*) 'PRESNIVS(',l,')=',presnivs(l),'  Z ~ ',log(preff/presnivs(l))*scaleheight/1000,       &
-                   ' DZ ~ ',scaleheight/1000*log((ap(l)+bp(l)*preff)/ max(ap(l+1)+bp(l+1)*preff,1.e-10))
+        WRITE(*,*) 'PRESNIVS(',l,')=',presnivs(l),'  Z ~ ',log(preff/presnivs(l))*scale_height/1000,       &
+                   ' DZ ~ ',scale_height/1000*log((ap(l)+bp(l)*preff)/ max(ap(l+1)+bp(l+1)*preff,1.e-10))
       ENDDO
 !$OMP END MASTER
Index: codes/icosagcm/trunk/src/disvert_std.f90
===================================================================
--- codes/icosagcm/trunk/src/disvert_std.f90	(revision 265)
+++ codes/icosagcm/trunk/src/disvert_std.f90	(revision 266)
@@ -70,8 +70,8 @@
       WRITE(*,*) "bp()=",bp
       WRITE(*,*) "Approximative mid-layer pressure, assuming a surface pressure preff=",preff," Pa"
-      WRITE(*,*) "and approximative mid-layer height, assuming an atmospheric scale height of ",scaleheight/1000," (km)"
+      WRITE(*,*) "and approximative mid-layer height, assuming an atmospheric scale height of ",scale_height/1000," (km)"
       DO l=1,llm
-        WRITE(*,*) 'PRESNIVS(',l,')=',presnivs(l),'  Z ~ ',log(preff/presnivs(l))*scaleheight/1000,       &
-                   ' DZ ~ ',scaleheight/1000*log((ap(l)+bp(l)*preff)/ max(ap(l+1)+bp(l+1)*preff,1.e-10))
+        WRITE(*,*) 'PRESNIVS(',l,')=',presnivs(l),'  Z ~ ',log(preff/presnivs(l))*scale_height/1000,       &
+                   ' DZ ~ ',scale_height/1000*log((ap(l)+bp(l)*preff)/ max(ap(l+1)+bp(l+1)*preff,1.e-10))
       ENDDO
 !$OMP END MASTER
Index: codes/icosagcm/trunk/src/domain.f90
===================================================================
--- codes/icosagcm/trunk/src/domain.f90	(revision 265)
+++ codes/icosagcm/trunk/src/domain.f90	(revision 266)
@@ -17,4 +17,5 @@
     INTEGER :: jj_end_glo
     INTEGER,POINTER  :: assign_domain(:,:)
+    INTEGER,POINTER  :: assign_cell_glo(:,:)
     INTEGER,POINTER  :: assign_i(:,:)
     INTEGER,POINTER  :: assign_j(:,:)
@@ -142,4 +143,5 @@
           d%face=nf        
           ALLOCATE(d%assign_domain(d%iim,d%jjm))
+          ALLOCATE(d%assign_cell_glo(d%iim,d%jjm))
           ALLOCATE(d%assign_i(d%iim,d%jjm))
           ALLOCATE(d%assign_j(d%iim,d%jjm))
@@ -183,4 +185,5 @@
     d2%jj_end_glo = d1%jj_end_glo
     d2%assign_domain => d1%assign_domain
+    d2%assign_cell_glo => d1%assign_cell_glo
     d2%assign_i => d1%assign_i
     d2%assign_j => d1%assign_j
@@ -268,4 +271,5 @@
           jj=d%jj_begin_glo-d%jj_begin+j
           ind=vertex_glo(ii,jj,nf)%ind
+          d%assign_cell_glo(i,j) = ind  
           d%assign_domain(i,j)=cell_glo(ind)%assign_domain
           d%assign_i(i,j)=cell_glo(ind)%assign_i
Index: codes/icosagcm/trunk/src/earth_const.f90
===================================================================
--- codes/icosagcm/trunk/src/earth_const.f90	(revision 265)
+++ codes/icosagcm/trunk/src/earth_const.f90	(revision 266)
@@ -11,6 +11,8 @@
   REAL(rstd),SAVE :: preff=101325.
   REAL(rstd),SAVE :: pa=50000.
-  REAL(rstd),SAVE :: scaleheight=8000. ! atmospheric scale height (m)
+  REAL(rstd),SAVE :: scale_height=8000. ! atmospheric scale height (m)
   REAL(rstd),SAVE :: scale_factor=1.
+  REAL(rstd),SAVE :: gas_constant = 8.3144621 
+  REAL(rstd),SAVE :: mu                 ! molar mass of the atmosphere
 
   LOGICAL, SAVE :: boussinesq
@@ -30,6 +32,7 @@
     CALL getin("cpp",cpp)  
     CALL getin("preff",preff)  
-    CALL getin("scaleheight",scaleheight)
+    CALL getin("scale_height",scale_height)
     
+    mu=kappa/cpp
     boussinesq=.FALSE.
     CALL getin("boussinesq",boussinesq)  
Index: codes/icosagcm/trunk/src/etat0.f90
===================================================================
--- codes/icosagcm/trunk/src/etat0.f90	(revision 265)
+++ codes/icosagcm/trunk/src/etat0.f90	(revision 266)
@@ -27,4 +27,5 @@
     USE dynetat0_gcm_mod, ONLY : dynetat0_start=>etat0 
     USE dynetat0_hz_mod,  ONLY : dynetat0_hz=>etat0 
+    USE etat0_start_file_mod, ONLY : etat0_start_file=>etat0  
 
     IMPLICIT NONE
@@ -66,4 +67,6 @@
        CALL etat0_collocated(f_phis,f_ps,f_mass,f_theta_rhodz,f_u, f_q)
        !------------------- Old interface --------------------
+    CASE ('start_file')
+       CALL etat0_start_file(f_ps,f_phis,f_theta_rhodz,f_u, f_q)
     CASE ('academic')
        CALL etat0_academic(f_ps,f_phis,f_theta_rhodz,f_u, f_q)
Index: codes/icosagcm/trunk/src/etat0_start_file.f90
===================================================================
--- codes/icosagcm/trunk/src/etat0_start_file.f90	(revision 266)
+++ codes/icosagcm/trunk/src/etat0_start_file.f90	(revision 266)
@@ -0,0 +1,71 @@
+MODULE etat0_start_file_mod
+
+
+
+
+CONTAINS
+  
+   
+  SUBROUTINE etat0(f_ps,f_phis,f_theta_rhodz,f_u, f_q)
+  USE icosa
+  USE restart_mod
+  USE wind_mod
+  USE write_field
+  USE time_mod
+  USE transfert_mod
+  IMPLICIT NONE
+    TYPE(t_field),POINTER :: f_ps(:)
+    TYPE(t_field),POINTER :: f_phis(:)
+    TYPE(t_field),POINTER :: f_theta_rhodz(:)
+    TYPE(t_field),POINTER :: f_u(:)
+    TYPE(t_field),POINTER :: f_q(:)
+  
+    TYPE(t_field),POINTER,SAVE :: f_ulon(:)
+    TYPE(t_field),POINTER,SAVE :: f_ulat(:)
+
+    LOGICAL :: etat0_start_file_colocated=.FALSE.
+    INTEGER :: ind
+
+      CALL getin("etat0_start_file_colocated",etat0_start_file_colocated)  
+
+      IF (.NOT. etat0_start_file_colocated) THEN    
+        CALL allocate_field(f_ulon,field_t,type_real,llm,name='ulon')
+        CALL allocate_field(f_ulat,field_t,type_real,llm,name='ulat')
+        CALL read_start(itau0,f_ps,f_phis,f_theta_rhodz,f_u, f_q)
+        CALL transfert_request(f_ps,req_i1)
+        CALL transfert_request(f_phis,req_i1)
+        CALL transfert_request(f_theta_rhodz,req_i1)
+        CALL transfert_request(f_q,req_i1)
+        CALL transfert_request(f_u,req_e1_vect)
+        CALL transfert_request(f_u,req_e0_vect)
+        CALL un2ulonlat(f_u,f_ulon,f_ulat)
+
+        CALL deallocate_field(f_ulon)
+        CALL deallocate_field(f_ulat)
+
+      ELSE
+        CALL allocate_field(f_ulon,field_t,type_real,llm,name='ulon')
+        CALL allocate_field(f_ulat,field_t,type_real,llm,name='ulat')
+        CALL read_start(itau0,f_ps,f_phis,f_theta_rhodz,f_ulon,f_ulat, f_q)
+        CALL transfert_request(f_ulat,req_i1)
+        CALL transfert_request(f_ulon,req_i1)
+
+        CALL ulonlat2un(f_ulon,f_ulat,f_u)
+
+        CALL transfert_request(f_ps,req_i1)
+        CALL transfert_request(f_phis,req_i1)
+        CALL transfert_request(f_theta_rhodz,req_i1)
+        CALL transfert_request(f_q,req_i1)
+        CALL transfert_request(f_u,req_e1_vect)
+        
+        CALL deallocate_field(f_ulon)
+        CALL deallocate_field(f_ulat)
+      ENDIF
+
+      CALL bcast(itau0)
+      CALL getin("etat0_start_iteration",itau0)        
+
+  END SUBROUTINE etat0
+  
+  
+END MODULE etat0_start_file_mod
Index: codes/icosagcm/trunk/src/field.f90
===================================================================
--- codes/icosagcm/trunk/src/field.f90	(revision 265)
+++ codes/icosagcm/trunk/src/field.f90	(revision 266)
@@ -116,5 +116,5 @@
   END SUBROUTINE allocate_field
 
-  SUBROUTINE allocate_field_glo(field,field_type,data_type,dim1,dim2)
+  SUBROUTINE allocate_field_glo(field,field_type,data_type,dim1,dim2,name)
   USE domain_mod
   IMPLICIT NONE
@@ -123,4 +123,5 @@
     INTEGER,INTENT(IN) :: data_type
     INTEGER,OPTIONAL :: dim1,dim2
+    CHARACTER(*), OPTIONAL :: name
     INTEGER :: ind
     INTEGER :: ii_size,jj_size
@@ -141,4 +142,9 @@
       ENDIF
     
+      IF(PRESENT(name)) THEN
+         field(ind)%name = name
+      ELSE
+         field(ind)%name = '(undefined)'
+      END IF
     
       field(ind)%data_type=data_type
@@ -180,5 +186,7 @@
     INTEGER :: ind
 
+!$OMP BARRIER
     DO ind=1,ndomain
+      IF (.NOT. assigned_domain(ind)) CYCLE
 
       data_type=field(ind)%data_type
@@ -199,5 +207,9 @@
       
    ENDDO
+!$OMP BARRIER
+!$OMP MASTER
    DEALLOCATE(field)
+!$OMP END MASTER
+!$OMP BARRIER
        
   END SUBROUTINE deallocate_field
Index: codes/icosagcm/trunk/src/geometry.f90
===================================================================
--- codes/icosagcm/trunk/src/geometry.f90	(revision 265)
+++ codes/icosagcm/trunk/src/geometry.f90	(revision 266)
@@ -83,5 +83,5 @@
   IMPLICIT NONE
   
-    CALL allocate_field(geom%Ai,field_t,type_real)
+    CALL allocate_field(geom%Ai,field_t,type_real,name='Ai')
     CALL allocate_field(geom%xyz_i,field_t,type_real,3)
     CALL allocate_field(geom%centroid,field_t,type_real,3)
Index: codes/icosagcm/trunk/src/mpi_mod.F90
===================================================================
--- codes/icosagcm/trunk/src/mpi_mod.F90	(revision 265)
+++ codes/icosagcm/trunk/src/mpi_mod.F90	(revision 266)
@@ -7,4 +7,6 @@
   INTEGER :: MPI_REAL8
   INTEGER :: MPI_INTEGER
+  INTEGER :: MPI_CHARACTER
+  INTEGER :: MPI_LOGICAL
   INTEGER :: MPI_ANY_SOURCE
   INTEGER :: MPI_MAX
Index: codes/icosagcm/trunk/src/mpipara.F90
===================================================================
--- codes/icosagcm/trunk/src/mpipara.F90	(revision 265)
+++ codes/icosagcm/trunk/src/mpipara.F90	(revision 266)
@@ -9,4 +9,7 @@
   LOGICAL,SAVE :: using_mpi
   LOGICAL,SAVE :: is_mpi_root
+  LOGICAL,SAVE :: is_mpi_master
+  LOGICAL,SAVE :: mpi_master
+  
   
   INTERFACE allocate_mpi_buffer
@@ -108,8 +111,11 @@
     ENDIF
     
+    mpi_master=0
     IF (mpi_rank==0) THEN 
       is_mpi_root=.TRUE.
+      is_mpi_master=.TRUE.
     ELSE
       is_mpi_root=.FALSE.
+      is_mpi_master=.FALSE.
     ENDIF
     
@@ -118,6 +124,12 @@
   SUBROUTINE finalize_mpipara
   USE mpi_mod
-  IMPLICIT NONE
-    
+#ifdef CPP_USING_XIOS
+  USE xios
+#endif
+  IMPLICIT NONE
+    
+#ifdef CPP_USING_XIOS
+      CALL xios_finalize
+#endif
     IF (using_mpi) CALL MPI_FINALIZE(ierr)
     
Index: codes/icosagcm/trunk/src/physics.f90
===================================================================
--- codes/icosagcm/trunk/src/physics.f90	(revision 265)
+++ codes/icosagcm/trunk/src/physics.f90	(revision 266)
@@ -51,5 +51,5 @@
   END SUBROUTINE init_physics
 
-  SUBROUTINE physics(it,jD_cur,jH_cur,f_phis, f_ps, f_theta_rhodz, f_ue, f_q)
+  SUBROUTINE physics(it,f_phis, f_ps, f_theta_rhodz, f_ue, f_q)
     USE icosa
     USE physics_interface_mod
@@ -58,5 +58,4 @@
     IMPLICIT NONE
     INTEGER, INTENT(IN)   :: it
-    REAL(rstd),INTENT(IN)::jD_cur,jH_cur
     TYPE(t_field),POINTER :: f_phis(:)
     TYPE(t_field),POINTER :: f_ps(:)
Index: codes/icosagcm/trunk/src/restart.f90
===================================================================
--- codes/icosagcm/trunk/src/restart.f90	(revision 266)
+++ codes/icosagcm/trunk/src/restart.f90	(revision 266)
@@ -0,0 +1,552 @@
+MODULE restart_mod
+  USE field_mod
+
+  TYPE t_field_array
+    TYPE(t_field),POINTER :: field(:)
+  END TYPE t_field_array
+
+
+
+CONTAINS
+  
+  SUBROUTINE write_restart(it,field0 ,field1 ,field2 ,field3 ,field4 ,field5 ,field6 ,field7 ,field8 ,field9,   &
+                           field10,field11,field12,field13,field14,field15,field16,field17,field18,field19 )
+  USE prec
+  USE metric
+  USE field_mod
+  USE domain_mod
+  USE netcdf_mod
+  USE mpipara
+  USE getin_mod
+  USE spherical_geom_mod
+  USE transfert_mod
+ 
+  IMPLICIT NONE 
+  INTEGER,INTENT(IN)     :: it
+
+  TYPE(t_field),POINTER,OPTIONAL,DIMENSION(:) :: field0 ,field1 ,field2 ,field3 ,field4 ,field5 ,field6 ,field7 ,field8 ,field9
+  TYPE(t_field),POINTER,OPTIONAL,DIMENSION(:) :: field10,field11,field12,field13,field14,field15,field16,field17,field18,field19
+
+  TYPE(t_field_array) :: field_array(20)
+  INTEGER             :: nfield
+  INTEGER             :: fieldId(20)
+   
+  TYPE(t_domain),POINTER :: d
+  TYPE(t_field),POINTER :: field_glo(:)
+  TYPE(t_field),POINTER :: field(:)
+  
+  CHARACTER(LEN=255) :: restart_file_name
+  INTEGER,PARAMETER  :: nvert=6
+  INTEGER    ::  ncid, cellId, levId, edgeId,  vertid, lonId, latId, bounds_lonId, bounds_latId, nqId
+  INTEGER    :: ind,ind_glo,i,j,k,nf
+  INTEGER    :: status
+  REAL(rstd),ALLOCATABLE :: lon(:),lat(:),bounds_lon(:,:),bounds_lat(:,:)
+   
+    restart_file_name="restart"
+    CALL getin("restart_file_name",restart_file_name)
+
+!$OMP MASTER
+
+    nfield=0
+    IF (PRESENT(field0))  THEN ; nfield=nfield+1 ; field_array(nfield)%field=>field0  ; ENDIF
+    IF (PRESENT(field1))  THEN ; nfield=nfield+1 ; field_array(nfield)%field=>field1  ; ENDIF
+    IF (PRESENT(field2))  THEN ; nfield=nfield+1 ; field_array(nfield)%field=>field2  ; ENDIF
+    IF (PRESENT(field3))  THEN ; nfield=nfield+1 ; field_array(nfield)%field=>field3  ; ENDIF
+    IF (PRESENT(field4))  THEN ; nfield=nfield+1 ; field_array(nfield)%field=>field4  ; ENDIF
+    IF (PRESENT(field5))  THEN ; nfield=nfield+1 ; field_array(nfield)%field=>field5  ; ENDIF
+    IF (PRESENT(field6))  THEN ; nfield=nfield+1 ; field_array(nfield)%field=>field6  ; ENDIF
+    IF (PRESENT(field7))  THEN ; nfield=nfield+1 ; field_array(nfield)%field=>field7  ; ENDIF
+    IF (PRESENT(field8))  THEN ; nfield=nfield+1 ; field_array(nfield)%field=>field8  ; ENDIF
+    IF (PRESENT(field9))  THEN ; nfield=nfield+1 ; field_array(nfield)%field=>field9  ; ENDIF
+    IF (PRESENT(field10)) THEN ; nfield=nfield+1 ; field_array(nfield)%field=>field10 ; ENDIF
+    IF (PRESENT(field11)) THEN ; nfield=nfield+1 ; field_array(nfield)%field=>field11 ; ENDIF
+    IF (PRESENT(field12)) THEN ; nfield=nfield+1 ; field_array(nfield)%field=>field12 ; ENDIF
+    IF (PRESENT(field13)) THEN ; nfield=nfield+1 ; field_array(nfield)%field=>field13 ; ENDIF
+    IF (PRESENT(field14)) THEN ; nfield=nfield+1 ; field_array(nfield)%field=>field14 ; ENDIF
+    IF (PRESENT(field15)) THEN ; nfield=nfield+1 ; field_array(nfield)%field=>field15 ; ENDIF
+    IF (PRESENT(field16)) THEN ; nfield=nfield+1 ; field_array(nfield)%field=>field16 ; ENDIF
+    IF (PRESENT(field17)) THEN ; nfield=nfield+1 ; field_array(nfield)%field=>field17 ; ENDIF
+    IF (PRESENT(field18)) THEN ; nfield=nfield+1 ; field_array(nfield)%field=>field18 ; ENDIF
+    IF (PRESENT(field19)) THEN ; nfield=nfield+1 ; field_array(nfield)%field=>field19 ; ENDIF
+    
+      
+
+    IF (is_mpi_root) THEN
+      status = NF90_CREATE(TRIM(ADJUSTL(restart_file_name))//'.nc', NF90_CLOBBER, ncid)
+      status = NF90_DEF_DIM(ncid,'cell',ncell_glo,cellId)
+      status = NF90_DEF_DIM(ncid,'edge',3*ncell_glo,edgeId)
+      status = NF90_DEF_DIM(ncid,'lev',llm,levId)
+      status = NF90_DEF_DIM(ncid,'nvert',nvert,vertId)
+      status = NF90_DEF_DIM(ncid,'nq',nqtot,nqId)
+      status = NF90_PUT_ATT(ncid,NF90_GLOBAL,"iteration",it)
+      
+      status = NF90_DEF_VAR(ncid,'lon',NF90_DOUBLE,(/ cellId /),lonId)
+      status = NF90_PUT_ATT(ncid,lonId,"long_name","longitude")
+      status = NF90_PUT_ATT(ncid,lonId,"units","degrees_east")
+      status = NF90_PUT_ATT(ncid,lonId,"bounds","bounds_lon")
+      status = NF90_DEF_VAR(ncid,'lat',NF90_DOUBLE,(/ cellId /),latId)
+      status = NF90_PUT_ATT(ncid,latId,"long_name","latitude")
+      status = NF90_PUT_ATT(ncid,latId,"units","degrees_north")
+      status = NF90_PUT_ATT(ncid,latId,"bounds","bounds_lat")
+      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)
+      
+      DO nf=1,nfield
+        field=>field_array(nf)%field
+        IF (field(1)%field_type==field_T) THEN
+          IF (field(1)%ndim==2) THEN
+            status = NF90_DEF_VAR(ncid,TRIM(ADJUSTL(field(1)%name)),NF90_DOUBLE,(/ cellId /),fieldId(nf))
+          ELSE IF (field(1)%ndim==3) THEN
+            status = NF90_DEF_VAR(ncid,TRIM(ADJUSTL(field(1)%name)),NF90_DOUBLE,(/ cellId, levId /),fieldId(nf))
+          ELSE IF (field(1)%ndim==4) THEN
+            status = NF90_DEF_VAR(ncid,TRIM(ADJUSTL(field(1)%name)),NF90_DOUBLE,(/ cellId, levId,nqId /),fieldId(nf))
+          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
+            status = NF90_DEF_VAR(ncid,TRIM(ADJUSTL(field(1)%name)),NF90_DOUBLE,(/ edgeId /),fieldId(nf))
+          ELSE IF (field(1)%ndim==3) THEN
+            status = NF90_DEF_VAR(ncid,TRIM(ADJUSTL(field(1)%name)),NF90_DOUBLE,(/ edgeId, levId /),fieldId(nf))
+          ELSE IF (field(1)%ndim==4) THEN
+            status = NF90_DEF_VAR(ncid,TRIM(ADJUSTL(field(1)%name)),NF90_DOUBLE,(/ edgeId, levId, nqId /),fieldId(nf))
+          ENDIF
+        ENDIF
+      ENDDO
+          
+      
+      status = NF90_ENDDEF(ncid)
+      
+      ALLOCATE(lon(ncell_glo),lat(ncell_glo),bounds_lon(0:nvert-1,ncell_glo),bounds_lat(0:nvert-1,ncell_glo))
+      DO ind=1,ndomain_glo
+        d=>domain_glo(ind)
+        DO j=d%jj_begin,d%jj_end
+          DO i=d%ii_begin,d%ii_end
+             ind_glo=d%assign_cell_glo(i,j)
+             CALL xyz2lonlat(d%xyz(:,i,j),lon(ind_glo),lat(ind_glo))
+             lon(ind_glo)=lon(ind_glo)*180/Pi
+             lat(ind_glo)=lat(ind_glo)*180/Pi
+             DO k=0,5
+                 CALL xyz2lonlat(d%vertex(:,k,i,j),bounds_lon(k,ind_glo), bounds_lat(k,ind_glo))
+                 bounds_lat(k,ind_glo)=bounds_lat(k,ind_glo)*180/Pi
+                 bounds_lon(k,ind_glo)=bounds_lon(k,ind_glo)*180/Pi
+             ENDDO
+          ENDDO
+        ENDDO
+      ENDDO
+
+      status=NF90_PUT_VAR(ncid,lonid,REAL(lon,r8),start=(/ 1 /),count=(/ ncell_glo /))
+      status=NF90_PUT_VAR(ncid,latid,REAL(lat,r8),start=(/ 1 /),count=(/ ncell_glo /))
+      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 /))
+    ENDIF
+
+    DO nf=1,nfield
+      field=>field_array(nf)%field
+      CALL write_restart_field(field,fieldId(nf),ncid)
+    ENDDO
+          
+!          status = NF90_DEF_VAR(ncid,TRIM(ADJUSTL(field(1)%name),NF90_DOUBLE,(/ ncellId /),fieldId(nf))
+!        ELSE IF (field(1)%ndim==3) THEN
+!          status = NF90_DEF_VAR(ncid,TRIM(ADJUSTL(field(1)%name),NF90_DOUBLE,(/ ncellId, levId /),fieldId(nf))
+!        ENDIF
+!      ENDDO
+
+
+    IF (is_mpi_root) THEN
+      status = NF90_CLOSE(ncid)      
+    ENDIF
+!$OMP END MASTER
+  
+  END SUBROUTINE write_restart
+  
+  SUBROUTINE write_restart_field(field,fieldId,ncid)
+  USE prec
+  USE metric
+  USE field_mod
+  USE domain_mod
+  USE netcdf_mod
+  USE mpipara
+  USE getin_mod
+  USE spherical_geom_mod
+  USE transfert_mod
+  IMPLICIT NONE
+    TYPE(t_field),POINTER :: field(:)
+    INTEGER,INTENT(IN)     :: fieldId
+    INTEGER,INTENT(IN)     :: ncid
+
+    TYPE(t_domain),POINTER :: d
+    TYPE(t_field),POINTER :: field_glo(:)
+    REAL(rstd),ALLOCATABLE :: global_field2d(:)
+    REAL(rstd),ALLOCATABLE :: global_field3d(:,:)
+    REAL(rstd),ALLOCATABLE :: global_field4d(:,:,:)
+    INTEGER :: i,j,ij,k,e,ind,ind_glo
+    INTEGER :: ndim, field_type
+    INTEGER :: status
+    
+      ndim=field(1)%ndim
+      field_Type= field(1)%field_type
+      
+      IF (is_mpi_root) THEN
+ 
+        IF (ndim==2) THEN
+          CALL allocate_field_glo(field_glo,field(1)%field_type,field(1)%data_type,name=field(1)%name)
+        ELSE IF (ndim==3) THEN
+          CALL allocate_field_glo(field_glo,field(1)%field_type,field(1)%data_type,field(1)%dim3,name=field(1)%name)
+        ELSE IF (ndim==4) THEN
+          CALL allocate_field_glo(field_glo,field(1)%field_type,field(1)%data_type,field(1)%dim3,field(1)%dim4,name=field(1)%name)
+        ENDIF
+      ENDIF
+      
+      CALL gather_field(field,field_glo)
+      
+
+      IF (is_mpi_root) THEN
+
+        IF (field_type==field_T) THEN
+          IF (ndim==2) THEN
+            ALLOCATE(global_field2d(ncell_glo))
+            DO ind=1,ndomain_glo
+              d=>domain_glo(ind)
+              DO j=d%jj_begin,d%jj_end
+                DO i=d%ii_begin,d%ii_end
+                  IF (d%own(i,j)) THEN 
+                    ij=(j-1)*d%iim+i
+                    ind_glo=d%assign_cell_glo(i,j)
+                    global_field2d(ind_glo)=field_glo(ind)%rval2d(ij)
+                  ENDIF 
+                ENDDO
+              ENDDO
+            ENDDO
+            status=NF90_PUT_VAR(ncid,fieldid,global_field2d,start=(/ 1 /),count=(/ ncell_glo /))
+          
+          ELSE IF (ndim==3) THEN
+            ALLOCATE(global_field3d(ncell_glo,llm))
+            DO ind=1,ndomain_glo
+              d=>domain_glo(ind)
+              DO j=d%jj_begin,d%jj_end
+                DO i=d%ii_begin,d%ii_end
+                  IF (d%own(i,j)) THEN 
+                    ij=(j-1)*d%iim+i
+                    ind_glo=d%assign_cell_glo(i,j)
+                    global_field3d(ind_glo,:)=field_glo(ind)%rval3d(ij,:)
+                  ENDIF
+                ENDDO
+              ENDDO
+            ENDDO
+            status=NF90_PUT_VAR(ncid,fieldid,global_field3d,start=(/ 1,1 /),count=(/ ncell_glo,llm /))
+          ELSE IF (ndim==4) THEN
+            ALLOCATE(global_field4d(ncell_glo,llm,nqtot))
+            DO ind=1,ndomain_glo
+              d=>domain_glo(ind)
+              DO j=d%jj_begin,d%jj_end
+                DO i=d%ii_begin,d%ii_end
+                  IF (d%own(i,j)) THEN 
+                    ij=(j-1)*d%iim+i
+                    ind_glo=d%assign_cell_glo(i,j)
+                    global_field4d(ind_glo,:,:)=field_glo(ind)%rval4d(ij,:,:)
+                  ENDIF
+                ENDDO
+              ENDDO
+            ENDDO
+            status=NF90_PUT_VAR(ncid,fieldid,global_field4d,start=(/ 1,1,1 /),count=(/ ncell_glo,llm,nqtot /))
+          ENDIF
+        
+        ELSE IF (field_type==field_U) THEN
+        
+          IF (ndim==2) THEN
+            ALLOCATE(global_field2d(3*ncell_glo))
+            DO ind=1,ndomain_glo
+              d=>domain_glo(ind)
+              DO j=d%jj_begin,d%jj_end
+                DO i=d%ii_begin,d%ii_end
+                  DO k=0,5
+                   IF (d%edge_assign_domain(k,i,j)==ind .AND. d%edge_assign_i(k,i,j)==i .AND. d%edge_assign_j(k,i,j)==j .AND. d%edge_assign_pos(k,i,j)==k) THEN
+                       ij=(j-1)*d%iim+i
+                      ind_glo=d%assign_cell_glo(i,j)
+                      e=cell_glo(ind_glo)%edge(MOD(k+d%delta(i,j)+6,6))  
+                      global_field2d(ind_glo)=d%edge_assign_sign(k,i,j)*field_glo(ind)%rval2d(ij+d%u_pos(k))
+                    ENDIF
+                  ENDDO
+                ENDDO
+              ENDDO
+            ENDDO
+            status=NF90_PUT_VAR(ncid,fieldid,REAL(global_field2d,r8),start=(/ 1 /),count=(/ 3*ncell_glo /))
+          ELSE IF (ndim==3) THEN
+            ALLOCATE(global_field3d(3*ncell_glo,llm))
+            DO ind=1,ndomain_glo
+              d=>domain_glo(ind)
+              DO j=d%jj_begin,d%jj_end
+                DO i=d%ii_begin,d%ii_end
+                  DO k=0,5
+                   IF (d%edge_assign_domain(k,i,j)==ind .AND. d%edge_assign_i(k,i,j)==i .AND. d%edge_assign_j(k,i,j)==j .AND. d%edge_assign_pos(k,i,j)==k) THEN
+                       ij=(j-1)*d%iim+i
+                      ind_glo=d%assign_cell_glo(i,j)
+                      e=cell_glo(ind_glo)%edge(MOD(k+d%delta(i,j)+6,6))  
+                      global_field3d(e,:)=d%edge_assign_sign(k,i,j)*field_glo(ind)%rval3d(ij+d%u_pos(k+1),:)
+                    ENDIF
+                  ENDDO
+                ENDDO
+              ENDDO
+            ENDDO
+            status=NF90_PUT_VAR(ncid,fieldid,global_field3d,start=(/ 1,1 /),count=(/ 3*ncell_glo,llm /))
+          ELSE IF (ndim==4) THEN
+            ALLOCATE(global_field4d(3*ncell_glo,llm,nqtot))
+            DO ind=1,ndomain_glo
+              d=>domain_glo(ind)
+              DO j=d%jj_begin,d%jj_end
+                DO i=d%ii_begin,d%ii_end
+                  DO k=0,5
+                    IF (d%edge_assign_domain(k,i,j)==ind .AND. d%edge_assign_i(k,i,j)==i .AND. d%edge_assign_j(k,i,j)==j .AND. d%edge_assign_pos(k,i,j)==k) THEN
+                      ij=(j-1)*d%iim+i
+                      ind_glo=d%assign_cell_glo(i,j)
+                      e=cell_glo(ind_glo)%edge(MOD(k+d%delta(i,j)+6,6))  
+                      global_field4d(e,:,:)=d%edge_assign_sign(k,i,j)*field_glo(ind)%rval4d(ij+d%u_pos(k+1),:,:)
+                    ENDIF
+                  ENDDO
+                ENDDO
+              ENDDO
+            ENDDO
+            status=NF90_PUT_VAR(ncid,fieldid,global_field3d,start=(/ 1,1,1 /),count=(/ 3*ncell_glo,llm,nqtot /))
+          ENDIF
+
+        ENDIF
+        
+        CALL deallocate_field_glo(field_glo)
+      
+      ENDIF
+      
+      
+  END SUBROUTINE write_restart_field
+
+
+  SUBROUTINE read_start(it,field0 ,field1 ,field2 ,field3 ,field4 ,field5 ,field6 ,field7 ,field8 ,field9,   &
+                           field10,field11,field12,field13,field14,field15,field16,field17,field18,field19 )
+  USE prec
+  USE metric
+  USE field_mod
+  USE domain_mod
+  USE netcdf_mod
+  USE mpipara
+  USE getin_mod
+  USE spherical_geom_mod
+  USE transfert_mod
+ 
+  IMPLICIT NONE
+  INTEGER, INTENT(OUT)  :: it
+  TYPE(t_field),POINTER,OPTIONAL,DIMENSION(:) :: field0 ,field1 ,field2 ,field3 ,field4 ,field5 ,field6 ,field7 ,field8 ,field9
+  TYPE(t_field),POINTER,OPTIONAL,DIMENSION(:) :: field10,field11,field12,field13,field14,field15,field16,field17,field18,field19
+
+  TYPE(t_field_array) :: field_array(20)
+  INTEGER             :: nfield
+  INTEGER             :: fieldId(20)
+   
+  TYPE(t_domain),POINTER :: d
+  TYPE(t_field),POINTER :: field_glo(:)
+  TYPE(t_field),POINTER :: field(:)
+  
+  CHARACTER(LEN=255) :: start_file_name
+  INTEGER,PARAMETER  :: nvert=6
+  INTEGER    ::  ncid, cellId, levId, edgeId,  vertid, lonId, latId, bounds_lonId, bounds_latId
+  INTEGER    :: ind,ind_glo,i,j,k,nf
+  INTEGER    :: status
+  REAL(rstd),ALLOCATABLE :: lon(:),lat(:),bounds_lon(:,:),bounds_lat(:,:)
+   
+    start_file_name="start"
+    CALL getin("start_file_name",start_file_name)
+
+!$OMP MASTER
+
+    nfield=0
+    IF (PRESENT(field0))  THEN ; nfield=nfield+1 ; field_array(nfield)%field=>field0  ; ENDIF
+    IF (PRESENT(field1))  THEN ; nfield=nfield+1 ; field_array(nfield)%field=>field1  ; ENDIF
+    IF (PRESENT(field2))  THEN ; nfield=nfield+1 ; field_array(nfield)%field=>field2  ; ENDIF
+    IF (PRESENT(field3))  THEN ; nfield=nfield+1 ; field_array(nfield)%field=>field3  ; ENDIF
+    IF (PRESENT(field4))  THEN ; nfield=nfield+1 ; field_array(nfield)%field=>field4  ; ENDIF
+    IF (PRESENT(field5))  THEN ; nfield=nfield+1 ; field_array(nfield)%field=>field5  ; ENDIF
+    IF (PRESENT(field6))  THEN ; nfield=nfield+1 ; field_array(nfield)%field=>field6  ; ENDIF
+    IF (PRESENT(field7))  THEN ; nfield=nfield+1 ; field_array(nfield)%field=>field7  ; ENDIF
+    IF (PRESENT(field8))  THEN ; nfield=nfield+1 ; field_array(nfield)%field=>field8  ; ENDIF
+    IF (PRESENT(field9))  THEN ; nfield=nfield+1 ; field_array(nfield)%field=>field9  ; ENDIF
+    IF (PRESENT(field10)) THEN ; nfield=nfield+1 ; field_array(nfield)%field=>field10 ; ENDIF
+    IF (PRESENT(field11)) THEN ; nfield=nfield+1 ; field_array(nfield)%field=>field11 ; ENDIF
+    IF (PRESENT(field12)) THEN ; nfield=nfield+1 ; field_array(nfield)%field=>field12 ; ENDIF
+    IF (PRESENT(field13)) THEN ; nfield=nfield+1 ; field_array(nfield)%field=>field13 ; ENDIF
+    IF (PRESENT(field14)) THEN ; nfield=nfield+1 ; field_array(nfield)%field=>field14 ; ENDIF
+    IF (PRESENT(field15)) THEN ; nfield=nfield+1 ; field_array(nfield)%field=>field15 ; ENDIF
+    IF (PRESENT(field16)) THEN ; nfield=nfield+1 ; field_array(nfield)%field=>field16 ; ENDIF
+    IF (PRESENT(field17)) THEN ; nfield=nfield+1 ; field_array(nfield)%field=>field17 ; ENDIF
+    IF (PRESENT(field18)) THEN ; nfield=nfield+1 ; field_array(nfield)%field=>field18 ; ENDIF
+    IF (PRESENT(field19)) THEN ; nfield=nfield+1 ; field_array(nfield)%field=>field19 ; ENDIF
+    
+      
+
+    IF (is_mpi_root) THEN
+      status = NF90_OPEN(TRIM(ADJUSTL(start_file_name))//'.nc', NF90_NOWRITE, ncid)
+    ENDIF
+   
+    DO nf=1,nfield
+      field=>field_array(nf)%field
+      status = nf90_inq_varid(ncid, TRIM(ADJUSTL(field(1)%name)), fieldId(nf))
+      status = nf90_get_att(ncid, NF90_GLOBAL, "iteration", it)
+      CALL read_start_field(field,fieldId(nf),ncid)
+    ENDDO
+
+
+    IF (is_mpi_root) THEN
+      status = NF90_CLOSE(ncid)      
+    ENDIF
+!$OMP END MASTER
+  
+  END SUBROUTINE read_start
+
+
+  SUBROUTINE read_start_field(field,fieldId,ncid)
+  USE prec
+  USE metric
+  USE field_mod
+  USE domain_mod
+  USE netcdf_mod
+  USE mpipara
+  USE getin_mod
+  USE spherical_geom_mod
+  USE transfert_mod
+  IMPLICIT NONE
+    TYPE(t_field),POINTER :: field(:)
+    INTEGER,INTENT(IN)     :: fieldId
+    INTEGER,INTENT(IN)     :: ncid
+
+    TYPE(t_domain),POINTER :: d
+    TYPE(t_field),POINTER :: field_glo(:)
+    REAL(rstd),ALLOCATABLE :: global_field2d(:)
+    REAL(rstd),ALLOCATABLE :: global_field3d(:,:)
+    REAL(rstd),ALLOCATABLE :: global_field4d(:,:,:)
+    INTEGER :: i,j,ij,k,e,ind,ind_glo
+    INTEGER :: ndim, field_type
+    INTEGER :: status
+    
+      ndim=field(1)%ndim
+      field_Type= field(1)%field_type
+      
+      IF (is_mpi_root) THEN
+ 
+        IF (ndim==2) THEN
+          CALL allocate_field_glo(field_glo,field(1)%field_type,field(1)%data_type,name=field(1)%name)
+        ELSE IF (ndim==3) THEN
+          CALL allocate_field_glo(field_glo,field(1)%field_type,field(1)%data_type,field(1)%dim3,name=field(1)%name)
+        ELSE IF (ndim==4) THEN
+          CALL allocate_field_glo(field_glo,field(1)%field_type,field(1)%data_type,field(1)%dim3,field(1)%dim4,name=field(1)%name)
+        ENDIF
+      ENDIF
+      
+      IF (is_mpi_root) THEN
+
+        IF (field_type==field_T) THEN
+          IF (ndim==2) THEN
+            ALLOCATE(global_field2d(ncell_glo))
+            status=NF90_GET_VAR(ncid,fieldid, global_field2d, start=(/ 1 /), count=(/ ncell_glo /))
+            DO ind=1,ndomain_glo
+              d=>domain_glo(ind)
+              DO j=d%jj_begin,d%jj_end
+                DO i=d%ii_begin,d%ii_end
+                    ij=(j-1)*d%iim+i
+                    ind_glo=d%assign_cell_glo(i,j)
+                    field_glo(ind)%rval2d(ij)=global_field2d(ind_glo)
+                ENDDO
+              ENDDO
+            ENDDO
+          
+          ELSE IF (ndim==3) THEN
+            ALLOCATE(global_field3d(ncell_glo,llm))
+            status=NF90_GET_VAR(ncid,fieldid,global_field3d,start=(/ 1,1 /),count=(/ ncell_glo,llm /))
+            DO ind=1,ndomain_glo
+              d=>domain_glo(ind)
+              DO j=d%jj_begin,d%jj_end
+                DO i=d%ii_begin,d%ii_end
+                  ij=(j-1)*d%iim+i
+                  ind_glo=d%assign_cell_glo(i,j)
+                  field_glo(ind)%rval3d(ij,:) = global_field3d(ind_glo,:)
+                ENDDO
+              ENDDO
+            ENDDO
+          ELSE IF (ndim==4) THEN
+            ALLOCATE(global_field4d(ncell_glo,llm,nqtot))
+            status=NF90_GET_VAR(ncid,fieldid,global_field4d,start=(/ 1,1,1 /),count=(/ ncell_glo,llm,nqtot /))
+            DO ind=1,ndomain_glo
+              d=>domain_glo(ind)
+              DO j=d%jj_begin,d%jj_end
+                DO i=d%ii_begin,d%ii_end
+                  ij=(j-1)*d%iim+i
+                  ind_glo=d%assign_cell_glo(i,j)
+                  field_glo(ind)%rval4d(ij,:,:) = global_field4d(ind_glo,:,:)
+                ENDDO
+              ENDDO
+            ENDDO
+          ENDIF
+        
+        ELSE IF (field_type==field_U) THEN
+        
+          IF (ndim==2) THEN
+            ALLOCATE(global_field2d(3*ncell_glo))
+            status=NF90_GET_VAR(ncid,fieldid,global_field2d,start=(/ 1 /),count=(/ 3*ncell_glo /))
+
+            DO ind=1,ndomain_glo
+              d=>domain_glo(ind)
+              DO j=d%jj_begin,d%jj_end
+                DO i=d%ii_begin,d%ii_end
+                  DO k=0,5
+                    ij=(j-1)*d%iim+i
+                    ind_glo=d%assign_cell_glo(i,j)
+                    e=cell_glo(ind_glo)%edge(MOD(k+d%delta(i,j)+6,6))  
+                    field_glo(ind)%rval2d(ij+d%u_pos(k))= global_field2d(ind_glo)*d%edge_assign_sign(k,i,j)
+                  ENDDO
+                ENDDO
+              ENDDO
+            ENDDO
+          ELSE IF (ndim==3) THEN
+            ALLOCATE(global_field3d(3*ncell_glo,llm))
+            status=NF90_GET_VAR(ncid,fieldid,global_field3d,start=(/ 1,1 /),count=(/ 3*ncell_glo,llm /))
+            DO ind=1,ndomain_glo
+              d=>domain_glo(ind)
+              DO j=d%jj_begin,d%jj_end
+                DO i=d%ii_begin,d%ii_end
+                  DO k=0,5
+                    ij=(j-1)*d%iim+i
+                    ind_glo=d%assign_cell_glo(i,j)
+                    e=cell_glo(ind_glo)%edge(MOD(k+d%delta(i,j)+6,6))  
+                    field_glo(ind)%rval3d(ij+d%u_pos(k+1),:)=global_field3d(e,:)*d%edge_assign_sign(k,i,j)
+                  ENDDO
+                ENDDO
+              ENDDO
+            ENDDO
+          ELSE IF (ndim==4) THEN
+            ALLOCATE(global_field4d(3*ncell_glo,llm,nqtot))
+            status=NF90_GET_VAR(ncid,fieldid,global_field4d,start=(/ 1,1,1 /),count=(/ 3*ncell_glo,llm,nqtot /))
+            DO ind=1,ndomain_glo
+              d=>domain_glo(ind)
+              DO j=d%jj_begin,d%jj_end
+                DO i=d%ii_begin,d%ii_end
+                  DO k=0,5
+                    ij=(j-1)*d%iim+i
+                    ind_glo=d%assign_cell_glo(i,j)
+                    e=cell_glo(ind_glo)%edge(MOD(k+d%delta(i,j)+6,6))  
+                    field_glo(ind)%rval4d(ij+d%u_pos(k+1),:,:)=global_field4d(e,:,:)*d%edge_assign_sign(k,i,j)
+                  ENDDO
+                ENDDO
+              ENDDO
+            ENDDO
+          ENDIF
+
+        ENDIF
+      ENDIF
+      
+      CALL scatter_field(field_glo,field)
+        
+      IF (is_mpi_root) THEN
+        CALL deallocate_field_glo(field_glo)
+      ENDIF
+      
+      
+  END SUBROUTINE read_start_field      
+    
+END MODULE restart_mod
+  
Index: codes/icosagcm/trunk/src/time.f90
===================================================================
--- codes/icosagcm/trunk/src/time.f90	(revision 265)
+++ codes/icosagcm/trunk/src/time.f90	(revision 266)
@@ -9,4 +9,7 @@
   INTEGER,SAVE :: it
 !$OMP THREADPRIVATE(it)  
+
+  INTEGER,SAVE :: itau0=0
+!$OMP THREADPRIVATE(itau0)  
 
   REAL(rstd),SAVE :: dt
@@ -37,5 +40,5 @@
          dt, write_period, itau_out, itau_adv, itau_dissip, itau_physics, itaumax, & 
 day_step,ndays,jD_ref,jH_ref,day_ini,day_end,annee_ref,day_ref,an, mois, jour,heure, &
-            calend,time_style
+            calend,time_style,itau0
 
 
Index: codes/icosagcm/trunk/src/timeloop_gcm.f90
===================================================================
--- codes/icosagcm/trunk/src/timeloop_gcm.f90	(revision 265)
+++ codes/icosagcm/trunk/src/timeloop_gcm.f90	(revision 266)
@@ -21,8 +21,4 @@
 !$OMP THREADPRIVATE(nb_stage, matsuno_period, scheme)
 
-  REAL(rstd),SAVE :: jD_cur, jH_cur
-!$OMP THREADPRIVATE(jD_cur, jH_cur)  
-  REAL(rstd),SAVE :: start_time
-!$OMP THREADPRIVATE(start_time)
 CONTAINS
   
@@ -47,56 +43,4 @@
     CHARACTER(len=255) :: def
 
-!----------------------------------------------------
-!  IF (TRIM(time_style)=='lmd')  Then
-
-!   day_step=180
-!   CALL getin('day_step',day_step)
-
-!   ndays=1
-!   CALL getin('ndays',ndays)
-
-!   dt = daysec/REAL(day_step)
-!   itaumax = ndays*day_step
-
-!   calend = 'earth_360d'
-!   CALL getin('calend', calend)
-
-!   day_ini = 0
-!   CALL getin('day_ini',day_ini)
-
-!   day_end = 0
-!   CALL getin('day_end',day_end)
-
-!   annee_ref = 1998
-!   CALL getin('annee_ref',annee_ref)
-
-!   start_time = 0
-!   CALL getin('start_time',start_time) 
-
-!   
-!   write_period=0
-!   CALL getin('write_period',write_period)
-!      
-!   write_period=write_period/scale_factor
-!   itau_out=FLOOR(write_period/dt)
-!   
-!   PRINT *, 'Output frequency (scaled) set to ',write_period, ' : itau_out = ',itau_out 
-
-!  mois = 1 ; heure = 0.
-!  call ymds2ju(annee_ref, mois, day_ref, heure, jD_ref)
-!  jH_ref = jD_ref - int(jD_ref) 
-!  jD_ref = int(jD_ref) 
-!  
-!  CALL ioconf_startdate(INT(jD_ref),jH_ref) 
-!  write(*,*)'annee_ref, mois, day_ref, heure, jD_ref'
-!  write(*,*)annee_ref, mois, day_ref, heure, jD_ref
-!  write(*,*)"ndays,day_step,itaumax,dt======>"
-!  write(*,*)ndays,day_step,itaumax,dt
-!  call ju2ymds(jD_ref+jH_ref,an, mois, jour, heure)
-!  write(*,*)'jD_ref+jH_ref,an, mois, jour, heure'
-!  write(*,*)jD_ref+jH_ref,an, mois, jour, heure
-!  day_end = day_ini + ndays 
-! END IF 
-!----------------------------------------------------
 
    IF (xios_output) itau_out=1
@@ -117,5 +61,5 @@
     CALL allocate_field(f_theta_rhodzm1,field_t,type_real,llm,name='theta_rhodzm1')
 ! Tracers
-    CALL allocate_field(f_q,field_t,type_real,llm,nqtot)
+    CALL allocate_field(f_q,field_t,type_real,llm,nqtot,'q')
     CALL allocate_field(f_rhodz,field_t,type_real,llm,name='rhodz')
 ! Mass fluxes
@@ -212,4 +156,5 @@
   USE xios_mod
   USE output_field_mod
+  USE write_etat0_mod
   IMPLICIT NONE  
     REAL(rstd),POINTER :: q(:,:,:)
@@ -227,4 +172,9 @@
     INTEGER :: stop_clock
     INTEGER :: rate_clock
+    
+    
+!    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 caldyn_BC(f_phis, f_wflux) ! set constant values in first/last interfaces
@@ -248,10 +198,12 @@
 !$OMP END MASTER   
 
+  CALL check_conserve(f_ps,f_dps,f_u,f_theta_rhodz,f_phis,itau0)  
+
   CALL trace_on
   
-  DO it=0,itaumax
+  DO it=itau0+1,itau0+itaumax
     
     IF (xios_output) CALL xios_update_calendar(it)
-    IF (MOD(it,itau_sync)==0) THEN
+    IF (it==itau0+1 .OR. MOD(it,itau_sync)==0) THEN
       CALL send_message(f_ps,req_ps0)
       CALL wait_message(req_ps0)
@@ -299,5 +251,5 @@
     END DO
 
-    IF (MOD(it+1,itau_dissip)==0) THEN
+    IF (MOD(it,itau_dissip)==0) THEN
 !         CALL send_message(f_ps,req_ps)
 !         CALL wait_message(req_ps)  
@@ -320,5 +272,5 @@
     END IF
 
-    IF(MOD(it+1,itau_adv)==0) THEN
+    IF(MOD(it,itau_adv)==0) THEN
 
        CALL advect_tracer(f_hfluxt,f_wfluxt,f_u, f_q,f_rhodz)  ! update q and rhodz after RK step
@@ -339,26 +291,24 @@
 
 
-
-!----------------------------------------------------
-!    jD_cur = jD_ref + day_ini - day_ref + it/day_step
-!    jH_cur = jH_ref + start_time + mod(it,day_step)/float(day_step)
-!    jD_cur = jD_cur + int(jH_cur)
-!    jH_cur = jH_cur - int(jH_cur)
-    CALL physics(it,jD_cur,jH_cur,f_phis, f_ps, f_theta_rhodz, f_u, f_q)
-
-    ENDDO
-
-    CALL check_conserve(f_ps,f_dps,f_u,f_theta_rhodz,f_phis,it)  
+    IF (MOD(it,itau_physics)==0) THEN
+      CALL physics(it,f_phis, f_ps, f_theta_rhodz, f_u,  f_q)
+    ENDIF
+    
+  ENDDO
+
+  CALL write_etat0(itau0+itaumax,f_ps, f_phis,f_theta_rhodz,f_u,f_q) 
+
+  CALL check_conserve(f_ps,f_dps,f_u,f_theta_rhodz,f_phis,it)  
 
 !$OMP MASTER
-    CALL SYSTEM_CLOCK(stop_clock)
-    CALL SYSTEM_CLOCK(count_rate=rate_clock)
-    
-    IF (mpi_rank==0) THEN 
-      PRINT *,"Time elapsed : ",(stop_clock-start_clock)*1./rate_clock
-    ENDIF  
+  CALL SYSTEM_CLOCK(stop_clock)
+  CALL SYSTEM_CLOCK(count_rate=rate_clock)
+    
+  IF (mpi_rank==0) THEN 
+    PRINT *,"Time elapsed : ",(stop_clock-start_clock)*1./rate_clock 
+  ENDIF  
 !$OMP END MASTER 
  
-  CONTAINS
+ CONTAINS
 
     SUBROUTINE Euler_scheme(with_dps)
Index: codes/icosagcm/trunk/src/transfert.F90
===================================================================
--- codes/icosagcm/trunk/src/transfert.F90	(revision 265)
+++ codes/icosagcm/trunk/src/transfert.F90	(revision 266)
@@ -3,13 +3,227 @@
 #ifdef CPP_USING_MPI
   USE transfert_mpi_mod, ONLY : init_transfert, transfert_request=>transfert_request_mpi, req_i1,req_e1_vect, &
-                                req_e1_scal, req_i0, req_e0_vect, req_e0_scal, request_add_point, create_request, gather_field, &
+                                req_e1_scal, req_i0, req_e0_vect, req_e0_scal, request_add_point, create_request, gather_field, scatter_field, &
                                 t_message,init_message=>init_message_mpi,transfert_message=>transfert_message_mpi,  &
-                                send_message=>send_message_mpi,test_message=>test_message_mpi,wait_message=>wait_message_mpi,barrier
+                                send_message=>send_message_mpi,test_message=>test_message_mpi,wait_message=>wait_message_mpi,barrier, &
+                                bcast_mpi
 #else 
   USE transfert_mpi_mod, ONLY : init_transfert, transfert_request=>transfert_request_seq, req_i1,req_e1_vect, &
-                                req_e1_scal,req_i0, req_e0_vect, req_e0_scal, request_add_point, create_request, gather_field, &
+                                req_e1_scal,req_i0, req_e0_vect, req_e0_scal, request_add_point, create_request, gather_field, scatter_field,&
                                 t_message,init_message=>init_message_seq,transfert_message=>transfert_message_seq,  &
-                                send_message=>send_message_seq,test_message=>test_message_seq,wait_message=>wait_message_seq,barrier
+                                send_message=>send_message_seq,test_message=>test_message_seq,wait_message=>wait_message_seq,barrier, &
+                                bcast_mpi
 #endif
+
+  USE transfert_omp_mod
+  
+  INTERFACE bcast
+    MODULE PROCEDURE bcast_c,                                     &
+                     bcast_i,bcast_i1,bcast_i2,bcast_i3,bcast_i4, &
+                     bcast_r,bcast_r1,bcast_r2,bcast_r3,bcast_r4, &
+		     bcast_l,bcast_l1,bcast_l2,bcast_l3,bcast_l4
+
+  END INTERFACE
+
+
+CONTAINS
+
+
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!! Definition des Broadcast --> 4D   !!
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+!! -- Les chaine de charactère -- !!
+
+  SUBROUTINE bcast_c(var)
+  IMPLICIT NONE
+    CHARACTER(LEN=*),INTENT(INOUT) :: Var
+   
+!$OMP MASTER
+    CALL bcast_mpi(Var)
+!$OMP END MASTER
+    CALL bcast_omp(Var)
+    
+  END SUBROUTINE bcast_c
+
+!! -- Les entiers -- !!
+  
+  SUBROUTINE bcast_i(var)
+  IMPLICIT NONE
+    INTEGER,INTENT(INOUT) :: Var
+!$OMP MASTER
+    CALL bcast_mpi(Var)
+!$OMP END MASTER
+    CALL bcast_omp(Var)
+    
+  END SUBROUTINE bcast_i
+
+  SUBROUTINE bcast_i1(var)
+  IMPLICIT NONE
+    INTEGER,INTENT(INOUT) :: Var(:)
+   
+!$OMP MASTER
+    CALL bcast_mpi(Var)
+!$OMP END MASTER
+    CALL bcast_omp(Var)
+    
+  END SUBROUTINE bcast_i1
+
+
+  SUBROUTINE bcast_i2(var)
+  IMPLICIT NONE
+    INTEGER,INTENT(INOUT) :: Var(:,:)
+   
+!$OMP MASTER
+    CALL bcast_mpi(Var)
+!$OMP END MASTER
+    CALL bcast_omp(Var)
+    
+  END SUBROUTINE bcast_i2
+
+
+  SUBROUTINE bcast_i3(var)
+  IMPLICIT NONE
+    INTEGER,INTENT(INOUT) :: Var(:,:,:)
+   
+!$OMP MASTER
+    CALL bcast_mpi(Var)
+!$OMP END MASTER
+    CALL bcast_omp(Var)
+    
+  END SUBROUTINE bcast_i3
+
+
+  SUBROUTINE bcast_i4(var)
+  IMPLICIT NONE
+    INTEGER,INTENT(INOUT) :: Var(:,:,:,:)
+   
+!$OMP MASTER
+    CALL bcast_mpi(Var)
+!$OMP END MASTER
+    CALL bcast_omp(Var)
+    
+  END SUBROUTINE bcast_i4
+
+ 
+!! -- Les reels -- !!
+  
+  SUBROUTINE bcast_r(var)
+  IMPLICIT NONE
+    REAL,INTENT(INOUT) :: Var
+
+!$OMP MASTER
+    CALL bcast_mpi(Var)
+!$OMP END MASTER
+    CALL bcast_omp(Var)
+    
+  END SUBROUTINE bcast_r
+
+  SUBROUTINE bcast_r1(var)
+  IMPLICIT NONE
+    REAL,INTENT(INOUT) :: Var(:)
+   
+!$OMP MASTER
+    CALL bcast_mpi(Var)
+!$OMP END MASTER
+    CALL bcast_omp(Var)
+    
+  END SUBROUTINE bcast_r1
+
+
+  SUBROUTINE bcast_r2(var)
+  IMPLICIT NONE
+    REAL,INTENT(INOUT) :: Var(:,:)
+   
+!$OMP MASTER
+    CALL bcast_mpi(Var)
+!$OMP END MASTER
+    CALL bcast_omp(Var)
+    
+  END SUBROUTINE bcast_r2
+
+
+  SUBROUTINE bcast_r3(var)
+  IMPLICIT NONE
+    REAL,INTENT(INOUT) :: Var(:,:,:)
+   
+!$OMP MASTER
+    CALL bcast_mpi(Var)
+!$OMP END MASTER
+    CALL bcast_omp(Var)
+    
+  END SUBROUTINE bcast_r3
+
+
+  SUBROUTINE bcast_r4(var)
+  IMPLICIT NONE
+    REAL,INTENT(INOUT) :: Var(:,:,:,:)
+   
+!$OMP MASTER
+    CALL bcast_mpi(Var)
+!$OMP END MASTER
+    CALL bcast_omp(Var)
+    
+  END SUBROUTINE bcast_r4 
+
+
+!! -- Les booleens -- !!
+  
+  SUBROUTINE bcast_l(var)
+  IMPLICIT NONE
+    LOGICAL,INTENT(INOUT) :: Var
+!$OMP MASTER
+    CALL bcast_mpi(Var)
+!$OMP END MASTER
+    CALL bcast_omp(Var)
+    
+  END SUBROUTINE bcast_l
+
+  SUBROUTINE bcast_l1(var)
+  IMPLICIT NONE
+    LOGICAL,INTENT(INOUT) :: Var(:)
+   
+!$OMP MASTER
+    CALL bcast_mpi(Var)
+!$OMP END MASTER
+    CALL bcast_omp(Var)
+    
+  END SUBROUTINE bcast_l1
+
+
+  SUBROUTINE bcast_l2(var)
+  IMPLICIT NONE
+    LOGICAL,INTENT(INOUT) :: Var(:,:)
+   
+!$OMP MASTER
+    CALL bcast_mpi(Var)
+!$OMP END MASTER
+    CALL bcast_omp(Var)
+    
+  END SUBROUTINE bcast_l2
+
+
+  SUBROUTINE bcast_l3(var)
+  IMPLICIT NONE
+    LOGICAL,INTENT(INOUT) :: Var(:,:,:)
+   
+!$OMP MASTER
+    CALL bcast_mpi(Var)
+!$OMP END MASTER
+    CALL bcast_omp(Var)
+    
+  END SUBROUTINE bcast_l3
+
+
+  SUBROUTINE bcast_l4(var)
+  IMPLICIT NONE
+    LOGICAL,INTENT(INOUT) :: Var(:,:,:,:)
+   
+!$OMP MASTER
+    CALL bcast_mpi(Var)
+!$OMP END MASTER
+    CALL bcast_omp(Var)
+    
+  END SUBROUTINE bcast_l4
+
   
 END MODULE transfert_mod
Index: codes/icosagcm/trunk/src/transfert_mpi.f90
===================================================================
--- codes/icosagcm/trunk/src/transfert_mpi.f90	(revision 265)
+++ codes/icosagcm/trunk/src/transfert_mpi.f90	(revision 266)
@@ -74,4 +74,14 @@
     INTEGER :: number
   END TYPE t_message
+
+
+  INTERFACE bcast_mpi
+    MODULE PROCEDURE bcast_mpi_c,                                                     &
+                     bcast_mpi_i,bcast_mpi_i1,bcast_mpi_i2,bcast_mpi_i3,bcast_mpi_i4, &
+                     bcast_mpi_r,bcast_mpi_r1,bcast_mpi_r2,bcast_mpi_r3,bcast_mpi_r4, &
+		     bcast_mpi_l,bcast_mpi_l1,bcast_mpi_l2,bcast_mpi_l3,bcast_mpi_l4
+  END INTERFACE
+
+
   
 CONTAINS
@@ -1646,4 +1656,78 @@
   END SUBROUTINE gather_field
 
+
+  SUBROUTINE scatter_field(field_glo,field_loc)
+  USE field_mod
+  USE domain_mod
+  USE mpi_mod
+  USE mpipara
+  IMPLICIT NONE
+    TYPE(t_field),POINTER :: field_glo(:)
+    TYPE(t_field),POINTER :: field_loc(:)
+    INTEGER, ALLOCATABLE :: mpi_req(:)
+    INTEGER, ALLOCATABLE :: status(:,:)
+    INTEGER :: ireq,nreq
+    INTEGER :: ind_glo,ind_loc    
+  
+    IF (.NOT. using_mpi) THEN
+    
+      DO ind_loc=1,ndomain
+        IF (field_loc(ind_loc)%ndim==2) field_loc(ind_loc)%rval2d=field_glo(ind_loc)%rval2d
+        IF (field_loc(ind_loc)%ndim==3) field_loc(ind_loc)%rval3d=field_glo(ind_loc)%rval3d
+        IF (field_loc(ind_loc)%ndim==4) field_loc(ind_loc)%rval4d=field_glo(ind_loc)%rval4d
+      ENDDO
+    
+    ELSE
+          
+      nreq=ndomain
+      IF (mpi_rank==0) nreq=nreq+ndomain_glo 
+      ALLOCATE(mpi_req(nreq))
+      ALLOCATE(status(MPI_STATUS_SIZE,nreq))
+    
+    
+      ireq=0
+      IF (mpi_rank==0) THEN
+        DO ind_glo=1,ndomain_glo
+          ireq=ireq+1
+
+          IF (field_glo(ind_glo)%ndim==2) THEN
+            CALL MPI_ISEND(field_glo(ind_glo)%rval2d,size(field_glo(ind_glo)%rval2d) , MPI_REAL8 ,   &
+                         domglo_rank(ind_glo),domglo_loc_ind(ind_glo), comm_icosa, mpi_req(ireq), ierr)
+   
+          ELSE IF (field_glo(ind_glo)%ndim==3) THEN
+            CALL MPI_ISEND(field_glo(ind_glo)%rval3d,size(field_glo(ind_glo)%rval3d) , MPI_REAL8 ,   &
+                         domglo_rank(ind_glo),domglo_loc_ind(ind_glo), comm_icosa, mpi_req(ireq), ierr)
+
+          ELSE IF (field_glo(ind_glo)%ndim==4) THEN
+            CALL MPI_ISEND(field_glo(ind_glo)%rval4d,size(field_glo(ind_glo)%rval4d) , MPI_REAL8 ,   &
+                         domglo_rank(ind_glo),domglo_loc_ind(ind_glo), comm_icosa, mpi_req(ireq), ierr)
+          ENDIF
+         
+        ENDDO
+      ENDIF
+  
+      DO ind_loc=1,ndomain
+        ireq=ireq+1
+
+        IF (field_loc(ind_loc)%ndim==2) THEN
+          CALL MPI_IRECV(field_loc(ind_loc)%rval2d,size(field_loc(ind_loc)%rval2d) , MPI_REAL8 ,   &
+                         0, ind_loc, comm_icosa, mpi_req(ireq), ierr)
+        ELSE IF (field_loc(ind_loc)%ndim==3) THEN
+          CALL MPI_IRECV(field_loc(ind_loc)%rval3d,size(field_loc(ind_loc)%rval3d) , MPI_REAL8 ,   &
+                         0, ind_loc, comm_icosa, mpi_req(ireq), ierr)
+        ELSE IF (field_loc(ind_loc)%ndim==4) THEN
+          CALL MPI_IRECV(field_loc(ind_loc)%rval4d,size(field_loc(ind_loc)%rval4d) , MPI_REAL8 ,   &
+                         0, ind_loc, comm_icosa, mpi_req(ireq), ierr)
+        ENDIF
+      
+      ENDDO
+   
+      CALL MPI_WAITALL(nreq,mpi_req,status,ierr)
+
+    ENDIF
+        
+  END SUBROUTINE scatter_field
+
+
    
   SUBROUTINE trace_in
@@ -1661,4 +1745,230 @@
   END SUBROUTINE trace_out              
 
+
+
+
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!! Definition des Broadcast --> 4D   !!
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+!! -- Les chaine de charactère -- !!
+
+  SUBROUTINE bcast_mpi_c(var1)
+  IMPLICIT NONE
+    CHARACTER(LEN=*),INTENT(INOUT) :: Var1
+   
+    CALL bcast_mpi_cgen(Var1,len(Var1))
+
+  END SUBROUTINE bcast_mpi_c
+
+!! -- Les entiers -- !!
+  
+  SUBROUTINE bcast_mpi_i(var)
+  USE mpipara
+  IMPLICIT NONE
+    INTEGER,INTENT(INOUT) :: Var
+    
+    INTEGER               :: var_tmp(1)
+    
+    IF (is_mpi_master) var_tmp(1)=var
+    CALL bcast_mpi_igen(Var_tmp,1)
+    var=var_tmp(1)
+    
+  END SUBROUTINE bcast_mpi_i
+
+  SUBROUTINE bcast_mpi_i1(var)
+  IMPLICIT NONE
+    INTEGER,INTENT(INOUT) :: Var(:)
+
+    CALL bcast_mpi_igen(Var,size(Var))
+    
+  END SUBROUTINE bcast_mpi_i1
+
+  SUBROUTINE bcast_mpi_i2(var)
+  IMPLICIT NONE
+    INTEGER,INTENT(INOUT) :: Var(:,:)
+   
+    CALL bcast_mpi_igen(Var,size(Var))
+  
+  END SUBROUTINE bcast_mpi_i2
+
+  SUBROUTINE bcast_mpi_i3(var)
+  IMPLICIT NONE
+    INTEGER,INTENT(INOUT) :: Var(:,:,:)
+   
+    CALL bcast_mpi_igen(Var,size(Var))
+
+  END SUBROUTINE bcast_mpi_i3
+
+  SUBROUTINE bcast_mpi_i4(var)
+  IMPLICIT NONE
+    INTEGER,INTENT(INOUT) :: Var(:,:,:,:)
+   
+    CALL bcast_mpi_igen(Var,size(Var))
+
+  END SUBROUTINE bcast_mpi_i4
+
+
+!! -- Les reels -- !!
+
+  SUBROUTINE bcast_mpi_r(var)
+  USE mpipara
+  IMPLICIT NONE
+    REAL,INTENT(INOUT) :: Var
+    REAL               :: var_tmp(1)
+    
+    IF (is_mpi_master) var_tmp(1)=var
+    CALL bcast_mpi_rgen(Var_tmp,1)
+    var=var_tmp(1)   
+
+  END SUBROUTINE bcast_mpi_r
+
+  SUBROUTINE bcast_mpi_r1(var)
+  IMPLICIT NONE
+    REAL,INTENT(INOUT) :: Var(:)
+   
+    CALL bcast_mpi_rgen(Var,size(Var))
+
+  END SUBROUTINE bcast_mpi_r1
+
+  SUBROUTINE bcast_mpi_r2(var)
+  IMPLICIT NONE
+    REAL,INTENT(INOUT) :: Var(:,:)
+   
+    CALL bcast_mpi_rgen(Var,size(Var))
+
+  END SUBROUTINE bcast_mpi_r2
+
+  SUBROUTINE bcast_mpi_r3(var)
+  IMPLICIT NONE
+    REAL,INTENT(INOUT) :: Var(:,:,:)
+   
+    CALL bcast_mpi_rgen(Var,size(Var))
+
+  END SUBROUTINE bcast_mpi_r3
+
+  SUBROUTINE bcast_mpi_r4(var)
+  IMPLICIT NONE
+    REAL,INTENT(INOUT) :: Var(:,:,:,:)
+   
+    CALL bcast_mpi_rgen(Var,size(Var))
+
+  END SUBROUTINE bcast_mpi_r4
+  
+!! -- Les booleans -- !!
+
+  SUBROUTINE bcast_mpi_l(var)
+  USE mpipara
+  IMPLICIT NONE
+    LOGICAL,INTENT(INOUT) :: Var
+    LOGICAL               :: var_tmp(1)
+    
+    IF (is_mpi_master) var_tmp(1)=var
+    CALL bcast_mpi_lgen(Var_tmp,1)
+    var=var_tmp(1)   
+
+  END SUBROUTINE bcast_mpi_l
+
+  SUBROUTINE bcast_mpi_l1(var)
+  IMPLICIT NONE
+    LOGICAL,INTENT(INOUT) :: Var(:)
+   
+    CALL bcast_mpi_lgen(Var,size(Var))
+
+  END SUBROUTINE bcast_mpi_l1
+
+  SUBROUTINE bcast_mpi_l2(var)
+  IMPLICIT NONE
+    LOGICAL,INTENT(INOUT) :: Var(:,:)
+   
+    CALL bcast_mpi_lgen(Var,size(Var))
+
+  END SUBROUTINE bcast_mpi_l2
+
+  SUBROUTINE bcast_mpi_l3(var)
+  IMPLICIT NONE
+    LOGICAL,INTENT(INOUT) :: Var(:,:,:)
+   
+    CALL bcast_mpi_lgen(Var,size(Var))
+
+  END SUBROUTINE bcast_mpi_l3
+
+  SUBROUTINE bcast_mpi_l4(var)
+  IMPLICIT NONE
+    LOGICAL,INTENT(INOUT) :: Var(:,:,:,:)
+   
+    CALL bcast_mpi_lgen(Var,size(Var))
+
+  END SUBROUTINE bcast_mpi_l4
+  
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!! DEFINITION DES FONCTIONS DE TRANSFERT GENERIQUES !
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+  SUBROUTINE bcast_mpi_cgen(var,nb)
+    USE mpi_mod
+    USE mpipara
+    IMPLICIT NONE
+    
+    CHARACTER(LEN=*),INTENT(INOUT) :: Var
+    INTEGER,INTENT(IN) :: nb
+
+    IF (.NOT. using_mpi) RETURN
+    
+    CALL MPI_BCAST(Var,nb,MPI_CHARACTER,mpi_master,comm_icosa,ierr)
+        
+  END SUBROUTINE bcast_mpi_cgen
+
+
+      
+  SUBROUTINE bcast_mpi_igen(var,nb)
+    USE mpi_mod
+    USE mpipara
+    IMPLICIT NONE
+    
+    INTEGER,DIMENSION(nb),INTENT(INOUT) :: Var
+    INTEGER,INTENT(IN) :: nb
+
+    IF (.NOT. using_mpi) RETURN
+
+    CALL MPI_BCAST(Var,nb,MPI_INTEGER,mpi_master,comm_icosa,ierr)
+        
+  END SUBROUTINE bcast_mpi_igen
+
+
+
+  
+  SUBROUTINE bcast_mpi_rgen(var,nb)
+    USE mpi_mod
+    USE mpipara
+    IMPLICIT NONE
+    
+    REAL,DIMENSION(nb),INTENT(INOUT) :: Var
+    INTEGER,INTENT(IN) :: nb
+
+    IF (.NOT. using_mpi) RETURN
+
+    CALL MPI_BCAST(Var,nb,MPI_REAL,mpi_master,comm_icosa,ierr)
+    
+  END SUBROUTINE bcast_mpi_rgen
+  
+
+
+
+  SUBROUTINE bcast_mpi_lgen(var,nb)
+    USE mpi_mod
+    USE mpipara
+    IMPLICIT NONE
+    
+    LOGICAL,DIMENSION(nb),INTENT(INOUT) :: Var
+    INTEGER,INTENT(IN) :: nb
+
+    IF (.NOT. using_mpi) RETURN
+
+    CALL MPI_BCAST(Var,nb,MPI_LOGICAL,mpi_master,comm_icosa,ierr)
+
+  END SUBROUTINE bcast_mpi_lgen
+  
+   
 END MODULE transfert_mpi_mod
       
Index: codes/icosagcm/trunk/src/wind.f90
===================================================================
--- codes/icosagcm/trunk/src/wind.f90	(revision 265)
+++ codes/icosagcm/trunk/src/wind.f90	(revision 266)
@@ -24,4 +24,24 @@
   END SUBROUTINE un2ulonlat
 
+  SUBROUTINE ulonlat2un(f_ulon, f_ulat,f_u)
+  USE icosa
+  IMPLICIT NONE
+    TYPE(t_field), POINTER :: f_ulon(:), f_ulat(:) ! IN : velocity reconstructed at hexagons
+    TYPE(t_field), POINTER :: f_u(:) ! OUT  : normal velocity components on edges
+    
+    REAL(rstd),POINTER :: u(:,:),  ulon(:,:), ulat(:,:)
+    INTEGER :: ind
+
+    DO ind=1,ndomain
+       IF (.NOT. assigned_domain(ind)) CYCLE
+       CALL swap_dimensions(ind)
+       CALL swap_geometry(ind)
+       u=f_u(ind)
+       ulon=f_ulon(ind)
+       ulat=f_ulat(ind)
+       CALL compute_ulonlat2un(ulon, ulat,u)
+    END DO
+
+  END SUBROUTINE ulonlat2un
  
   SUBROUTINE compute_wind_centered(ue,ucenter)
@@ -298,4 +318,52 @@
  END SUBROUTINE compute_wind_centered_lonlat_compound
 
+ SUBROUTINE compute_wind_centered_from_wind_lonlat_centered(ulon, ulat,uc)
+  USE icosa  
+    
+  IMPLICIT NONE
+  REAL(rstd) :: ulon(iim*jjm,llm)
+  REAL(rstd) :: ulat(iim*jjm,llm)
+  REAL(rstd) :: uc(iim*jjm,3,llm)
+
+  INTEGER :: i,j,ij,l     
+    
+  
+    DO l=1,llm
+      DO j=jj_begin,jj_end
+        DO i=ii_begin,ii_end
+          ij=(j-1)*iim+i
+          uc(ij,:,l)=ulon(ij,l)*elon_i(ij,:)+ulat(ij,l)*elat_i(ij,:)
+        ENDDO
+      ENDDO
+    ENDDO
+ 
+ END SUBROUTINE compute_wind_centered_from_wind_lonlat_centered
+
+
+
+ SUBROUTINE compute_wind_perp_from_wind_centered(uc,un)
+  USE icosa  
+    
+  IMPLICIT NONE
+  REAL(rstd),INTENT(IN)   :: uc(iim*jjm,3,llm)
+  REAL(rstd),INTENT(OUT)  :: un(3*iim*jjm,llm)
+
+  INTEGER :: i,j,ij,l     
+    
+  
+    DO l=1,llm
+      DO j=jj_begin,jj_end
+        DO i=ii_begin,ii_end
+          ij=(j-1)*iim+i
+          un(ij+u_right,l) = sum(0.5*(uc(ij,:,l) + uc(ij+t_right,:,l))*ep_e(ij+u_right,:))
+          un(ij+u_lup,l) = sum(0.5*(uc(ij,:,l) + uc(ij+t_lup,:,l))*ep_e(ij+u_lup,:))
+          un(ij+u_ldown,l) = sum(0.5*(uc(ij,:,l) + uc(ij+t_ldown,:,l))*ep_e(ij+u_ldown,:))
+         ENDDO
+      ENDDO
+    ENDDO
+ 
+ END SUBROUTINE compute_wind_perp_from_wind_centered
+
+
  SUBROUTINE compute_un2ulonlat(un, ulon, ulat)
   USE icosa  
@@ -313,3 +381,19 @@
  END SUBROUTINE compute_un2ulonlat
 
+ SUBROUTINE compute_ulonlat2un(ulon, ulat,un)
+  USE icosa  
+    
+  IMPLICIT NONE
+  REAL(rstd),INTENT(IN) :: ulon(iim*jjm,llm)
+  REAL(rstd),INTENT(IN) :: ulat(iim*jjm,llm)
+  REAL(rstd),INTENT(OUT)  :: un(3*iim*jjm,llm)
+
+  REAL(rstd)             :: uc(iim*jjm,3,llm)
+    
+    CALL compute_wind_centered_from_wind_lonlat_centered(ulon, ulat, uc)  
+    CALL compute_wind_perp_from_wind_centered(uc, un)
+ 
+ END SUBROUTINE compute_ulonlat2un
+
+
 END MODULE wind_mod
Index: codes/icosagcm/trunk/src/write_etat0.f90
===================================================================
--- codes/icosagcm/trunk/src/write_etat0.f90	(revision 266)
+++ codes/icosagcm/trunk/src/write_etat0.f90	(revision 266)
@@ -0,0 +1,37 @@
+MODULE write_etat0_mod
+
+
+
+CONTAINS
+
+  SUBROUTINE write_etat0(it,f_ps,f_phis,f_theta_rhodz,f_u, f_q)
+  USE icosa
+  USE restart_mod
+  USE wind_mod
+  USE write_field
+  IMPLICIT NONE
+    INTEGER,INTENT(IN)    :: it
+    TYPE(t_field),POINTER :: f_ps(:)
+    TYPE(t_field),POINTER :: f_phis(:)
+    TYPE(t_field),POINTER :: f_theta_rhodz(:)
+    TYPE(t_field),POINTER :: f_u(:)
+    TYPE(t_field),POINTER :: f_q(:)
+  
+    TYPE(t_field),POINTER,SAVE :: f_ulon(:)
+    TYPE(t_field),POINTER,SAVE :: f_ulat(:)
+    
+    
+    CALL allocate_field(f_ulon,field_t,type_real,llm,name='ulon')
+    CALL allocate_field(f_ulat,field_t,type_real,llm,name='ulat')
+
+    CALL transfert_request(f_u,req_e1_vect)
+    CALL un2ulonlat(f_u, f_ulon, f_ulat)
+    
+    CALL write_restart(it,f_ps,f_phis,f_theta_rhodz,f_u, f_ulon, f_ulat, f_q)
+
+    CALL deallocate_field(f_ulon)
+    CALL deallocate_field(f_ulat)
+    
+  END SUBROUTINE write_etat0
+    
+END MODULE write_etat0_mod
Index: codes/icosagcm/trunk/src/xios_mod.F90
===================================================================
--- codes/icosagcm/trunk/src/xios_mod.F90	(revision 265)
+++ codes/icosagcm/trunk/src/xios_mod.F90	(revision 266)
@@ -420,5 +420,15 @@
 
  END SUBROUTINE xios_write_field_finalize
-   
+
+ SUBROUTINE xios_set_context
+ IMPLICIT NONE   
+  TYPE(xios_context) :: ctx_hdl
+
+!$OMP MASTER 
+   CALL xios_get_handle("icosagcm",ctx_hdl)
+   CALL xios_set_current_context(ctx_hdl)
+!$OMP END MASTER
+
+  END SUBROUTINE xios_set_context
 #else
   
@@ -447,4 +457,9 @@
   SUBROUTINE xios_init_write_field
   END SUBROUTINE xios_init_write_field  
+  
+  SUBROUTINE xios_set_context
+  END SUBROUTINE xios_set_context
+  
+
 #endif  
   
