Index: /LMDZ6/trunk/libf/phylmd/iostart.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/iostart.F90	(revision 3505)
+++ /LMDZ6/trunk/libf/phylmd/iostart.F90	(revision 3506)
@@ -25,5 +25,5 @@
 
     PUBLIC get_field,get_var,put_field,put_var
-    PUBLIC Open_startphy,close_startphy,open_restartphy,close_restartphy
+    PUBLIC Open_startphy,close_startphy,open_restartphy,close_restartphy, enddef_restartphy
     
 CONTAINS
@@ -326,9 +326,19 @@
       ierr = NF90_DEF_DIM (nid_restart, "horizon_klevp1", klon_glo*klevp1, idim4)
 
-      ierr = NF90_ENDDEF(nid_restart)
+!      ierr = NF90_ENDDEF(nid_restart)
     ENDIF
 
   END SUBROUTINE open_restartphy
   
+  SUBROUTINE enddef_restartphy
+  USE netcdf
+  USE mod_phys_lmdz_para
+  IMPLICIT NONE
+    INTEGER          :: ierr
+
+    IF (is_master) ierr = NF90_ENDDEF(nid_restart)
+ 
+  END SUBROUTINE enddef_restartphy
+
   SUBROUTINE close_restartphy
   USE netcdf
@@ -337,42 +347,42 @@
     INTEGER          :: ierr
 
-    IF (is_mpi_root .AND. is_omp_root) THEN
-      ierr = NF90_CLOSE (nid_restart)
-    ENDIF
+    IF (is_master) ierr = NF90_CLOSE (nid_restart)
  
   END SUBROUTINE close_restartphy
 
   
-  SUBROUTINE put_field_r1(field_name,title,field)
-  IMPLICIT NONE
+  SUBROUTINE put_field_r1(pass, field_name,title,field)
+  IMPLICIT NONE
+  INTEGER, INTENT(IN)            :: pass
   CHARACTER(LEN=*),INTENT(IN)    :: field_name
   CHARACTER(LEN=*),INTENT(IN)    :: title
   REAL,INTENT(IN)                :: field(:)
-  
-    CALL put_field_rgen(field_name,title,field,1)
+    CALL put_field_rgen(pass, field_name,title,field,1)
   
   END SUBROUTINE put_field_r1
 
-  SUBROUTINE put_field_r2(field_name,title,field)
-  IMPLICIT NONE
+  SUBROUTINE put_field_r2(pass, field_name,title,field)
+  IMPLICIT NONE
+  INTEGER, INTENT(IN)            :: pass
   CHARACTER(LEN=*),INTENT(IN)    :: field_name
   CHARACTER(LEN=*),INTENT(IN)    :: title
   REAL,INTENT(IN)                :: field(:,:)
   
-    CALL put_field_rgen(field_name,title,field,size(field,2))
+    CALL put_field_rgen(pass, field_name,title,field,size(field,2))
   
   END SUBROUTINE put_field_r2
 
-  SUBROUTINE put_field_r3(field_name,title,field)
-  IMPLICIT NONE
+  SUBROUTINE put_field_r3(pass, field_name,title,field)
+  IMPLICIT NONE
+  INTEGER, INTENT(IN)            :: pass
   CHARACTER(LEN=*),INTENT(IN)    :: field_name
   CHARACTER(LEN=*),INTENT(IN)    :: title
   REAL,INTENT(IN)                :: field(:,:,:)
   
-    CALL put_field_rgen(field_name,title,field,size(field,2)*size(field,3))
+    CALL put_field_rgen(pass, field_name,title,field,size(field,2)*size(field,3))
   
   END SUBROUTINE put_field_r3
   
-  SUBROUTINE put_field_rgen(field_name,title,field,field_size)
+  SUBROUTINE put_field_rgen(pass, field_name,title,field,field_size)
   USE netcdf
   USE dimphy
@@ -381,4 +391,5 @@
   USE mod_phys_lmdz_para
   IMPLICIT NONE
+  INTEGER, INTENT(IN)            :: pass
   CHARACTER(LEN=*),INTENT(IN)    :: field_name
   CHARACTER(LEN=*),INTENT(IN)    :: title
@@ -386,24 +397,18 @@
   REAL,INTENT(IN)                :: field(klon,field_size)
   
-  REAL                           :: field_glo(klon_glo,field_size)
-  REAL                           :: field_glo_tmp(klon_glo,field_size)
-!  INTEGER,ALLOCATABLE            :: ind_cell_glo_glo(:)
-  INTEGER                        :: ind_cell_glo_glo(klon_glo)
+!  REAL                           :: field_glo(klon_glo,field_size)
+!  REAL                           :: field_glo_tmp(klon_glo,field_size)
+  REAL ,ALLOCATABLE              :: field_glo(:,:)
+  REAL ,ALLOCATABLE              :: field_glo_tmp(:,:)
+  INTEGER,ALLOCATABLE            :: ind_cell_glo_glo(:)
+!  INTEGER                        :: ind_cell_glo_glo(klon_glo)
   INTEGER                        :: ierr,i
   INTEGER                        :: nvarid
   INTEGER                        :: idim
    
-   
-!    IF (is_master) ALLOCATE(ind_cell_glo_glo(klon_glo))
-    CALL gather(ind_cell_glo,ind_cell_glo_glo)
-
-    CALL gather(field,field_glo_tmp)
+! first pass : definition   
+  IF (pass==1) THEN
     
     IF (is_master) THEN
-
-      DO i=1,klon_glo
-       field_glo(ind_cell_glo_glo(i),:)=field_glo_tmp(i,:)
-      ENDDO
-
 
       IF (field_size==1) THEN
@@ -418,5 +423,5 @@
       ENDIF
          
-      ierr = NF90_REDEF (nid_restart)
+!      ierr = NF90_REDEF (nid_restart)
 #ifdef NC_DOUBLE
       ierr = NF90_DEF_VAR (nid_restart, field_name, NF90_DOUBLE,(/ idim /),nvarid)
@@ -425,12 +430,40 @@
 #endif
       IF (LEN_TRIM(title) > 0) ierr = NF90_PUT_ATT (nid_restart,nvarid,"title", title)
-      ierr = NF90_ENDDEF(nid_restart)
-      ierr = NF90_PUT_VAR(nid_restart,nvarid,RESHAPE(field_glo,(/klon_glo*field_size/)))
-    ENDIF
-    
-   END SUBROUTINE put_field_rgen  
-  
-   SUBROUTINE put_var_r0(var_name,title,var)
+!      ierr = NF90_ENDDEF(nid_restart)
+     ENDIF
+
+! second pass : write     
+   ELSE IF (pass==2) THEN 
+    
+     IF (is_master) THEN
+       ALLOCATE(ind_cell_glo_glo(klon_glo))
+       ALLOCATE(field_glo(klon_glo,field_size))
+       ALLOCATE(field_glo_tmp(klon_glo,field_size))
+     ELSE
+       ALLOCATE(ind_cell_glo_glo(0))
+       ALLOCATE(field_glo(0,0))
+     ENDIF
+     
+     CALL gather(ind_cell_glo,ind_cell_glo_glo) 
+
+     CALL gather(field,field_glo_tmp)
+    
+     IF (is_master) THEN
+
+       DO i=1,klon_glo
+         field_glo(ind_cell_glo_glo(i),:)=field_glo_tmp(i,:)
+       ENDDO
+
+       ierr = NF90_INQ_VARID(nid_restart, field_name, nvarid)
+       ierr = NF90_PUT_VAR(nid_restart,nvarid,RESHAPE(field_glo,(/klon_glo*field_size/)))
+      ENDIF
+   ENDIF
+    
+ END SUBROUTINE put_field_rgen  
+  
+
+ SUBROUTINE put_var_r0(pass, var_name,title,var)
    IMPLICIT NONE
+     INTEGER, INTENT(IN)            :: pass
      CHARACTER(LEN=*),INTENT(IN) :: var_name
      CHARACTER(LEN=*),INTENT(IN) :: title
@@ -440,53 +473,57 @@
      varin(1)=var
      
-     CALL put_var_rgen(var_name,title,varin,size(varin))
+     CALL put_var_rgen(pass, var_name,title,varin,size(varin))
 
   END SUBROUTINE put_var_r0
 
 
-   SUBROUTINE put_var_r1(var_name,title,var)
+   SUBROUTINE put_var_r1(pass, var_name,title,var)
    IMPLICIT NONE
+     INTEGER, INTENT(IN)            :: pass
      CHARACTER(LEN=*),INTENT(IN) :: var_name
      CHARACTER(LEN=*),INTENT(IN) :: title
      REAL,INTENT(IN)             :: var(:)
      
-     CALL put_var_rgen(var_name,title,var,size(var))
+     CALL put_var_rgen(pass, var_name,title,var,size(var))
 
   END SUBROUTINE put_var_r1
  
-  SUBROUTINE put_var_r2(var_name,title,var)
+  SUBROUTINE put_var_r2(pass, var_name,title,var)
    IMPLICIT NONE
+     INTEGER, INTENT(IN)            :: pass
      CHARACTER(LEN=*),INTENT(IN) :: var_name
      CHARACTER(LEN=*),INTENT(IN) :: title
      REAL,INTENT(IN)             :: var(:,:)
      
-     CALL put_var_rgen(var_name,title,var,size(var))
+     CALL put_var_rgen(pass, var_name,title,var,size(var))
 
   END SUBROUTINE put_var_r2     
   
-  SUBROUTINE put_var_r3(var_name,title,var)
+  SUBROUTINE put_var_r3(pass, var_name,title,var)
    IMPLICIT NONE
+     INTEGER, INTENT(IN)            :: pass
      CHARACTER(LEN=*),INTENT(IN) :: var_name
      CHARACTER(LEN=*),INTENT(IN) :: title
      REAL,INTENT(IN)             :: var(:,:,:)
      
-     CALL put_var_rgen(var_name,title,var,size(var))
+     CALL put_var_rgen(pass, var_name,title,var,size(var))
 
   END SUBROUTINE put_var_r3
 
-  SUBROUTINE put_var_rgen(var_name,title,var,var_size)
+  SUBROUTINE put_var_rgen(pass, var_name,title,var,var_size)
   USE netcdf
   USE dimphy
   USE mod_phys_lmdz_para
   IMPLICIT NONE
-     CHARACTER(LEN=*),INTENT(IN) :: var_name
-     CHARACTER(LEN=*),INTENT(IN) :: title
-     INTEGER,INTENT(IN)          :: var_size
-     REAL,INTENT(IN)             :: var(var_size)
-     
-     INTEGER :: ierr
-     INTEGER :: nvarid
+    INTEGER, INTENT(IN)         :: pass
+    CHARACTER(LEN=*),INTENT(IN) :: var_name
+    CHARACTER(LEN=*),INTENT(IN) :: title
+    INTEGER,INTENT(IN)          :: var_size
+    REAL,INTENT(IN)             :: var(var_size)
+    
+    INTEGER :: ierr
+    INTEGER :: nvarid
          
-    IF (is_mpi_root .AND. is_omp_root) THEN
+    IF (is_master) THEN
 
       IF (var_size/=length) THEN
@@ -494,17 +531,23 @@
         call abort_physic("", "", 1)
       ENDIF
-      
-      ierr = NF90_REDEF (nid_restart)
+
+     ! first pass : definition   
+      IF (pass==1) THEN
+        
+!      ierr = NF90_REDEF (nid_restart)
 
 #ifdef NC_DOUBLE
-      ierr = NF90_DEF_VAR (nid_restart, var_name, NF90_DOUBLE,(/ idim1 /),nvarid)
+        ierr = NF90_DEF_VAR (nid_restart, var_name, NF90_DOUBLE,(/ idim1 /),nvarid)
 #else
-      ierr = NF90_DEF_VAR (nid_restart, var_name, NF90_FLOAT,(/ idim1 /),nvarid)
+        ierr = NF90_DEF_VAR (nid_restart, var_name, NF90_FLOAT,(/ idim1 /),nvarid)
 #endif
-      IF (LEN_TRIM(title)>0) ierr = NF90_PUT_ATT (nid_restart,nvarid,"title", title)
-      ierr = NF90_ENDDEF(nid_restart)
-     
-      ierr = NF90_PUT_VAR(nid_restart,nvarid,var)
-
+        IF (LEN_TRIM(title)>0) ierr = NF90_PUT_ATT (nid_restart,nvarid,"title", title)
+!      ierr = NF90_ENDDEF(nid_restart)
+
+    ! second pass : write     
+      ELSE IF (pass==2) THEN 
+        ierr = NF90_INQ_VARID(nid_restart, var_name, nvarid)
+        ierr = NF90_PUT_VAR(nid_restart,nvarid,var)
+      ENDIF
     ENDIF
     
Index: /LMDZ6/trunk/libf/phylmd/phyredem.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/phyredem.F90	(revision 3505)
+++ /LMDZ6/trunk/libf/phylmd/phyredem.F90	(revision 3506)
@@ -29,5 +29,5 @@
                                 treedrg
   USE geometry_mod, ONLY : longitude_deg, latitude_deg
-  USE iostart, ONLY: open_restartphy, close_restartphy, put_field, put_var
+  USE iostart, ONLY: open_restartphy, close_restartphy, enddef_restartphy, put_field, put_var
   USE traclmdz_mod, ONLY : traclmdz_to_restart
   USE infotrac_phy, ONLY: type_trac, niadv, tname, nbtr, nqo
@@ -65,5 +65,5 @@
   CHARACTER (len=2) :: str2
   CHARACTER (len=256) :: nam, lnam
-  INTEGER           :: it, iiq
+  INTEGER           :: it, iiq, pass
 
   !======================================================================
@@ -80,4 +80,5 @@
   CALL open_restartphy(fichnom)
 
+  
   DO ierr = 1, length
      tab_cntrl(ierr) = 0.0
@@ -104,238 +105,243 @@
   tab_cntrl(16) = co2_ppm0
 
-  CALL put_var("controle", "Parametres de controle", tab_cntrl)
-
-  CALL put_field("longitude", &
-       "Longitudes de la grille physique", longitude_deg)
-
-  CALL put_field("latitude", "Latitudes de la grille physique", latitude_deg)
-
-  ! PB ajout du masque terre/mer
-
-  CALL put_field("masque", "masque terre mer", zmasq)
-
-  ! BP ajout des fraction de chaque sous-surface
-
-  ! Get last fractions from slab ocean
-  IF (type_ocean == 'slab' .AND. version_ocean == "sicINT") THEN
-      WHERE (1.-zmasq(:).GT.EPSFRA)
-          pctsrf(:,is_oce)=(1.-fsic(:))*(1.-zmasq(:))
-          pctsrf(:,is_sic)=fsic(:)*(1.-zmasq(:))
-      END WHERE
-  END IF
-
-  ! 1. fraction de terre 
-
-  CALL put_field("FTER", "fraction de continent", pctsrf(:, is_ter))
-
-  ! 2. Fraction de glace de terre
-
-  CALL put_field("FLIC", "fraction glace de terre", pctsrf(:, is_lic))
-
-  ! 3. fraction ocean
-
-  CALL put_field("FOCE", "fraction ocean", pctsrf(:, is_oce))
-
-  ! 4. Fraction glace de mer
-
-  CALL put_field("FSIC", "fraction glace mer", pctsrf(:, is_sic))
-
-  IF(nbsrf>99) THEN
-    PRINT*, "Trop de sous-mailles";  CALL abort_physic("phyredem", "", 1)
-  END IF
-  IF(nsoilmx>99) THEN
-    PRINT*, "Trop de sous-surfaces"; CALL abort_physic("phyredem", "", 1)
-  END IF
-  IF(nsw>99) THEN
-    PRINT*, "Trop de bandes"; CALL abort_physic("phyredem", "", 1)
-  END IF
-
-  CALL put_field_srf1("TS","Temperature",ftsol(:,:))
+  DO pass=1,2   ! pass=1 netcdf definition ; pass=2 netcdf write
+  
+    CALL put_var(pass, "controle", "Parametres de controle", tab_cntrl)
+
+    CALL put_field(pass,"longitude", &
+         "Longitudes de la grille physique", longitude_deg)
+
+    CALL put_field(pass,"latitude", "Latitudes de la grille physique", latitude_deg)
+
+    ! PB ajout du masque terre/mer
+
+    CALL put_field(pass,"masque", "masque terre mer", zmasq)
+
+    ! BP ajout des fraction de chaque sous-surface
+
+    ! Get last fractions from slab ocean
+    IF (type_ocean == 'slab' .AND. version_ocean == "sicINT") THEN
+        WHERE (1.-zmasq(:).GT.EPSFRA)
+            pctsrf(:,is_oce)=(1.-fsic(:))*(1.-zmasq(:))
+            pctsrf(:,is_sic)=fsic(:)*(1.-zmasq(:))
+        END WHERE
+    END IF
+
+    ! 1. fraction de terre 
+
+    CALL put_field(pass,"FTER", "fraction de continent", pctsrf(:, is_ter))
+
+    ! 2. Fraction de glace de terre
+
+    CALL put_field(pass,"FLIC", "fraction glace de terre", pctsrf(:, is_lic))
+
+    ! 3. fraction ocean
+
+    CALL put_field(pass,"FOCE", "fraction ocean", pctsrf(:, is_oce))
+
+    ! 4. Fraction glace de mer
+
+    CALL put_field(pass,"FSIC", "fraction glace mer", pctsrf(:, is_sic))
+
+    IF(nbsrf>99) THEN
+      PRINT*, "Trop de sous-mailles";  CALL abort_physic("phyredem", "", 1)
+    END IF
+    IF(nsoilmx>99) THEN
+      PRINT*, "Trop de sous-surfaces"; CALL abort_physic("phyredem", "", 1)
+    END IF
+    IF(nsw>99) THEN
+      PRINT*, "Trop de bandes"; CALL abort_physic("phyredem", "", 1)
+    END IF
+
+    CALL put_field_srf1(pass,"TS","Temperature",ftsol(:,:))
 
 ! ================== Albedo =======================================
-  print*,'PHYREDEM NOUVEAU'
-  CALL put_field_srf2("A_dir_SW","Albedo direct",falb_dir(:,:,:))
-  CALL put_field_srf2("A_dif_SW","Albedo diffus",falb_dif(:,:,:))
-
-  CALL put_field_srf1("U10M", "u a 10m", u10m)
-
-  CALL put_field_srf1("V10M", "v a 10m", v10m)
+    print*,'PHYREDEM NOUVEAU'
+    CALL put_field_srf2(pass,"A_dir_SW","Albedo direct",falb_dir(:,:,:))
+    CALL put_field_srf2(pass,"A_dif_SW","Albedo diffus",falb_dif(:,:,:))
+
+    CALL put_field_srf1(pass,"U10M", "u a 10m", u10m)
+
+    CALL put_field_srf1(pass,"V10M", "v a 10m", v10m)
 
 
 ! ================== Tsoil =========================================
-  CALL put_field_srf2("Tsoil","Temperature",tsoil(:,:,:))
+    CALL put_field_srf2(pass,"Tsoil","Temperature",tsoil(:,:,:))
 !FC
 !  CALL put_field_srf2("treedrg","freinage arbres",treedrg(:,:,:))
-  CALL put_field("treedrg_ter","freinage arbres",treedrg(:,:,is_ter))
-
-
-  CALL put_field_srf1("QS"  , "Humidite",qsurf(:,:))
-
-  CALL put_field     ("QSOL", "Eau dans le sol (mm)", qsol)
-
-  CALL put_field_srf1("EVAP", "Evaporation", fevap(:,:))
-
-  CALL put_field_srf1("SNOW", "Neige", snow(:,:))
-
-  CALL put_field("RADS", "Rayonnement net a la surface", radsol)
-
-  CALL put_field("solsw", "Rayonnement solaire a la surface", solsw)
-
-  CALL put_field("sollw", "Rayonnement IF a la surface", sollw)
-
-  CALL put_field("sollwdown", "Rayonnement down IF a la surface", sollwdown)
-
-  CALL put_field("fder", "Derive de flux", fder)
-
-  CALL put_field("rain_f", "precipitation liquide", rain_fall)
-
-  CALL put_field("snow_f", "precipitation solide", snow_fall)
-
-  CALL put_field_srf1("Z0m", "rugosite", z0m(:,:))
-
-  CALL put_field_srf1("Z0h", "rugosite", z0h(:,:))
-
-  CALL put_field_srf1("AGESNO", "Age de la neige", agesno(:,:))
-
-  CALL put_field("ZMEA", "ZMEA", zmea)
-
-  CALL put_field("ZSTD", "ZSTD", zstd)
-
-  CALL put_field("ZSIG", "ZSIG", zsig)
-
-  CALL put_field("ZGAM", "ZGAM", zgam)
-
-  CALL put_field("ZTHE", "ZTHE", zthe)
-
-  CALL put_field("ZPIC", "ZPIC", zpic)
-
-  CALL put_field("ZVAL", "ZVAL", zval)
-
-  CALL put_field("RUGSREL", "RUGSREL", rugoro)
-
-  CALL put_field("TANCIEN", "TANCIEN", t_ancien)
-
-  CALL put_field("QANCIEN", "QANCIEN", q_ancien)
-
-  CALL put_field("QLANCIEN", "QLANCIEN", ql_ancien)
-
-  CALL put_field("QSANCIEN", "QSANCIEN", qs_ancien)
-
-  CALL put_field("PRWANCIEN", "PRWANCIEN", prw_ancien)
-
-  CALL put_field("PRLWANCIEN", "PRLWANCIEN", prlw_ancien)
-
-  CALL put_field("PRSWANCIEN", "PRSWANCIEN", prsw_ancien)
-
-  CALL put_field("UANCIEN", "UANCIEN", u_ancien)
-
-  CALL put_field("VANCIEN", "VANCIEN", v_ancien)
-
-  CALL put_field("CLWCON", "Eau liquide convective", clwcon)
-
-  CALL put_field("RNEBCON", "Nebulosite convective", rnebcon)
-
-  CALL put_field("RATQS", "Ratqs", ratqs)
-
-  ! run_off_lic_0
-
-  CALL put_field("RUNOFFLIC0", "Runofflic0", run_off_lic_0)
-
-  ! DEB TKE PBL !
-
-  IF (iflag_pbl>1) then
-    CALL put_field_srf3("TKE", "Energ. Cineti. Turb.", &
-         pbl_tke(:,:,:))
-    CALL put_field_srf3("DELTATKE", "Del TKE wk/env.", &
-         wake_delta_pbl_tke(:,:,:))
-  END IF
-
-  ! FIN TKE PBL !
-  !IM ajout zmax0, f0, sig1, w01
-  !IM wake_deltat, wake_deltaq, wake_s, wake_cstar, wake_pe, wake_fip
-
-  CALL put_field("ZMAX0", "ZMAX0", zmax0)
-
-  CALL put_field("F0", "F0", f0)
-
-  CALL put_field("sig1", "sig1 Emanuel", sig1)
-
-  CALL put_field("w01", "w01 Emanuel", w01)
-
-  ! wake_deltat
-  CALL put_field("WAKE_DELTAT", "WAKE_DELTAT", wake_deltat)
-
-  CALL put_field("WAKE_DELTAQ", "WAKE_DELTAQ", wake_deltaq)
-
-  CALL put_field("WAKE_S", "Wake frac. area", wake_s)
-
-  CALL put_field("WAKE_DENS", "Wake num. /unit area", wake_dens)
-
-  CALL put_field("WAKE_CSTAR", "WAKE_CSTAR", wake_cstar)
-
-  CALL put_field("WAKE_PE", "WAKE_PE", wake_pe)
-
-  CALL put_field("WAKE_FIP", "WAKE_FIP", wake_fip)
-
-  ! thermiques
-
-  CALL put_field("FM_THERM", "FM_THERM", fm_therm)
-
-  CALL put_field("ENTR_THERM", "ENTR_THERM", entr_therm)
-
-  CALL put_field("DETR_THERM", "DETR_THERM", detr_therm)
-
-  CALL put_field("ALE_BL", "ALE_BL", ale_bl)
-
-  CALL put_field("ALE_BL_TRIG", "ALE_BL_TRIG", ale_bl_trig)
-
-  CALL put_field("ALP_BL", "ALP_BL", alp_bl)
-
-  CALL put_field("ALE_WAKE", "ALE_WAKE", ale_wake)
-
-  CALL put_field("ALE_BL_STAT", "ALE_BL_STAT", ale_bl_stat)
-
-
-  ! trs from traclmdz_mod
-  IF (type_trac == 'lmdz') THEN
-     CALL traclmdz_to_restart(trs)
-     DO it=1, nbtr
+    CALL put_field(pass,"treedrg_ter","freinage arbres",treedrg(:,:,is_ter))
+
+
+    CALL put_field_srf1(pass,"QS"  , "Humidite",qsurf(:,:))
+
+    CALL put_field     (pass,"QSOL", "Eau dans le sol (mm)", qsol)
+
+    CALL put_field_srf1(pass,"EVAP", "Evaporation", fevap(:,:))
+
+    CALL put_field_srf1(pass,"SNOW", "Neige", snow(:,:))
+
+    CALL put_field(pass,"RADS", "Rayonnement net a la surface", radsol)
+
+    CALL put_field(pass,"solsw", "Rayonnement solaire a la surface", solsw)
+
+    CALL put_field(pass,"sollw", "Rayonnement IF a la surface", sollw)
+
+    CALL put_field(pass,"sollwdown", "Rayonnement down IF a la surface", sollwdown)
+
+    CALL put_field(pass,"fder", "Derive de flux", fder)
+
+    CALL put_field(pass,"rain_f", "precipitation liquide", rain_fall)
+
+    CALL put_field(pass,"snow_f", "precipitation solide", snow_fall)
+
+    CALL put_field_srf1(pass,"Z0m", "rugosite", z0m(:,:))
+
+    CALL put_field_srf1(pass,"Z0h", "rugosite", z0h(:,:))
+
+    CALL put_field_srf1(pass,"AGESNO", "Age de la neige", agesno(:,:))
+
+    CALL put_field(pass,"ZMEA", "ZMEA", zmea)
+
+    CALL put_field(pass,"ZSTD", "ZSTD", zstd)
+
+    CALL put_field(pass,"ZSIG", "ZSIG", zsig)
+
+    CALL put_field(pass,"ZGAM", "ZGAM", zgam)
+
+    CALL put_field(pass,"ZTHE", "ZTHE", zthe)
+
+    CALL put_field(pass,"ZPIC", "ZPIC", zpic)
+
+    CALL put_field(pass,"ZVAL", "ZVAL", zval)
+
+    CALL put_field(pass,"RUGSREL", "RUGSREL", rugoro)
+
+    CALL put_field(pass,"TANCIEN", "TANCIEN", t_ancien)
+
+    CALL put_field(pass,"QANCIEN", "QANCIEN", q_ancien)
+
+    CALL put_field(pass,"QLANCIEN", "QLANCIEN", ql_ancien)
+
+    CALL put_field(pass,"QSANCIEN", "QSANCIEN", qs_ancien)
+
+    CALL put_field(pass,"PRWANCIEN", "PRWANCIEN", prw_ancien)
+
+    CALL put_field(pass,"PRLWANCIEN", "PRLWANCIEN", prlw_ancien)
+
+    CALL put_field(pass,"PRSWANCIEN", "PRSWANCIEN", prsw_ancien)
+
+    CALL put_field(pass,"UANCIEN", "UANCIEN", u_ancien)
+
+    CALL put_field(pass,"VANCIEN", "VANCIEN", v_ancien)
+
+    CALL put_field(pass,"CLWCON", "Eau liquide convective", clwcon)
+
+    CALL put_field(pass,"RNEBCON", "Nebulosite convective", rnebcon)
+
+    CALL put_field(pass,"RATQS", "Ratqs", ratqs)
+
+    ! run_off_lic_0
+
+    CALL put_field(pass,"RUNOFFLIC0", "Runofflic0", run_off_lic_0)
+
+    ! DEB TKE PBL !
+
+    IF (iflag_pbl>1) then
+      CALL put_field_srf3(pass,"TKE", "Energ. Cineti. Turb.", &
+           pbl_tke(:,:,:))
+      CALL put_field_srf3(pass,"DELTATKE", "Del TKE wk/env.", &
+           wake_delta_pbl_tke(:,:,:))
+    END IF
+
+    ! FIN TKE PBL !
+    !IM ajout zmax0, f0, sig1, w01
+    !IM wake_deltat, wake_deltaq, wake_s, wake_cstar, wake_pe, wake_fip
+
+    CALL put_field(pass,"ZMAX0", "ZMAX0", zmax0)
+
+    CALL put_field(pass,"F0", "F0", f0)
+
+    CALL put_field(pass,"sig1", "sig1 Emanuel", sig1)
+
+    CALL put_field(pass,"w01", "w01 Emanuel", w01)
+
+    ! wake_deltat
+    CALL put_field(pass,"WAKE_DELTAT", "WAKE_DELTAT", wake_deltat)
+
+    CALL put_field(pass,"WAKE_DELTAQ", "WAKE_DELTAQ", wake_deltaq)
+
+    CALL put_field(pass,"WAKE_S", "Wake frac. area", wake_s)
+
+    CALL put_field(pass,"WAKE_DENS", "Wake num. /unit area", wake_dens)
+
+    CALL put_field(pass,"WAKE_CSTAR", "WAKE_CSTAR", wake_cstar)
+
+    CALL put_field(pass,"WAKE_PE", "WAKE_PE", wake_pe)
+
+    CALL put_field(pass,"WAKE_FIP", "WAKE_FIP", wake_fip)
+
+    ! thermiques
+
+    CALL put_field(pass,"FM_THERM", "FM_THERM", fm_therm)
+
+    CALL put_field(pass,"ENTR_THERM", "ENTR_THERM", entr_therm)
+
+    CALL put_field(pass,"DETR_THERM", "DETR_THERM", detr_therm)
+
+    CALL put_field(pass,"ALE_BL", "ALE_BL", ale_bl)
+
+    CALL put_field(pass,"ALE_BL_TRIG", "ALE_BL_TRIG", ale_bl_trig)
+
+    CALL put_field(pass,"ALP_BL", "ALP_BL", alp_bl)
+
+    CALL put_field(pass,"ALE_WAKE", "ALE_WAKE", ale_wake)
+
+    CALL put_field(pass,"ALE_BL_STAT", "ALE_BL_STAT", ale_bl_stat)
+
+
+    ! trs from traclmdz_mod
+    IF (type_trac == 'lmdz') THEN
+       CALL traclmdz_to_restart(trs)
+       DO it=1, nbtr
 !!        iiq=niadv(it+2)                                                           ! jyg
-        iiq=niadv(it+nqo)                                                           ! jyg
-        CALL put_field("trs_"//tname(iiq), "", trs(:, it))
-     END DO
-     IF (carbon_cycle_cpl) THEN
-        IF (.NOT. ALLOCATED(co2_send)) THEN
-           ! This is the case of create_etat0_limit, ce0l
-           ALLOCATE(co2_send(klon))
-           co2_send(:) = co2_ppm0
+          iiq=niadv(it+nqo)                                                           ! jyg
+          CALL put_field(pass,"trs_"//tname(iiq), "", trs(:, it))
+       END DO
+       IF (carbon_cycle_cpl) THEN
+          IF (.NOT. ALLOCATED(co2_send)) THEN
+             ! This is the case of create_etat0_limit, ce0l
+             ALLOCATE(co2_send(klon))
+             co2_send(:) = co2_ppm0
+          END IF
+          CALL put_field(pass,"co2_send", "co2_ppm for coupling", co2_send)
+       END IF
+    END IF
+
+    ! Restart variables for Slab ocean
+    IF (type_ocean == 'slab') THEN
+        IF (nslay.EQ.1) THEN
+          CALL put_field(pass,"tslab", "Slab ocean temperature", tslab)
+        ELSE
+          DO it=1,nslay
+            WRITE(str2,'(i2.2)') it
+            CALL put_field(pass,"tslab"//str2, "Slab ocean temperature", tslab(:,it))
+          END DO
         END IF
-        CALL put_field("co2_send", "co2_ppm for coupling", co2_send)
-     END IF
-  END IF
-
-  ! Restart variables for Slab ocean
-  IF (type_ocean == 'slab') THEN
-      IF (nslay.EQ.1) THEN
-        CALL put_field("tslab", "Slab ocean temperature", tslab)
-      ELSE
-        DO it=1,nslay
-          WRITE(str2,'(i2.2)') it
-          CALL put_field("tslab"//str2, "Slab ocean temperature", tslab(:,it))
-        END DO
-      END IF
-      IF (version_ocean == 'sicINT') THEN
-          CALL put_field("seaice", "Slab seaice (kg/m2)", seaice)
-          CALL put_field("slab_tice", "Slab sea ice temperature", tice)
-      END IF
-  END IF
-
-  if (ok_gwd_rando) call put_field("du_gwd_rando", &
-       "tendency on zonal wind due to flott gravity waves", du_gwd_rando)
-
-  IF (.not. ok_hines .and. ok_gwd_rando) call put_field("du_gwd_front", &
-       "tendency on zonal wind due to acama gravity waves", du_gwd_front)
-
-  CALL close_restartphy
+        IF (version_ocean == 'sicINT') THEN
+            CALL put_field(pass,"seaice", "Slab seaice (kg/m2)", seaice)
+            CALL put_field(pass,"slab_tice", "Slab sea ice temperature", tice)
+        END IF
+    END IF
+
+    if (ok_gwd_rando) call put_field(pass,"du_gwd_rando", &
+         "tendency on zonal wind due to flott gravity waves", du_gwd_rando)
+
+    IF (.not. ok_hines .and. ok_gwd_rando) call put_field(pass,"du_gwd_front", &
+         "tendency on zonal wind due to acama gravity waves", du_gwd_front)
+
+    IF (pass==1) CALL enddef_restartphy
+    IF (pass==2) CALL close_restartphy
+  ENDDO
+  
   !$OMP BARRIER
 
@@ -344,7 +350,8 @@
 
 
-SUBROUTINE put_field_srf1(nam,lnam,field)
+SUBROUTINE put_field_srf1(pass,nam,lnam,field)
 
   IMPLICIT NONE
+  INTEGER, INTENT(IN)            :: pass
   CHARACTER(LEN=*),  INTENT(IN) :: nam, lnam
   REAL,              INTENT(IN) :: field(:,:)
@@ -354,5 +361,5 @@
     nm=TRIM(nam)//TRIM(str)
     lm=TRIM(lnam)//" de surface No. "//TRIM(str)
-    CALL put_field(nm,lm,field(:,nsrf))
+    CALL put_field(pass,nm,lm,field(:,nsrf))
   END DO
 
@@ -360,7 +367,8 @@
 
 
-SUBROUTINE put_field_srf2(nam,lnam,field)
+SUBROUTINE put_field_srf2(pass,nam,lnam,field)
 
   IMPLICIT NONE
+  INTEGER, INTENT(IN)            :: pass
   CHARACTER(LEN=*),  INTENT(IN) :: nam, lnam
   REAL,              INTENT(IN) :: field(:,:,:)
@@ -372,5 +380,5 @@
       nm=TRIM(nam)//TRIM(str)
       lm=TRIM(lnam)//" du sol No. "//TRIM(str)
-      CALL put_field(nm,lm,field(:,isoil,nsrf))
+      CALL put_field(pass,nm,lm,field(:,isoil,nsrf))
     END DO
   END DO
@@ -379,7 +387,8 @@
 
 
-SUBROUTINE put_field_srf3(nam,lnam,field)
+SUBROUTINE put_field_srf3(pass,nam,lnam,field)
 
   IMPLICIT NONE
+  INTEGER, INTENT(IN)            :: pass
   CHARACTER(LEN=*),  INTENT(IN) :: nam, lnam
   REAL,              INTENT(IN) :: field(:,:,:)
@@ -389,5 +398,5 @@
     nm=TRIM(nam)//TRIM(str)
     lm=TRIM(lnam)//TRIM(str)
-    CALL put_field(nm,lm,field(:,1:klev+1,nsrf))
+    CALL put_field(pass,nm,lm,field(:,1:klev+1,nsrf))
   END DO
 
