Index: /codes/icosagcm/trunk/src/icosa_init.f90
===================================================================
--- /codes/icosagcm/trunk/src/icosa_init.f90	(revision 881)
+++ /codes/icosagcm/trunk/src/icosa_init.f90	(revision 882)
@@ -22,4 +22,6 @@
   USE diagflux_mod
   USE profiling_mod
+  USE read_metric_mod
+  USE xios
   IMPLICIT NONE
   
@@ -39,4 +41,5 @@
   !$OMP PARALLEL  
     CALL switch_omp_no_distrib_level
+    CALL read_metric
     CALL compute_geometry
     CALL check_total_area
@@ -64,5 +67,9 @@
     CALL init_diagflux
     CALL zero_du_phys
+    
+    IF (is_omp_master) CALL xios_timer_resume("dynamico")
     CALL timeloop
+    IF (is_omp_master) CALL xios_timer_suspend("dynamico")
+    
     CALL switch_omp_no_distrib_level
   !$OMP END PARALLEL
Index: /codes/icosagcm/trunk/src/output/write_etat0.f90
===================================================================
--- /codes/icosagcm/trunk/src/output/write_etat0.f90	(revision 881)
+++ /codes/icosagcm/trunk/src/output/write_etat0.f90	(revision 882)
@@ -26,5 +26,7 @@
     TYPE(t_field),POINTER,SAVE :: f_ulat(:)
     TYPE(t_field),POINTER,SAVE :: f_theta_rhodz_1d(:)
+    TYPE(t_field),POINTER,SAVE :: f_xcell(:),f_ycell(:),f_zcell(:)
     REAL(rstd), POINTER :: theta_rhodz(:,:,:),theta_rhodz_1d(:,:)
+    REAL(rstd), POINTER :: xcell(:), ycell(:), zcell(:)
     INTEGER :: ind
     
@@ -33,10 +35,18 @@
     CALL allocate_field(f_ulat,field_t,type_real,llm,name='ulat')
     CALL allocate_field(f_theta_rhodz_1d,field_t,type_real,llm,name='theta_rhodz')
+    CALL allocate_field(f_xcell,field_t,type_real,name='xcell')
+    CALL allocate_field(f_ycell,field_t,type_real,name='ycell')
+    CALL allocate_field(f_zcell,field_t,type_real,name='zcell')
 
 !$OMP BARRIER    
     DO ind=1, ndomain
        IF (.NOT. assigned_domain(ind) .OR. .NOT. is_omp_level_master) CYCLE
+       CALL swap_dimensions(ind)
+       CALL swap_geometry(ind)
        theta_rhodz=f_theta_rhodz(ind) ; theta_rhodz_1d=f_theta_rhodz_1d(ind)
        theta_rhodz_1d(:,:)=theta_rhodz(:,:,1)
+       xcell=f_xcell(ind) ; xcell=xyz_i(:,1)/radius
+       ycell=f_ycell(ind) ; ycell=xyz_i(:,2)/radius
+       zcell=f_zcell(ind) ; zcell=xyz_i(:,3)/radius
     ENDDO
     
@@ -45,7 +55,7 @@
 
     IF(hydrostatic) THEN
-       CALL write_restart(it,f_ps,f_phis,f_theta_rhodz_1d,f_u, f_ulon, f_ulat, f_q)
+       CALL write_restart(it,f_ps,f_phis,f_theta_rhodz_1d,f_u, f_ulon, f_ulat, f_q, f_xcell, f_ycell, f_zcell )
     ELSE
-       CALL write_restart(it,f_ps,f_phis,f_theta_rhodz_1d,f_u, f_ulon, f_ulat, f_q, f_geopot, f_W)
+       CALL write_restart(it,f_ps,f_phis,f_theta_rhodz_1d,f_u, f_ulon, f_ulat, f_q, f_geopot, f_W, f_xcell, f_ycell, f_zcell)
     END IF
     CALL deallocate_field(f_ulon)
Index: /codes/icosagcm/trunk/src/output/xios_mod.F90
===================================================================
--- /codes/icosagcm/trunk/src/output/xios_mod.F90	(revision 881)
+++ /codes/icosagcm/trunk/src/output/xios_mod.F90	(revision 882)
@@ -31,6 +31,6 @@
      using_xios=.TRUE.
      CALL xios_context_initialize("icosagcm",comm_icosa)
-     CALL xios_get_handle("icosagcm",ctx_hdl)
-     CALL xios_set_current_context(ctx_hdl)
+     CALL xios_context_initialize("icosagcm_input",comm_icosa)
+     CALL xios_set_context
    
  END SUBROUTINE xios_init  
@@ -60,9 +60,10 @@
   TYPE(t_domain),POINTER :: d
 
+   CALL xios_set_context
 !$OMP BARRIER
 !$OMP MASTER
 !   CALL xios_context_initialize("icosagcm",comm_icosa)
-   CALL xios_get_handle("icosagcm",ctx_hdl)
-   CALL xios_set_current_context(ctx_hdl)
+!   CALL xios_get_handle("icosagcm",ctx_hdl)
+!   CALL xios_set_current_context(ctx_hdl)
    lev_value(:) = (/ (l,l=1,llm) /)     
    lev_valuep1(:) = (/ (l,l=1,llm+1) /)     
@@ -274,5 +275,102 @@
    
  END SUBROUTINE xios_init_write_field
-  
+ 
+ 
+ SUBROUTINE xios_init_write_field_input
+ USE genmod
+ USE mpipara
+ USE xios
+ USE grid_param
+ USE domain_mod
+ USE dimensions
+ USE spherical_geom_mod
+ USE geometry
+ USE mpi_mod
+ USE time_mod
+ USE metric, ONLY : vup,vdown, cell_glo
+ USE icosa,ONLY  : getin
+ IMPLICIT NONE
+  TYPE(xios_context) :: ctx_hdl
+  TYPE(xios_duration)      :: dtime
+  INTEGER :: ncell, ncell_tot, ncell_glo(0:mpi_size-1), displ
+  INTEGER :: ind, i,j,k,l,ij
+  REAL(rstd),ALLOCATABLE    :: lon(:), lat(:), bounds_lon(:,:), bounds_lat(:,:)
+  INTEGER, ALLOCATABLE      :: ind_glo(:)
+  TYPE(t_domain),POINTER :: d
+  CHARACTER(len=255) :: etat0_type
+  LOGICAL :: read_metric_
+
+   CALL xios_set_context_input
+!$OMP BARRIER
+!$OMP MASTER
+   
+   ncell=0
+   DO ind=1,ndomain
+     d=>domain(ind)
+        
+     DO j=d%jj_begin,d%jj_end
+       DO i=d%ii_begin,d%ii_end
+         IF (domain(ind)%own(i,j)) ncell=ncell+1
+       ENDDO
+     ENDDO
+   ENDDO      
+   ncell_i=ncell
+   
+   CALL MPI_ALLGATHER(ncell,1,MPI_INTEGER,ncell_glo,1,MPI_INTEGER,comm_icosa,ierr)
+
+   displ=0
+   DO i=1,mpi_rank
+     displ=displ+ncell_glo(i-1)
+   ENDDO
+
+   ncell_tot=sum(ncell_glo(:))
+   
+   ALLOCATE(lon(ncell), lat(ncell), bounds_lon(0:5,ncell), bounds_lat(0:5,ncell), ind_glo(ncell)) 
+   
+   ncell=0
+   DO ind=1,ndomain
+     d=>domain(ind)
+        
+     DO j=d%jj_begin,d%jj_end
+       DO i=d%ii_begin,d%ii_end
+         IF (domain(ind)%own(i,j)) THEN 
+           ncell=ncell+1
+           CALL xyz2lonlat(d%xyz(:,i,j),lon(ncell),lat(ncell))
+           lon(ncell)=lon(ncell)*180/Pi
+           lat(ncell)=lat(ncell)*180/Pi
+           DO k=0,5
+             CALL xyz2lonlat(d%vertex(:,k,i,j),bounds_lon(k,ncell), bounds_lat(k,ncell))
+             bounds_lat(k,ncell)=bounds_lat(k,ncell)*180/Pi
+             bounds_lon(k,ncell)=bounds_lon(k,ncell)*180/Pi
+           ENDDO
+           ind_glo(ncell)=domain(ind)%assign_cell_glo(i,j)-1 
+         ENDIF
+       ENDDO
+     ENDDO
+   ENDDO         
+
+   CALL xios_set_domain_attr("i",ni_glo=ncell_tot, ibegin=displ, ni=ncell)
+   CALL xios_set_domain_attr("i", data_dim=1, type='unstructured' , nvertex=6, i_index=ind_glo)
+   CALL xios_set_domain_attr("i",lonvalue_1d=lon, latvalue_1d=lat, bounds_lon_1d=bounds_lon, bounds_lat_1d=bounds_lat)
+   
+   DEALLOCATE(lon, lat, bounds_lon, bounds_lat,ind_glo) 
+
+   dtime%second=1
+   CALL xios_set_timestep(dtime)
+
+   CALL getin('etat0',etat0_type)
+   CALL getin('read_metric', read_metric_) 
+   
+   CALL xios_set_file_attr('start', enabled=.FALSE.)
+   IF (TRIM(etat0_type)=='start_file' .AND. read_metric_) THEN
+     CALL xios_set_file_attr('start', enabled=.TRUE.)
+   ENDIF
+     
+
+   CALL xios_close_context_definition()
+!$OMP END MASTER
+!$OMP BARRIER
+   
+ END SUBROUTINE xios_init_write_field_input 
   
  SUBROUTINE xios_write_field(name,field)
@@ -955,4 +1053,15 @@
   END SUBROUTINE xios_set_context
 
+ SUBROUTINE xios_set_context_input
+ IMPLICIT NONE   
+  TYPE(xios_context) :: ctx_hdl
+
+!$OMP MASTER 
+   CALL xios_get_handle("icosagcm_input",ctx_hdl)
+   CALL xios_set_current_context(ctx_hdl)
+!$OMP END MASTER
+
+  END SUBROUTINE xios_set_context_input
+
 
 #else
@@ -1020,4 +1129,7 @@
   SUBROUTINE xios_set_context
   END SUBROUTINE xios_set_context
+
+  SUBROUTINE xios_set_context_input
+  END SUBROUTINE xios_set_context_input
   
   SUBROUTINE xios_set_fieldgroup_attr(name,enabled,freq_op)
Index: /codes/icosagcm/trunk/src/read_metric.f90
===================================================================
--- /codes/icosagcm/trunk/src/read_metric.f90	(revision 882)
+++ /codes/icosagcm/trunk/src/read_metric.f90	(revision 882)
@@ -0,0 +1,59 @@
+MODULE read_metric_mod
+
+CONTAINS
+
+
+  SUBROUTINE read_metric
+  USE icosa
+  USE xios_mod
+  USE omp_para
+  IMPLICIT NONE
+    TYPE(t_field),POINTER,SAVE :: f_xcell(:),f_ycell(:),f_zcell(:)
+    REAL(rstd), POINTER :: xcell(:), ycell(:), zcell(:)
+    TYPE(t_domain),POINTER :: d
+    INTEGER :: ind,i,j,n
+    CHARACTER(len=255) :: etat0_type
+    LOGICAL :: read_metric_
+    
+    CALL getin('etat0',etat0_type)
+    CALL getin('read_metric', read_metric_) 
+    
+    CALL allocate_field(f_xcell,field_t,type_real,name='xcell')
+    CALL allocate_field(f_ycell,field_t,type_real,name='ycell')
+    CALL allocate_field(f_zcell,field_t,type_real,name='zcell')
+
+    CALL xios_set_context_input
+    CALL xios_init_write_field_input 
+
+    IF (TRIM(etat0_type)=='start_file' .AND. read_metric_) THEN
+    
+      CALL xios_read_field("xcell_start",f_xcell)
+      CALL xios_read_field("ycell_start",f_ycell)
+      CALL xios_read_field("zcell_start",f_zcell)
+
+      DO ind=1,ndomain
+        IF (.NOT. assigned_domain(ind)  .OR. .NOT. is_omp_level_master) CYCLE
+        d=>domain(ind)
+        CALL swap_dimensions(ind)
+        xcell=f_xcell(ind) 
+        ycell=f_ycell(ind) 
+        zcell=f_zcell(ind) 
+      
+        DO j=jj_begin,jj_end
+          DO i=ii_begin,ii_end
+            n=(j-1)*iim+i
+            d%xyz(1,i,j) = xcell(n) 
+            d%xyz(2,i,j) = ycell(n) 
+            d%xyz(3,i,j) = zcell(n) 
+          ENDDO
+        ENDDO
+      ENDDO
+    ENDIF
+
+    CALL xios_set_context
+
+  END SUBROUTINE read_metric
+
+
+
+END MODULE read_metric_mod
Index: /codes/icosagcm/trunk/src/sphere/geometry.f90
===================================================================
--- /codes/icosagcm/trunk/src/sphere/geometry.f90	(revision 881)
+++ /codes/icosagcm/trunk/src/sphere/geometry.f90	(revision 882)
@@ -295,24 +295,25 @@
     CALL update_circumcenters
 
-    DO ind=1,ndomain
-      IF (.NOT. assigned_domain(ind)  .OR. .NOT. is_omp_level_master ) CYCLE
-      d=>domain(ind)
-      CALL swap_dimensions(ind)
-      CALL swap_geometry(ind)
-      DO j=jj_begin,jj_end
-        DO i=ii_begin,ii_end
-          n=(j-1)*iim+i
-          DO k=0,5
-            x1(:) = xyz_v(n+z_pos(k+1),:)
-            x2(:) = d%vertex(:,k,i,j) 
-            IF (norm(x1-x2)>1e-10) THEN
-              PRINT*,"vertex diff ",ind,i,j,k
-              PRINT*,x1
-              PRINT*,x2
-            ENDIF
-          ENDDO
-        ENDDO
-      ENDDO
-    ENDDO
+!ym you get discrepency if you try to read metric from file, vertex are not saved in file
+!    DO ind=1,ndomain
+!      IF (.NOT. assigned_domain(ind)  .OR. .NOT. is_omp_level_master ) CYCLE
+!      d=>domain(ind)
+!      CALL swap_dimensions(ind)
+!      CALL swap_geometry(ind)
+!      DO j=jj_begin,jj_end
+!        DO i=ii_begin,ii_end
+!          n=(j-1)*iim+i
+!          DO k=0,5
+!            x1(:) = xyz_v(n+z_pos(k+1),:)
+!            x2(:) = d%vertex(:,k,i,j) 
+!            IF (norm(x1-x2)>1e-10) THEN
+!              PRINT*,"vertex diff ",ind,i,j,k
+!              PRINT*,x1
+!              PRINT*,x2
+!            ENDIF
+!          ENDDO
+!        ENDDO
+!      ENDDO
+!   ENDDO
     
     
