Index: codes/icosagcm/branches/SATURN_DYNAMICO/ICOSAGCM/src/physics_lmdz_generic.f90
===================================================================
--- codes/icosagcm/branches/SATURN_DYNAMICO/ICOSAGCM/src/physics_lmdz_generic.f90	(revision 313)
+++ codes/icosagcm/branches/SATURN_DYNAMICO/ICOSAGCM/src/physics_lmdz_generic.f90	(revision 314)
@@ -54,4 +54,5 @@
   REAL(rstd),ALLOCATABLE :: bounds_latfi(:,:)
   REAL(rstd),ALLOCATABLE :: bounds_lonfi(:,:)
+  INTEGER :: time0
 
     start_day=0
@@ -120,7 +121,7 @@
     ENDDO
 
-
+    time0=itau0*dt
     CALL initialize_unstructured_physics(nbp_phys,llm, comm_icosa, mpi_size,distrib,            &
-                                         day_length,start_day,itau_physics*dt,                  &
+                                         day_length,start_day,time0,itau_physics*dt,                  &
                                          6,latfi,lonfi,airefi,bounds_lonfi,bounds_latfi,         &
                                          radius,g, gas_constant/mu, cpp,                        &
Index: codes/icosagcm/branches/SATURN_DYNAMICO/ICOSAGCM/src/restart.f90
===================================================================
--- codes/icosagcm/branches/SATURN_DYNAMICO/ICOSAGCM/src/restart.f90	(revision 313)
+++ codes/icosagcm/branches/SATURN_DYNAMICO/ICOSAGCM/src/restart.f90	(revision 314)
@@ -4,8 +4,16 @@
   TYPE t_field_array
     TYPE(t_field),POINTER :: field(:)
+    INTEGER               :: id
   END TYPE t_field_array
 
-
-
+  TYPE(t_field_array),SAVE :: field_array(20)
+!$OMP THREADPRIVATE(field_array)
+  
+  INTEGER,SAVE :: ncid
+  INTEGER,SAVE :: itid
+
+
+  PRIVATE :: ncid
+  
 CONTAINS
   
@@ -31,5 +39,4 @@
   TYPE(t_field_array) :: field_array(20)
   INTEGER             :: nfield
-  INTEGER             :: fieldId(20)
    
   TYPE(t_domain),POINTER :: d
@@ -39,12 +46,15 @@
   CHARACTER(LEN=255) :: restart_file_name
   INTEGER,PARAMETER  :: nvert=6
-  INTEGER    ::  ncid, cellId, levId, edgeId,  vertid, lonId, latId, bounds_lonId, bounds_latId, nqId, levAxisId
+  INTEGER    ::  cellId, levId, edgeId,  vertid, lonId, latId, bounds_lonId, bounds_latId, nqId, levAxisId
   INTEGER    :: ind,ind_glo,i,j,k,nf
   INTEGER    :: status
   REAL(rstd),ALLOCATABLE :: lon(:),lat(:),bounds_lon(:,:),bounds_lat(:,:)
+  LOGICAL,SAVE :: first=.TRUE.
+!$OMP THREADPRIVATE(first)
    
     restart_file_name="restart"
     CALL getin("restart_file_name",restart_file_name)
 
+!$OMP BARRIER
 !$OMP MASTER
 
@@ -73,5 +83,5 @@
       
 
-    IF (is_mpi_root) THEN
+    IF (is_mpi_root .AND. first) THEN
       status = NF90_CREATE(TRIM(ADJUSTL(restart_file_name))//'.nc', IOR(NF90_CLOBBER,NF90_NETCDF4), ncid)
       IF (status/=NF90_NOERR) THEN
@@ -86,5 +96,6 @@
       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_PUT_ATT(ncid,NF90_GLOBAL,"iteration",it)
+      status = NF90_DEF_VAR(ncid,"iteration",NF90_INT,varid=itid)
       
       status = NF90_DEF_VAR(ncid,'lon',NF90_DOUBLE,(/ cellId /),lonId)
@@ -107,20 +118,20 @@
         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))
-            status = NF90_PUT_ATT(ncid,FieldId(nf),"coordinates","lon lat")
+            status = NF90_DEF_VAR(ncid,TRIM(ADJUSTL(field(1)%name)),NF90_DOUBLE,(/ cellId /),field_array(nf)%id)
+            status = NF90_PUT_ATT(ncid,field_array(nf)%id,"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")
+            status = NF90_DEF_VAR(ncid,TRIM(ADJUSTL(field(1)%name)),NF90_DOUBLE,(/ cellId, levId /),field_array(nf)%id)
+            status = NF90_PUT_ATT(ncid,field_array(nf)%id,"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")
+            status = NF90_DEF_VAR(ncid,TRIM(ADJUSTL(field(1)%name)),NF90_DOUBLE,(/ cellId, levId,nqId /),field_array(nf)%id)
+            status = NF90_PUT_ATT(ncid,field_array(nf)%id,"coordinates","nq lev lon lat")
           ENDIF
         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))
+            status = NF90_DEF_VAR(ncid,TRIM(ADJUSTL(field(1)%name)),NF90_DOUBLE,(/ edgeId /),field_array(nf)%id)
           ELSE IF (field(1)%ndim==3) THEN
-            status = NF90_DEF_VAR(ncid,TRIM(ADJUSTL(field(1)%name)),NF90_DOUBLE,(/ edgeId, levId /),fieldId(nf))
+            status = NF90_DEF_VAR(ncid,TRIM(ADJUSTL(field(1)%name)),NF90_DOUBLE,(/ edgeId, levId /),field_array(nf)%id)
           ELSE IF (field(1)%ndim==4) THEN
-            status = NF90_DEF_VAR(ncid,TRIM(ADJUSTL(field(1)%name)),NF90_DOUBLE,(/ edgeId, levId, nqId /),fieldId(nf))
+            status = NF90_DEF_VAR(ncid,TRIM(ADJUSTL(field(1)%name)),NF90_DOUBLE,(/ edgeId, levId, nqId /),field_array(nf)%id)
           ENDIF
         ENDIF
@@ -162,9 +173,12 @@
       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 /))
+      first=.FALSE.
+      
     ENDIF ! of IF (is_mpi_root)
 
+    IF (is_mpi_root) status=NF90_PUT_VAR(ncid,itid,it)
     DO nf=1,nfield
       field=>field_array(nf)%field
-      CALL write_restart_field(field,fieldId(nf),ncid)
+      CALL write_restart_field(field,field_array(nf)%id,ncid)
     ENDDO
           
@@ -177,5 +191,5 @@
 
     IF (is_mpi_root) THEN
-      status = NF90_CLOSE(ncid)      
+      status = NF90_SYNC(ncid)      
       IF (status/=NF90_NOERR) THEN
          WRITE(*,*) "write_restart error: failed to close ",TRIM(ADJUSTL(restart_file_name))//'.nc'
@@ -418,5 +432,10 @@
       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)
+      status = nf90_inq_varid(ncid, "iteration",itid)
+      IF (status==NF90_NOERR) THEN 
+        status = nf90_get_var(ncid, itid, it)
+      ELSE
+        status = nf90_get_att(ncid, NF90_GLOBAL, "iteration", it)
+      ENDIF
       CALL read_start_field(field,fieldId(nf),ncid)
     ENDDO
Index: codes/icosagcm/branches/SATURN_DYNAMICO/ICOSAGCM/src/time.f90
===================================================================
--- codes/icosagcm/branches/SATURN_DYNAMICO/ICOSAGCM/src/time.f90	(revision 313)
+++ codes/icosagcm/branches/SATURN_DYNAMICO/ICOSAGCM/src/time.f90	(revision 314)
@@ -17,6 +17,6 @@
   REAL(rstd),SAVE :: write_period
 !$OMP THREADPRIVATE(write_period)  
-  INTEGER,SAVE    :: itau_out, itau_adv, itau_dissip, itau_physics, itaumax
-!$OMP THREADPRIVATE(itau_out, itau_adv, itau_dissip, itau_physics, itaumax)  
+  INTEGER,SAVE    :: itau_out, itau_adv, itau_dissip, itau_physics, itaumax, itau_write_etat0
+!$OMP THREADPRIVATE(itau_out, itau_adv, itau_dissip, itau_physics, itaumax, itau_write_etat0)  
   
   INTEGER,SAVE :: day_step,ndays
@@ -38,5 +38,5 @@
 
   PUBLIC create_time_counter_header, update_time_counter, close_time_counter, init_time,  &
-         dt, write_period, itau_out, itau_adv, itau_dissip, itau_physics, itaumax, & 
+         dt, write_period, itau_out, itau_adv, itau_dissip, itau_physics,itau_write_etat0, itaumax, & 
 day_step,ndays,jD_ref,jH_ref,day_ini,day_end,annee_ref,day_ref,an, mois, jour,heure, &
             calend,time_style,itau0
@@ -86,4 +86,8 @@
     itau_physics=1
     CALL getin('itau_physics',itau_physics)
+
+    itau_write_etat0=HUGE(itau_write_etat0)
+    CALL getin('itau_write_etat0',itau_write_etat0)
+    itau_write_etat0=itau_write_etat0/dt
 
     IF (is_mpi_root .AND. omp_master)  THEN
Index: codes/icosagcm/branches/SATURN_DYNAMICO/ICOSAGCM/src/timeloop_gcm.f90
===================================================================
--- codes/icosagcm/branches/SATURN_DYNAMICO/ICOSAGCM/src/timeloop_gcm.f90	(revision 313)
+++ codes/icosagcm/branches/SATURN_DYNAMICO/ICOSAGCM/src/timeloop_gcm.f90	(revision 314)
@@ -302,8 +302,12 @@
       CALL physics(it,f_phis, f_ps, f_theta_rhodz, f_u, f_wflux, f_q)
     ENDIF
+
+    IF (MOD(it,itau_write_etat0)==0 .OR. it==itau0+itaumax) THEN
+      CALL write_etat0(it,f_ps, f_phis,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 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)  
