Index: LMDZ5/trunk/libf/phylmd/iophy.F90
===================================================================
--- LMDZ5/trunk/libf/phylmd/iophy.F90	(revision 1821)
+++ LMDZ5/trunk/libf/phylmd/iophy.F90	(revision 1825)
@@ -5,4 +5,8 @@
 
   USE phys_output_var_mod
+
+#ifdef CPP_XIOS
+  USE wxios
+#endif
 
 ! abd  REAL,private,allocatable,DIMENSION(:),save :: io_lat
@@ -22,5 +26,5 @@
 
   INTERFACE histbeg_phy_all
-    MODULE PROCEDURE histbeg_phy,histbeg_phy_points
+    MODULE PROCEDURE histbeg_phy,histbeg_phyxios,histbeg_phy_points
   END INTERFACE
 
@@ -40,4 +44,5 @@
   USE mod_grid_phy_lmdz
   USE ioipsl
+  
   IMPLICIT NONE
   INCLUDE 'dimensions.h'   
@@ -89,5 +94,8 @@
     CALL flio_dom_set(mpi_size,mpi_rank,ddid,dsg,dsl,dpf,dpl,dhs,dhe, &
                       'APPLE',phys_domain_id)
-
+#ifdef CPP_XIOS
+    !On initialise le domaine xios, maintenant que tout est connu:
+    CALL wxios_domain_param("dom_glo", is_sequential, iim, jjm+1, io_lat, io_lon)
+#endif
 !$OMP END MASTER
       
@@ -135,4 +143,41 @@
       
   end SUBROUTINE init_iophy
+
+ SUBROUTINE histbeg_phyxios(name,itau0,zjulian,dtime,ffreq,lev,nhori,nid_day)
+  USE dimphy
+  USE mod_phys_lmdz_para
+  use ioipsl
+  use write_field
+  IMPLICIT NONE
+  include 'dimensions.h'
+    
+    character*(*), INTENT(IN) :: name
+    integer, INTENT(IN) :: itau0
+    REAL,INTENT(IN) :: zjulian
+    REAL,INTENT(IN) :: dtime
+    character(LEN=*), INTENT(IN) :: ffreq
+    INTEGER,INTENT(IN) :: lev
+    integer,intent(out) :: nhori
+    integer,intent(out) :: nid_day
+
+!$OMP MASTER    
+    if (is_sequential) then
+      call histbeg(name,iim,io_lon, jj_nb,io_lat(jj_begin:jj_end), &
+                   1,iim,1,jj_nb,itau0, zjulian, dtime, nhori, nid_day)
+    else
+      call histbeg(name,iim,io_lon, jj_nb,io_lat(jj_begin:jj_end), &
+                   1,iim,1,jj_nb,itau0, zjulian, dtime, nhori, nid_day,phys_domain_id)
+    endif
+
+#ifdef CPP_XIOS
+    ! ug OMP en chantier...
+    IF((.NOT. is_using_mpi) .OR. is_mpi_root) THEN
+        ! ug Création du fichier
+        CALL wxios_add_file(name, ffreq, lev)
+    END IF
+#endif
+!$OMP END MASTER
+  
+  END SUBROUTINE histbeg_phyxios
   
   SUBROUTINE histbeg_phy(name,itau0,zjulian,dtime,nhori,nid_day)
@@ -159,7 +204,9 @@
                    1,iim,1,jj_nb,itau0, zjulian, dtime, nhori, nid_day,phys_domain_id)
     endif
+
 !$OMP END MASTER
   
   END SUBROUTINE histbeg_phy
+
 
   SUBROUTINE histbeg_phy_points(rlon,rlat,pim,tabij,ipt,jpt, &
@@ -487,4 +534,9 @@
 
     IF(.NOT.clef_stations(iff)) THEN  
+#ifdef CPP_XIOS
+        CALL wxios_add_field_to_file(var%name, 2, nid_files(iff), phys_out_filenames(iff), &
+        var%description, var%unit, var%flag(iff), typeecrit)
+#endif
+
        IF ( var%flag(iff)<=lev_files(iff) ) THEN
           CALL histdef (nid_files(iff), var%name, var%description, var%unit, &
@@ -550,4 +602,9 @@
 
     IF(.NOT.clef_stations(iff)) THEN
+#ifdef CPP_XIOS
+        CALL wxios_add_field_to_file(var%name, 3, nid_files(iff), phys_out_filenames(iff), &
+        var%description, var%unit, var%flag(iff), typeecrit)
+#endif
+
        IF ( var%flag(iff)<=lev_files(iff) ) THEN
           CALL histdef (nid_files(iff), var%name, var%description, var%unit, &
@@ -734,6 +791,7 @@
 
 #ifdef CPP_XIOS
-!  USE WXIOS
+  USE wxios
 #endif
+
 
   IMPLICIT NONE
@@ -794,7 +852,7 @@
                         CALL histwrite(nid_files(iff),var%name,itau_iophy,Field2d,iim*jj_nb,index2d)
 #ifdef CPP_XIOS
-!                        IF (iff .EQ. 1) THEN
-!                              CALL wxios_write_2D(var%name, Field2d)
-!                        ENDIF
+                        IF (iff == iff_beg) THEN
+                              CALL wxios_write_2D(var%name, Field2d)
+                        ENDIF
 #endif
                   ELSE 
@@ -887,8 +945,9 @@
                         ALLOCATE(fieldok(iim*jj_nb,nlev))
                         CALL histwrite(nid_files(iff),var%name,itau_iophy,Field3d,iim*jj_nb*nlev,index3d)
+
 #ifdef CPP_XIOS
-!                        IF (iff .EQ. 1) THEN
-!                              CALL wxios_write_3D(var%name, Field3d(:,:,1:klev))
-!                        ENDIF
+                        IF (iff == 1) THEN
+                              CALL wxios_write_3D(var%name, Field3d(:,:,1:klev))
+                        ENDIF
 #endif
                         
