Index: LMDZ6/trunk/libf/dyn3d/abort_gcm.F
===================================================================
--- LMDZ6/trunk/libf/dyn3d/abort_gcm.F	(revision 4618)
+++ LMDZ6/trunk/libf/dyn3d/abort_gcm.F	(revision 4619)
@@ -12,9 +12,6 @@
       USE ioipsl_getincom
 #endif
-
-#ifdef CPP_XIOS
-    ! ug Pour les sorties XIOS
+ ! ug Pour les sorties XIOS
       USE wxios
-#endif
 
 #include "iniprint.h"
@@ -34,8 +31,8 @@
       write(lunout,*) 'in abort_gcm'
 
-#ifdef CPP_XIOS
-    !Fermeture propre de XIOS
-      CALL wxios_close()
-#endif
+      IF (using_xios) THEN
+!Fermeture propre de XIOS
+        CALL wxios_close()
+      ENDIF
 
 #ifdef CPP_IOIPSL
Index: LMDZ6/trunk/libf/dyn3d/gcm.F90
===================================================================
--- LMDZ6/trunk/libf/dyn3d/gcm.F90	(revision 4618)
+++ LMDZ6/trunk/libf/dyn3d/gcm.F90	(revision 4619)
@@ -14,8 +14,6 @@
 
 
-#ifdef CPP_XIOS
-  ! ug Pour les sorties XIOS
+! ug Pour les sorties XIOS
   USE wxios
-#endif
 
   USE filtreg_mod
@@ -156,7 +154,7 @@
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
-#ifdef CPP_XIOS
-  CALL wxios_init("LMDZ")
-#endif
+  IF (using_xios) THEN
+    CALL wxios_init("LMDZ")
+  ENDIF
 
 
Index: LMDZ6/trunk/libf/dyn3dmem/gcm.F90
===================================================================
--- LMDZ6/trunk/libf/dyn3dmem/gcm.F90	(revision 4618)
+++ LMDZ6/trunk/libf/dyn3dmem/gcm.F90	(revision 4619)
@@ -28,7 +28,5 @@
                        itau_dyn,itau_phy,day_ini,jD_ref,jH_ref,day_end, &
                        dt,hour_ini,itaufin
-#ifdef CPP_XIOS
   USE mod_xios_dyn3dmem, ONLY: xios_dyn3dmem_init
-#endif
 
   IMPLICIT NONE
@@ -457,10 +455,8 @@
 
 ! setting up DYN3D/XIOS inerface
-#ifdef CPP_XIOS
-   if (ok_dyn_xios) then
-     CALL xios_dyn3dmem_init(xios_cal_type, anref, moisref, jourref,heureref, an,   &
+  if (ok_dyn_xios) then
+      CALL xios_dyn3dmem_init(xios_cal_type, anref, moisref, jourref,heureref, an,   &
           mois, jour, heure, zdtvr)
   endif
-#endif
 
   ! #endif of #ifdef CPP_IOIPSL
Index: LMDZ6/trunk/libf/dyn3dmem/leapfrog_loc.F
===================================================================
--- LMDZ6/trunk/libf/dyn3dmem/leapfrog_loc.F	(revision 4618)
+++ LMDZ6/trunk/libf/dyn3dmem/leapfrog_loc.F	(revision 4619)
@@ -42,8 +42,8 @@
        USE temps_mod, ONLY: itaufin,jD_ref,jH_ref,day_ini,
      &                        day_ref,start_time,dt
-#ifdef CPP_XIOS
        USE mod_xios_dyn3dmem, ONLY : dyn3d_ctx_handle
-       USE xios, ONLY: xios_update_calendar, xios_set_current_context
-#endif
+       USE lmdz_xios, ONLY: xios_update_calendar, 
+     &                      xios_set_current_context, 
+     &                      using_xios
        
       IMPLICIT NONE
@@ -1523,5 +1523,4 @@
             CALL finalize_inca
 !     switching back to LMDZDYN context
-#ifdef CPP_XIOS
 !$OMP MASTER
             IF (ok_dyn_xios) THEN
@@ -1529,5 +1528,4 @@
             ENDIF
 !$OMP END MASTER
-#endif
          ENDIF
 #endif
@@ -1582,5 +1580,4 @@
                  CALL finalize_inca
 !     switching back to LMDZDYN context
-#ifdef CPP_XIOS
 !$OMP MASTER
                  IF (ok_dyn_xios) THEN
@@ -1588,5 +1585,4 @@
                  ENDIF
 !$OMP END MASTER
-#endif
               ENDIF
 #endif
@@ -1661,5 +1657,4 @@
 #endif
              
-#ifdef CPP_XIOS
               IF (ok_dyn_xios) THEN
 c$OMP MASTER
@@ -1670,5 +1665,4 @@
      &                 ucov,teta,pk,phi,q,masse,ps,phis)
               ENDIF
-#endif
               
           endif                 ! of if (leapf.or.(.not.leapf.and.(.not.forward)))
@@ -1759,5 +1753,4 @@
                     CALL finalize_inca
 !     switching back to LMDZDYN context
-#ifdef CPP_XIOS
 !$OMP MASTER
                     IF (ok_dyn_xios) THEN
@@ -1765,5 +1758,4 @@
                     ENDIF
 !$OMP END MASTER
-#endif
                  ENDIF
 
@@ -1833,5 +1825,4 @@
 #endif
 
-#ifdef CPP_XIOS
               IF (ok_dyn_xios) THEN
 c$OMP MASTER
@@ -1842,5 +1833,4 @@
      &                 ucov,teta,pk,phi,q,masse,ps,phis)
               ENDIF
-#endif
               
            ENDIF                ! of IF(MOD(itau,iecri).EQ.0)
@@ -1877,5 +1867,4 @@
          CALL finalize_inca
 !     switching back to LMDZDYN context
-#ifdef CPP_XIOS
 !$OMP MASTER
          IF (ok_dyn_xios) THEN
@@ -1883,5 +1872,4 @@
          ENDIF
 !$OMP END MASTER
-#endif
       ENDIF
 
Index: LMDZ6/trunk/libf/dyn3dmem/mod_const_mpi.F90
===================================================================
--- LMDZ6/trunk/libf/dyn3dmem/mod_const_mpi.F90	(revision 4618)
+++ LMDZ6/trunk/libf/dyn3dmem/mod_const_mpi.F90	(revision 4619)
@@ -23,7 +23,5 @@
     USE mod_prism
 #endif
-#ifdef CPP_XIOS
     USE wxios, only: wxios_init
-#endif
     IMPLICIT NONE
 
@@ -44,10 +42,10 @@
 #ifdef CPP_COUPLE
 !$OMP MASTER
-#ifdef CPP_XIOS
-        CALL wxios_init("LMDZ", outcom=COMM_LMDZ, type_ocean=type_ocean)
-#else
-        CALL prism_init_comp_proto (comp_id, 'LMDZ', ierr)
-        CALL prism_get_localcomm_proto(COMM_LMDZ,ierr)
-#endif
+        IF (using_xios) THEN
+          CALL wxios_init("LMDZ", outcom=COMM_LMDZ, type_ocean=type_ocean)
+        ELSE
+          CALL prism_init_comp_proto (comp_id, 'LMDZ', ierr)
+          CALL prism_get_localcomm_proto(COMM_LMDZ,ierr)
+        ENDIF
 !$OMP END MASTER
 #endif
@@ -61,8 +59,6 @@
   SUBROUTINE Init_mpi
     USE lmdz_mpi
+    USE wxios, only: wxios_init, using_xios
 
-#ifdef CPP_XIOS
-    USE wxios, only: wxios_init
-#endif
   IMPLICIT NONE
     INTEGER             :: ierr
@@ -83,8 +79,8 @@
 ! Initialisation de XIOS
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-#ifdef CPP_XIOS
-      WRITE(*,*)'IN Init_mpi call wxios_init'
-      CALL wxios_init("LMDZ", outcom=COMM_LMDZ)
-#endif
+      IF (using_xios) THEN
+        WRITE(*,*)'IN Init_mpi call wxios_init'
+        CALL wxios_init("LMDZ", outcom=COMM_LMDZ)
+      ENDIF
 !$OMP END MASTER
 
Index: LMDZ6/trunk/libf/dyn3dmem/mod_xios_dyn3dmem.F90
===================================================================
--- LMDZ6/trunk/libf/dyn3dmem/mod_xios_dyn3dmem.F90	(revision 4618)
+++ LMDZ6/trunk/libf/dyn3dmem/mod_xios_dyn3dmem.F90	(revision 4619)
@@ -12,9 +12,8 @@
 !
 !
-#ifdef CPP_XIOS
 
 MODULE mod_xios_dyn3dmem
 
-     USE xios
+     USE lmdz_xios
      USE wxios, ONLY : g_comm
      CHARACTER(len=100), SAVE :: dyn3d_ctx_name = "LMDZDYN"
@@ -259,4 +258,3 @@
    
 END MODULE mod_xios_dyn3dmem 
-#endif
-
+
Index: LMDZ6/trunk/libf/dyn3dmem/parallel_lmdz.F90
===================================================================
--- LMDZ6/trunk/libf/dyn3dmem/parallel_lmdz.F90	(revision 4618)
+++ LMDZ6/trunk/libf/dyn3dmem/parallel_lmdz.F90	(revision 4619)
@@ -384,8 +384,7 @@
     subroutine Finalize_parallel
     USE lmdz_mpi
-#ifdef CPP_XIOS
     ! ug Pour les sorties XIOS
-	USE wxios
-#endif
+  	USE wxios
+
 #ifdef CPP_COUPLE
 ! Use of Oasis-MCT coupler 
@@ -416,21 +415,21 @@
 
       if (type_ocean == 'couple') then
-#ifdef CPP_XIOS
-    !Fermeture propre de XIOS
-      CALL wxios_close()
-#else
+        IF (using_xios) THEN
+          !Fermeture propre de XIOS
+          CALL wxios_close()
+        ELSE
 #ifdef CPP_COUPLE
-         call prism_terminate_proto(ierr)
-         IF (ierr .ne. PRISM_Ok) THEN
-            call abort_gcm('Finalize_parallel',' Probleme dans prism_terminate_proto ',1)
-         endif
+           call prism_terminate_proto(ierr)
+           IF (ierr .ne. PRISM_Ok) THEN
+              call abort_gcm('Finalize_parallel',' Probleme dans prism_terminate_proto ',1)
+           endif
 #endif 
-#endif
+        ENDIF
       else
-#ifdef CPP_XIOS
-    !Fermeture propre de XIOS
-      CALL wxios_close()
-#endif
-      IF (using_mpi) call MPI_FINALIZE(ierr)
+        IF (using_xios) THEN
+          !Fermeture propre de XIOS
+          CALL wxios_close()
+        ENDIF
+        IF (using_mpi) call MPI_FINALIZE(ierr)
       end if
       
Index: LMDZ6/trunk/libf/dyn3dmem/writedyn_xios.F90
===================================================================
--- LMDZ6/trunk/libf/dyn3dmem/writedyn_xios.F90	(revision 4618)
+++ LMDZ6/trunk/libf/dyn3dmem/writedyn_xios.F90	(revision 4619)
@@ -5,6 +5,5 @@
      &                           masse,ps,phis)
 
-#ifdef CPP_XIOS
-      USE xios
+      USE lmdz_xios
       USE parallel_lmdz
       USE misc_mod
@@ -180,5 +179,3 @@
       CALL writefield_dyn_u('PS', ps(ijb:ije))
 
-#endif
-
       END
Index: LMDZ6/trunk/libf/dynphy_lonlat/phylmd/callphysiq_mod.F90
===================================================================
--- LMDZ6/trunk/libf/dynphy_lonlat/phylmd/callphysiq_mod.F90	(revision 4618)
+++ LMDZ6/trunk/libf/dynphy_lonlat/phylmd/callphysiq_mod.F90	(revision 4619)
@@ -22,8 +22,5 @@
   USE control_mod, ONLY: planet_type, ok_dyn_xios
   USE physiq_mod, ONLY: physiq
-#ifdef CPP_XIOS
-  USE mod_xios_dyn3dmem, ONLY : dyn3d_ctx_handle
-  USE xios, ONLY : xios_set_current_context
-#endif
+  USE lmdz_xios, ONLY : xios_set_current_context, xios_get_current_context, xios_context
   IMPLICIT NONE
 
@@ -56,5 +53,6 @@
   REAL,INTENT(OUT) :: zdqfi_omp(klon,llm,nqtot) ! tendency on tracers
   REAL,INTENT(OUT) :: zdpsrf_omp(klon) ! tendency on surface pressure
-  
+  TYPE(xios_context) :: dyn3d_ctx_handle
+
   ! Local variables
   CHARACTER(len=11) :: modname="call_physiq"
@@ -70,4 +68,9 @@
   ENDIF
 
+  !$OMP MASTER
+  if (ok_dyn_xios) then
+     CALL xios_get_current_context(dyn3d_ctx_handle)
+  endif
+  !$OMP END MASTER
 
 ! Call physics package with required inputs/outputs
@@ -95,5 +98,4 @@
 
 ! switching back to LMDZDYN context
-#ifdef CPP_XIOS
 !$OMP MASTER
   if (ok_dyn_xios) then
@@ -101,5 +103,4 @@
   endif
 !$OMP END MASTER
-#endif  
 
 
Index: LMDZ6/trunk/libf/dynphy_lonlat/phylmd/ce0l.F90
===================================================================
--- LMDZ6/trunk/libf/dynphy_lonlat/phylmd/ce0l.F90	(revision 4618)
+++ LMDZ6/trunk/libf/dynphy_lonlat/phylmd/ce0l.F90	(revision 4619)
@@ -36,7 +36,5 @@
   USE mod_hallo,      ONLY: init_mod_hallo
   USE mod_interface_dyn_phys, ONLY: init_interface_dyn_phys
-#ifdef CPP_XIOS
-  USE xios, only: xios_finalize
-#endif
+  USE lmdz_xios, only: xios_finalize
 #endif
 
@@ -250,7 +248,5 @@
 #ifdef CPP_PARA
   END IF
-#ifdef CPP_XIOS
-  CALL xios_finalize
-#endif
+  IF (using_xios) CALL xios_finalize
   IF (using_mpi) call MPI_FINALIZE(ierr)
 #endif
Index: LMDZ6/trunk/libf/misc/lmdz_xios.F90
===================================================================
--- LMDZ6/trunk/libf/misc/lmdz_xios.F90	(revision 4619)
+++ LMDZ6/trunk/libf/misc/lmdz_xios.F90	(revision 4619)
@@ -0,0 +1,1213 @@
+#ifdef CPP_XIOS
+
+MODULE lmdz_xios
+  USE xios
+  
+  LOGICAL,PARAMETER :: using_xios = .TRUE.
+
+END MODULE lmdz_xios
+
+#else
+
+MODULE lmdz_xios
+  !!!! Wrapper XIOS
+  !! => must be replaced latter by official xios wrapper when available
+
+  LOGICAL,PARAMETER :: using_xios = .FALSE.
+
+INTERFACE xios_send_field
+  MODULE PROCEDURE xios_send_field_scalar, xios_send_field_1d, xios_send_field_2d, xios_send_field_3d, &
+                   xios_send_field_4d, xios_send_field_5d
+END INTERFACE  xios_send_field
+
+INTERFACE xios_recv_field
+  MODULE PROCEDURE xios_recv_field_scalar, xios_recv_field_1d, xios_recv_field_2d, xios_recv_field_3d, &
+                   xios_recv_field_4d
+END INTERFACE  xios_recv_field
+
+INTERFACE xios_field_is_active
+  MODULE PROCEDURE xios_field_is_active_id,xios_field_is_active_hdl
+END INTERFACE xios_field_is_active
+
+INTERFACE xios_set_attr
+  MODULE PROCEDURE xios_set_fieldgroup_attr_hdl, xios_set_field_attr_hdl, xios_set_domain_attr_hdl, &
+                   xios_set_axis_attr_hdl, xios_set_file_attr_hdl
+END INTERFACE  xios_set_attr
+
+INTERFACE xios_get_handle
+  MODULE PROCEDURE  xios_get_context_handle, xios_get_field_handle, xios_get_fieldgroup_handle, &
+                    xios_get_domain_handle,xios_get_file_handle, xios_get_filegroup_handle 
+END INTERFACE  xios_get_handle
+
+INTERFACE xios_add_child
+  MODULE PROCEDURE xios_fieldgroup_add_child, xios_add_fieldtofile, xios_add_file
+END INTERFACE  xios_add_child
+
+INTERFACE xios_set_current_context
+      MODULE PROCEDURE xios_set_current_context_hdl, xios_set_current_context_id
+END INTERFACE xios_set_current_context
+
+INTERFACE xios_get_current_context
+      MODULE PROCEDURE xios_get_current_context_hdl, xios_get_current_context_id
+END INTERFACE xios_get_current_context
+
+INTERFACE xios_set_start_date
+  MODULE PROCEDURE xios_set_start_date_date, xios_set_start_date_dur
+END INTERFACE xios_set_start_date
+
+INTERFACE xios_set_time_origin
+  MODULE PROCEDURE xios_set_time_origin_date, xios_set_time_origin_dur
+END INTERFACE xios_set_time_origin
+
+INTERFACE xios_is_defined_attr
+  MODULE PROCEDURE xios_is_defined_domain_attr_hdl
+END INTERFACE xios_is_defined_attr
+
+TYPE xios_duration
+  DOUBLE PRECISION :: year=0, month=0, day=0, hour=0, minute=0, second=0, timestep=0
+END TYPE xios_duration
+
+TYPE xios_date
+  INTEGER :: year=0, month=0, day=0, hour=0, minute=0, second=0
+END TYPE xios_date
+
+   
+REAL,PARAMETER :: xios_timestep=1.
+REAL,PARAMETER :: xios_second=1.
+
+TYPE xios_fieldgroup
+END TYPE xios_fieldgroup
+
+TYPE xios_filegroup
+END TYPE xios_filegroup
+
+TYPE xios_context
+END TYPE xios_context
+
+TYPE xios_domain
+END TYPE xios_domain
+
+TYPE xios_axis
+END TYPE xios_axis
+
+TYPE xios_file
+END TYPE xios_file
+
+TYPE xios_field
+END TYPE 
+
+
+CONTAINS  
+  
+  
+  SUBROUTINE  xios_initialize(client_id, local_comm, return_comm)
+   IMPLICIT NONE
+   CHARACTER(LEN=*),INTENT(IN) :: client_id
+   INTEGER,INTENT(IN),OPTIONAL         :: local_comm
+   INTEGER,INTENT(OUT),OPTIONAL        :: return_comm
+   INTEGER :: f_local_comm
+   INTEGER :: f_return_comm
+
+  END SUBROUTINE  xios_initialize 
+
+SUBROUTINE xios_define_calendar(type, timestep, start_date, time_origin, &
+                                    day_length, month_lengths, year_length, &
+                                    leap_year_month, leap_year_drift, leap_year_drift_offset)
+      IMPLICIT NONE
+      CHARACTER(len = *),              INTENT(IN) :: type
+      TYPE(xios_duration), OPTIONAL, INTENT(IN) :: timestep
+      TYPE(xios_date),     OPTIONAL, INTENT(IN) :: start_date
+      TYPE(xios_date),     OPTIONAL, INTENT(IN) :: time_origin
+      INTEGER,               OPTIONAL, INTENT(IN) :: day_length
+      INTEGER,               OPTIONAL, INTENT(IN) :: month_lengths(:)
+      INTEGER,               OPTIONAL, INTENT(IN) :: year_length
+      REAL (KIND=8),         OPTIONAL, INTENT(IN) :: leap_year_drift
+      REAL (KIND=8),         OPTIONAL, INTENT(IN) :: leap_year_drift_offset
+      INTEGER,               OPTIONAL, INTENT(IN) :: leap_year_month
+
+   END SUBROUTINE xios_define_calendar
+   
+  SUBROUTINE xios_duration_convert_to_string(dur, str)
+    IMPLICIT NONE
+    TYPE(xios_duration), INTENT(IN) :: dur
+    CHARACTER(len = *), INTENT(OUT) :: str
+    str=''
+  END SUBROUTINE xios_duration_convert_to_string
+
+  FUNCTION xios_duration_convert_from_string(str) RESULT(res)
+    IMPLICIT NONE
+    CHARACTER(len = *), INTENT(IN) :: str
+    TYPE(xios_duration) :: res
+
+  END FUNCTION xios_duration_convert_from_string
+
+   SUBROUTINE xios_set_timestep(timestep)
+      IMPLICIT NONE
+      TYPE(xios_duration), INTENT(IN) :: timestep
+   END SUBROUTINE xios_set_timestep
+   
+  SUBROUTINE xios_set_start_date_date(start_date)
+      IMPLICIT NONE
+      TYPE(xios_date), INTENT(IN) :: start_date
+   END SUBROUTINE xios_set_start_date_date
+
+   SUBROUTINE xios_set_start_date_dur(start_date)
+      IMPLICIT NONE
+      TYPE(xios_duration), INTENT(IN) :: start_date
+   END SUBROUTINE xios_set_start_date_dur
+   
+   SUBROUTINE xios_set_time_origin_date(time_origin)
+      IMPLICIT NONE
+      TYPE(xios_date), INTENT(IN) :: time_origin
+   END SUBROUTINE xios_set_time_origin_date
+
+   SUBROUTINE xios_set_time_origin_dur(time_origin)
+      IMPLICIT NONE
+      TYPE(xios_duration), INTENT(IN) :: time_origin
+   END SUBROUTINE xios_set_time_origin_dur
+            
+  SUBROUTINE xios_send_field_scalar(name,field)
+  IMPLICIT NONE
+    CHARACTER(LEN=*),INTENT(IN) :: name
+    REAL,INTENT(IN) :: field
+  END SUBROUTINE xios_send_field_scalar  
+
+  SUBROUTINE xios_send_field_1d(name,field)
+  IMPLICIT NONE
+    CHARACTER(LEN=*),INTENT(IN) :: name
+    REAL,INTENT(IN) :: field(:)
+  END SUBROUTINE xios_send_field_1d  
+
+  SUBROUTINE xios_send_field_2d(name,field)
+  IMPLICIT NONE
+    CHARACTER(LEN=*),INTENT(IN) :: name
+    REAL,INTENT(IN) :: field(:,:)
+  END SUBROUTINE xios_send_field_2d  
+
+  SUBROUTINE xios_send_field_3d(name,field)
+  IMPLICIT NONE
+    CHARACTER(LEN=*),INTENT(IN) :: name
+    REAL,INTENT(IN) :: field(:,:,:)
+  END SUBROUTINE xios_send_field_3d  
+
+  SUBROUTINE xios_send_field_4d(name,field)
+  IMPLICIT NONE
+    CHARACTER(LEN=*),INTENT(IN) :: name
+    REAL,INTENT(IN) :: field(:,:,:,:)
+  END SUBROUTINE xios_send_field_4d  
+
+  SUBROUTINE xios_send_field_5d(name,field)
+  IMPLICIT NONE
+    CHARACTER(LEN=*),INTENT(IN) :: name
+    REAL,INTENT(IN) :: field(:,:,:,:,:)
+  END SUBROUTINE xios_send_field_5d  
+
+
+  SUBROUTINE xios_recv_field_scalar(name,field)
+  IMPLICIT NONE
+    CHARACTER(LEN=*),INTENT(IN) :: name
+    REAL,INTENT(OUT) :: field
+    field=0
+  END SUBROUTINE xios_recv_field_scalar  
+
+  SUBROUTINE xios_recv_field_1d(name,field)
+  IMPLICIT NONE
+    CHARACTER(LEN=*),INTENT(IN) :: name
+    REAL,INTENT(OUT) :: field(:)
+    field=0
+  END SUBROUTINE xios_recv_field_1d  
+
+  SUBROUTINE xios_recv_field_2d(name,field)
+  IMPLICIT NONE
+    CHARACTER(LEN=*),INTENT(IN) :: name
+    REAL,INTENT(OUT) :: field(:,:)
+    field=0
+  END SUBROUTINE xios_recv_field_2d  
+
+  SUBROUTINE xios_recv_field_3d(name,field)
+  IMPLICIT NONE
+    CHARACTER(LEN=*),INTENT(IN) :: name
+    REAL,INTENT(OUT) :: field(:,:,:)
+    field=0
+  END SUBROUTINE xios_recv_field_3d  
+
+  SUBROUTINE xios_recv_field_4d(name,field)
+  IMPLICIT NONE
+    CHARACTER(LEN=*),INTENT(IN) :: name
+    REAL,INTENT(OUT) :: field(:,:,:,:)
+    field=0
+  END SUBROUTINE xios_recv_field_4d  
+
+
+  FUNCTION xios_is_active_field(field_id)
+  IMPLICIT NONE
+   LOGICAL ::  xios_is_active_field
+   CHARACTER(LEN=*) :: field_id
+    xios_is_active_field = .TRUE.
+  END FUNCTION xios_is_active_field
+
+  LOGICAL FUNCTION xios_is_valid_field(idt)
+    IMPLICIT NONE
+    CHARACTER(len  = *)    , INTENT(IN) :: idt
+    xios_is_valid_field = .FALSE.
+  END FUNCTION  xios_is_valid_field
+
+  LOGICAL FUNCTION xios_is_valid_file(idt)
+    IMPLICIT NONE
+    CHARACTER(len  = *)    , INTENT(IN) :: idt
+    xios_is_valid_file = .FALSE.
+  END FUNCTION  xios_is_valid_file
+
+  LOGICAL FUNCTION xios_is_valid_axis(idt)
+    IMPLICIT NONE
+    CHARACTER(len  = *)    , INTENT(IN) :: idt
+    xios_is_valid_axis = .FALSE.
+  END FUNCTION  xios_is_valid_axis
+
+  LOGICAL FUNCTION xios_is_valid_domain(idt)
+    IMPLICIT NONE
+    CHARACTER(len  = *)    , INTENT(IN) :: idt
+    xios_is_valid_domain = .FALSE.
+  END FUNCTION  xios_is_valid_domain
+
+
+   SUBROUTINE  xios_context_initialize(context_id,comm)
+   IMPLICIT NONE
+   CHARACTER(LEN=*),INTENT(IN)  :: context_id
+   INTEGER, INTENT(IN)          :: comm
+
+   END SUBROUTINE  xios_context_initialize
+
+
+   SUBROUTINE  xios_finalize
+   IMPLICIT NONE
+
+   END SUBROUTINE  xios_finalize
+
+
+   SUBROUTINE  xios_oasis_enddef
+   IMPLICIT NONE
+
+   END SUBROUTINE  xios_oasis_enddef
+
+
+   SUBROUTINE xios_close_context_definition
+   IMPLICIT NONE
+
+   END SUBROUTINE xios_close_context_definition
+
+
+   SUBROUTINE xios_set_current_context_hdl(context, withswap)
+      IMPLICIT NONE
+      TYPE(xios_context)          , INTENT(IN) :: context
+      LOGICAL                     , OPTIONAL, INTENT(IN) :: withswap
+   END SUBROUTINE xios_set_current_context_hdl
+   
+   SUBROUTINE xios_set_current_context_id(idt)
+      IMPLICIT NONE
+
+      CHARACTER(len = *) , INTENT(IN) :: idt
+      LOGICAL           :: withswap
+    END SUBROUTINE xios_set_current_context_id
+    
+
+   SUBROUTINE xios_get_current_context_hdl(context)
+      IMPLICIT NONE
+      TYPE(xios_context), INTENT(OUT) :: context
+   END SUBROUTINE xios_get_current_context_hdl
+
+   SUBROUTINE xios_get_current_context_id(idt)
+      IMPLICIT NONE
+      CHARACTER(len = *) , INTENT(OUT) :: idt
+      TYPE(xios_context) :: context
+   END SUBROUTINE xios_get_current_context_id
+
+   SUBROUTINE xios_context_finalize()
+   IMPLICIT NONE
+
+   END SUBROUTINE xios_context_finalize
+
+
+   SUBROUTINE xios_solve_inheritance()
+   IMPLICIT NONE
+
+   END SUBROUTINE xios_solve_inheritance
+
+
+
+
+  
+  SUBROUTINE xios_update_calendar(step)
+  IMPLICIT NONE
+   INTEGER, INTENT(IN):: step  
+  END SUBROUTINE xios_update_calendar
+
+  SUBROUTINE xios_set_filegroup_attr(name,enabled)
+    CHARACTER(LEN=*) :: name
+    LOGICAL,OPTIONAL          :: enabled
+  END SUBROUTINE xios_set_filegroup_attr
+
+  SUBROUTINE xios_get_axis_attr(name,n_glo,value)
+    CHARACTER(LEN=*) :: name
+    INTEGER,OPTIONAL          :: n_glo
+    REAL,OPTIONAL             :: value(:)
+  END SUBROUTINE xios_get_axis_attr
+
+   SUBROUTINE xios_get_context_handle(idt,ret)
+    IMPLICIT NONE
+    CHARACTER(len = *)  , INTENT(IN)  :: idt
+    TYPE(xios_context), INTENT(OUT):: ret
+    TYPE(xios_context)             :: nothing 
+      
+      ret=nothing
+   END SUBROUTINE xios_get_context_handle
+
+   SUBROUTINE xios_get_domain_handle(idt,ret)
+      IMPLICIT NONE
+      CHARACTER(len = *) , INTENT(IN) :: idt      
+      TYPE(xios_domain), INTENT(OUT):: ret
+      TYPE(xios_domain)             :: hdl
+      ret=hdl
+   END SUBROUTINE xios_get_domain_handle   
+
+   SUBROUTINE xios_get_field_handle(idt,ret)
+      IMPLICIT NONE
+      CHARACTER(len = *) , INTENT(IN) :: idt      
+      TYPE(xios_field), INTENT(OUT):: ret
+      TYPE(xios_field)             :: hdl
+      ret=hdl
+   END SUBROUTINE xios_get_field_handle   
+
+   SUBROUTINE xios_get_fieldgroup_handle(idt,ret)
+      IMPLICIT NONE
+      CHARACTER(len = *) , INTENT(IN) :: idt      
+      TYPE(xios_fieldgroup), INTENT(OUT):: ret
+      TYPE(xios_fieldgroup)             :: hdl
+      ret=hdl
+   END SUBROUTINE xios_get_fieldgroup_handle   
+
+   SUBROUTINE xios_get_file_handle(idt,ret)
+      IMPLICIT NONE
+      CHARACTER(len = *) , INTENT(IN) :: idt      
+      TYPE(xios_file), INTENT(OUT):: ret
+      TYPE(xios_file)             :: hdl
+      ret=hdl
+   END SUBROUTINE xios_get_file_handle   
+
+   SUBROUTINE xios_get_filegroup_handle(idt,ret)
+      IMPLICIT NONE
+      CHARACTER(len = *) , INTENT(IN) :: idt      
+      TYPE(xios_filegroup), INTENT(OUT):: ret
+      TYPE(xios_filegroup)             :: hdl
+      ret=hdl
+   END SUBROUTINE xios_get_filegroup_handle   
+
+
+
+  SUBROUTINE xios_fieldgroup_add_child(fieldgroup_hdl, field_hdl, id)
+    TYPE(xios_fieldgroup)     :: fieldgroup_hdl
+    TYPE(xios_field)          :: field_hdl
+    CHARACTER(LEN=*),OPTIONAL :: id
+  END SUBROUTINE xios_fieldgroup_add_child
+
+  SUBROUTINE xios_add_file(parent_hdl, child_hdl, child_id)
+      TYPE(xios_filegroup)      , INTENT(IN) :: parent_hdl
+      TYPE(xios_file)           , INTENT(OUT):: child_hdl
+      CHARACTER(len = *), OPTIONAL, INTENT(IN)  :: child_id
+      TYPE(xios_file) :: hdl
+      child_hdl = hdl
+  END SUBROUTINE xios_add_file
+
+  SUBROUTINE xios_add_field(parent_hdl, child_hdl, child_id)
+      TYPE(xios_fieldgroup)      , INTENT(IN) :: parent_hdl
+      TYPE(xios_field)           , INTENT(OUT):: child_hdl
+      CHARACTER(len = *), OPTIONAL, INTENT(IN)  :: child_id
+      TYPE(xios_field) :: hdl
+      child_hdl = hdl
+  END SUBROUTINE xios_add_field
+  
+  SUBROUTINE xios_add_fieldtofile(parent_hdl, child_hdl, child_id)
+    TYPE(xios_file)            , INTENT(IN) :: parent_hdl
+    TYPE(xios_field)           , INTENT(OUT):: child_hdl
+    CHARACTER(len = *), OPTIONAL , INTENT(IN) :: child_id
+    TYPE(xios_field) :: hdl
+    child_hdl = hdl
+
+  END SUBROUTINE xios_add_fieldtofile
+   
+  LOGICAL FUNCTION xios_field_is_active_id(field_id, at_current_timestep_arg)
+      IMPLICIT NONE
+      CHARACTER(len  = *) , INTENT(IN) :: field_id
+      LOGICAL, OPTIONAL   , INTENT(IN) :: at_current_timestep_arg
+
+     xios_field_is_active_id=.FALSE.
+   END FUNCTION xios_field_is_active_id
+
+   LOGICAL FUNCTION xios_field_is_active_hdl(field_hdl, at_current_timestep_arg)
+      IMPLICIT NONE
+      TYPE(xios_field) , INTENT(IN) :: field_hdl
+      LOGICAL, OPTIONAL  , INTENT(IN) :: at_current_timestep_arg
+
+     xios_field_is_active_hdl = .FALSE.
+   END FUNCTION xios_field_is_active_hdl
+   
+
+  SUBROUTINE  xios_set_generate_rectilinear_domain_attr(id, bounds_lon_start, bounds_lon_end,  bounds_lat_start,  bounds_lat_end)
+    CHARACTER(LEN=*) :: id
+    REAL, OPTIONAL :: bounds_lon_start
+    REAL, OPTIONAL :: bounds_lon_end
+    REAL, OPTIONAL :: bounds_lat_start
+    REAL, OPTIONAL :: bounds_lat_end
+  END SUBROUTINE  xios_set_generate_rectilinear_domain_attr    
+
+  SUBROUTINE xios_set_domain_attr  &
+    ( domain_id, area, bounds_lat_1d, bounds_lat_2d, bounds_lat_name, bounds_lon_1d, bounds_lon_2d  &
+    , bounds_lon_name, comment, data_dim, data_i_index, data_ibegin, data_j_index, data_jbegin, data_ni  &
+    , data_nj, dim_i_name, dim_j_name, domain_ref, i_index, ibegin, j_index, jbegin, lat_name, latvalue_1d  &
+    , latvalue_2d, lon_name, long_name, lonvalue_1d, lonvalue_2d, mask_1d, mask_2d, name, ni, ni_glo  &
+    , nj, nj_glo, nvertex, prec, radius, standard_name, type )
+
+    IMPLICIT NONE
+      TYPE(xios_domain)  :: domain_hdl
+      CHARACTER(LEN=*), INTENT(IN) ::domain_id
+      REAL (KIND=8) , OPTIONAL, INTENT(IN) :: area(:,:)
+      REAL (KIND=8) , OPTIONAL, INTENT(IN) :: bounds_lat_1d(:,:)
+      REAL (KIND=8) , OPTIONAL, INTENT(IN) :: bounds_lat_2d(:,:,:)
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: bounds_lat_name
+      REAL (KIND=8) , OPTIONAL, INTENT(IN) :: bounds_lon_1d(:,:)
+      REAL (KIND=8) , OPTIONAL, INTENT(IN) :: bounds_lon_2d(:,:,:)
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: bounds_lon_name
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: comment
+      INTEGER  , OPTIONAL, INTENT(IN) :: data_dim
+      INTEGER  , OPTIONAL, INTENT(IN) :: data_i_index(:)
+      INTEGER  , OPTIONAL, INTENT(IN) :: data_ibegin
+      INTEGER  , OPTIONAL, INTENT(IN) :: data_j_index(:)
+      INTEGER  , OPTIONAL, INTENT(IN) :: data_jbegin
+      INTEGER  , OPTIONAL, INTENT(IN) :: data_ni
+      INTEGER  , OPTIONAL, INTENT(IN) :: data_nj
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: dim_i_name
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: dim_j_name
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: domain_ref
+      INTEGER  , OPTIONAL, INTENT(IN) :: i_index(:)
+      INTEGER  , OPTIONAL, INTENT(IN) :: ibegin
+      INTEGER  , OPTIONAL, INTENT(IN) :: j_index(:)
+      INTEGER  , OPTIONAL, INTENT(IN) :: jbegin
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: lat_name
+      REAL (KIND=8) , OPTIONAL, INTENT(IN) :: latvalue_1d(:)
+      REAL (KIND=8) , OPTIONAL, INTENT(IN) :: latvalue_2d(:,:)
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: lon_name
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: long_name
+      REAL (KIND=8) , OPTIONAL, INTENT(IN) :: lonvalue_1d(:)
+      REAL (KIND=8) , OPTIONAL, INTENT(IN) :: lonvalue_2d(:,:)
+      LOGICAL  , OPTIONAL, INTENT(IN) :: mask_1d(:)
+      LOGICAL  , OPTIONAL, INTENT(IN) :: mask_2d(:,:)
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: name
+      INTEGER  , OPTIONAL, INTENT(IN) :: ni
+      INTEGER  , OPTIONAL, INTENT(IN) :: ni_glo
+      INTEGER  , OPTIONAL, INTENT(IN) :: nj
+      INTEGER  , OPTIONAL, INTENT(IN) :: nj_glo
+      INTEGER  , OPTIONAL, INTENT(IN) :: nvertex
+      INTEGER  , OPTIONAL, INTENT(IN) :: prec
+      REAL (KIND=8) , OPTIONAL, INTENT(IN) :: radius
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: standard_name
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: type
+
+  END SUBROUTINE xios_set_domain_attr  
+
+  SUBROUTINE xios_set_domain_attr_hdl  &
+    ( domain_hdl, area, bounds_lat_1d, bounds_lat_2d, bounds_lat_name, bounds_lon_1d, bounds_lon_2d  &
+    , bounds_lon_name, comment, data_dim, data_i_index, data_ibegin, data_j_index, data_jbegin, data_ni  &
+    , data_nj, dim_i_name, dim_j_name, domain_ref, i_index, ibegin, j_index, jbegin, lat_name, latvalue_1d  &
+    , latvalue_2d, lon_name, long_name, lonvalue_1d, lonvalue_2d, mask_1d, mask_2d, name, ni, ni_glo  &
+    , nj, nj_glo, nvertex, prec, radius, standard_name, type )
+
+    IMPLICIT NONE
+      TYPE(xios_domain) , INTENT(IN) :: domain_hdl
+      REAL (KIND=8) , OPTIONAL, INTENT(IN) :: area(:,:)
+      REAL (KIND=8) , OPTIONAL, INTENT(IN) :: bounds_lat_1d(:,:)
+      REAL (KIND=8) , OPTIONAL, INTENT(IN) :: bounds_lat_2d(:,:,:)
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: bounds_lat_name
+      REAL (KIND=8) , OPTIONAL, INTENT(IN) :: bounds_lon_1d(:,:)
+      REAL (KIND=8) , OPTIONAL, INTENT(IN) :: bounds_lon_2d(:,:,:)
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: bounds_lon_name
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: comment
+      INTEGER  , OPTIONAL, INTENT(IN) :: data_dim
+      INTEGER  , OPTIONAL, INTENT(IN) :: data_i_index(:)
+      INTEGER  , OPTIONAL, INTENT(IN) :: data_ibegin
+      INTEGER  , OPTIONAL, INTENT(IN) :: data_j_index(:)
+      INTEGER  , OPTIONAL, INTENT(IN) :: data_jbegin
+      INTEGER  , OPTIONAL, INTENT(IN) :: data_ni
+      INTEGER  , OPTIONAL, INTENT(IN) :: data_nj
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: dim_i_name
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: dim_j_name
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: domain_ref
+      INTEGER  , OPTIONAL, INTENT(IN) :: i_index(:)
+      INTEGER  , OPTIONAL, INTENT(IN) :: ibegin
+      INTEGER  , OPTIONAL, INTENT(IN) :: j_index(:)
+      INTEGER  , OPTIONAL, INTENT(IN) :: jbegin
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: lat_name
+      REAL (KIND=8) , OPTIONAL, INTENT(IN) :: latvalue_1d(:)
+      REAL (KIND=8) , OPTIONAL, INTENT(IN) :: latvalue_2d(:,:)
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: lon_name
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: long_name
+      REAL (KIND=8) , OPTIONAL, INTENT(IN) :: lonvalue_1d(:)
+      REAL (KIND=8) , OPTIONAL, INTENT(IN) :: lonvalue_2d(:,:)
+      LOGICAL  , OPTIONAL, INTENT(IN) :: mask_1d(:)
+      LOGICAL  , OPTIONAL, INTENT(IN) :: mask_2d(:,:)
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: name
+      INTEGER  , OPTIONAL, INTENT(IN) :: ni
+      INTEGER  , OPTIONAL, INTENT(IN) :: ni_glo
+      INTEGER  , OPTIONAL, INTENT(IN) :: nj
+      INTEGER  , OPTIONAL, INTENT(IN) :: nj_glo
+      INTEGER  , OPTIONAL, INTENT(IN) :: nvertex
+      INTEGER  , OPTIONAL, INTENT(IN) :: prec
+      REAL (KIND=8) , OPTIONAL, INTENT(IN) :: radius
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: standard_name
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: type
+  
+  END SUBROUTINE xios_set_domain_attr_hdl
+
+
+
+  SUBROUTINE xios_set_axis_attr  &
+    ( axis_id, axis_ref, axis_type, begin, bounds, bounds_name, comment, data_begin, data_index  &
+    , data_n, dim_name, formula, formula_bounds, formula_term, formula_term_bounds, index, label  &
+    , long_name, mask, n, n_distributed_partition, n_glo, name, positive, prec, standard_name, unit  &
+    , value )
+
+    IMPLICIT NONE
+      TYPE(xios_axis)  :: axis_hdl
+      CHARACTER(LEN=*), INTENT(IN) ::axis_id
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: axis_ref
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: axis_type
+      INTEGER  , OPTIONAL, INTENT(IN) :: begin
+      REAL (KIND=8) , OPTIONAL, INTENT(IN) :: bounds(:,:)
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: bounds_name
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: comment
+      INTEGER  , OPTIONAL, INTENT(IN) :: data_begin
+      INTEGER  , OPTIONAL, INTENT(IN) :: data_index(:)
+      INTEGER  , OPTIONAL, INTENT(IN) :: data_n
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: dim_name
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: formula
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: formula_bounds
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: formula_term
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: formula_term_bounds
+      INTEGER  , OPTIONAL, INTENT(IN) :: index(:)
+      CHARACTER(len=*) , OPTIONAL, INTENT(IN) :: label(:)
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: long_name
+      LOGICAL  , OPTIONAL, INTENT(IN) :: mask(:)
+      INTEGER  , OPTIONAL, INTENT(IN) :: n
+      INTEGER  , OPTIONAL, INTENT(IN) :: n_distributed_partition
+      INTEGER  , OPTIONAL, INTENT(IN) :: n_glo
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: name
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: positive
+      INTEGER  , OPTIONAL, INTENT(IN) :: prec
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: standard_name
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: unit
+      REAL (KIND=8) , OPTIONAL, INTENT(IN) :: value(:)
+
+  END SUBROUTINE xios_set_axis_attr
+
+  SUBROUTINE xios_set_axis_attr_hdl  &
+    ( axis_hdl, axis_ref, axis_type, begin, bounds, bounds_name, comment, data_begin, data_index  &
+    , data_n, dim_name, formula, formula_bounds, formula_term, formula_term_bounds, index, label  &
+    , long_name, mask, n, n_distributed_partition, n_glo, name, positive, prec, standard_name, unit  &
+    , value )
+
+    IMPLICIT NONE
+      TYPE(xios_axis) , INTENT(IN) :: axis_hdl
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: axis_ref
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: axis_type
+      INTEGER  , OPTIONAL, INTENT(IN) :: begin
+      REAL (KIND=8) , OPTIONAL, INTENT(IN) :: bounds(:,:)
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: bounds_name
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: comment
+      INTEGER  , OPTIONAL, INTENT(IN) :: data_begin
+      INTEGER  , OPTIONAL, INTENT(IN) :: data_index(:)
+      INTEGER  , OPTIONAL, INTENT(IN) :: data_n
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: dim_name
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: formula
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: formula_bounds
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: formula_term
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: formula_term_bounds
+      INTEGER  , OPTIONAL, INTENT(IN) :: index(:)
+      CHARACTER(len=*) , OPTIONAL, INTENT(IN) :: label(:)
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: long_name
+      LOGICAL  , OPTIONAL, INTENT(IN) :: mask(:)
+      INTEGER  , OPTIONAL, INTENT(IN) :: n
+      INTEGER  , OPTIONAL, INTENT(IN) :: n_distributed_partition
+      INTEGER  , OPTIONAL, INTENT(IN) :: n_glo
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: name
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: positive
+      INTEGER  , OPTIONAL, INTENT(IN) :: prec
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: standard_name
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: unit
+      REAL (KIND=8) , OPTIONAL, INTENT(IN) :: value(:)
+
+  END SUBROUTINE xios_set_axis_attr_hdl
+
+  SUBROUTINE xios_set_field_attr  &
+    ( field_id, add_offset, axis_ref, build_workflow_graph, cell_methods, cell_methods_mode, check_if_active  &
+    , comment, compression_level, default_value, detect_missing_value, domain_ref, enabled, expr  &
+    , field_ref, freq_offset, freq_op, grid_path, grid_ref, indexed_output, level, long_name, name  &
+    , operation, prec, read_access, scalar_ref, scale_factor, standard_name, ts_enabled, ts_split_freq  &
+    , unit, valid_max, valid_min )
+
+    IMPLICIT NONE
+      TYPE(xios_field)  :: field_hdl
+      CHARACTER(LEN=*), INTENT(IN) ::field_id
+      REAL (KIND=8) , OPTIONAL, INTENT(IN) :: add_offset
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: axis_ref
+      LOGICAL  , OPTIONAL, INTENT(IN) :: build_workflow_graph
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: cell_methods
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: cell_methods_mode
+      LOGICAL  , OPTIONAL, INTENT(IN) :: check_if_active
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: comment
+      INTEGER  , OPTIONAL, INTENT(IN) :: compression_level
+      REAL (KIND=8) , OPTIONAL, INTENT(IN) :: default_value
+      LOGICAL  , OPTIONAL, INTENT(IN) :: detect_missing_value
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: domain_ref
+      LOGICAL  , OPTIONAL, INTENT(IN) :: enabled
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: expr
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: field_ref
+      TYPE(xios_duration)  , OPTIONAL, INTENT(IN) :: freq_offset
+      TYPE(xios_duration)  , OPTIONAL, INTENT(IN) :: freq_op
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: grid_path
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: grid_ref
+      LOGICAL  , OPTIONAL, INTENT(IN) :: indexed_output
+      INTEGER  , OPTIONAL, INTENT(IN) :: level
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: long_name
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: name
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: operation
+      INTEGER  , OPTIONAL, INTENT(IN) :: prec
+      LOGICAL  , OPTIONAL, INTENT(IN) :: read_access
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: scalar_ref
+      REAL (KIND=8) , OPTIONAL, INTENT(IN) :: scale_factor
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: standard_name
+      LOGICAL  , OPTIONAL, INTENT(IN) :: ts_enabled
+      TYPE(xios_duration)  , OPTIONAL, INTENT(IN) :: ts_split_freq
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: unit
+      REAL (KIND=8) , OPTIONAL, INTENT(IN) :: valid_max
+      REAL (KIND=8) , OPTIONAL, INTENT(IN) :: valid_min
+
+  END SUBROUTINE xios_set_field_attr
+
+  SUBROUTINE xios_set_field_attr_hdl  &
+    ( field_hdl, add_offset, axis_ref, build_workflow_graph, cell_methods, cell_methods_mode, check_if_active  &
+    , comment, compression_level, default_value, detect_missing_value, domain_ref, enabled, expr  &
+    , field_ref, freq_offset, freq_op, grid_path, grid_ref, indexed_output, level, long_name, name  &
+    , operation, prec, read_access, scalar_ref, scale_factor, standard_name, ts_enabled, ts_split_freq  &
+    , unit, valid_max, valid_min )
+
+    IMPLICIT NONE
+      TYPE(xios_field) , INTENT(IN) :: field_hdl
+      REAL (KIND=8) , OPTIONAL, INTENT(IN) :: add_offset
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: axis_ref
+      LOGICAL  , OPTIONAL, INTENT(IN) :: build_workflow_graph
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: cell_methods
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: cell_methods_mode
+      LOGICAL  , OPTIONAL, INTENT(IN) :: check_if_active
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: comment
+      INTEGER  , OPTIONAL, INTENT(IN) :: compression_level
+      REAL (KIND=8) , OPTIONAL, INTENT(IN) :: default_value
+      LOGICAL  , OPTIONAL, INTENT(IN) :: detect_missing_value
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: domain_ref
+      LOGICAL  , OPTIONAL, INTENT(IN) :: enabled
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: expr
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: field_ref
+      TYPE(xios_duration)  , OPTIONAL, INTENT(IN) :: freq_offset
+      TYPE(xios_duration)  , OPTIONAL, INTENT(IN) :: freq_op
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: grid_path
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: grid_ref
+      LOGICAL  , OPTIONAL, INTENT(IN) :: indexed_output
+      INTEGER  , OPTIONAL, INTENT(IN) :: level
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: long_name
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: name
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: operation
+      INTEGER  , OPTIONAL, INTENT(IN) :: prec
+      LOGICAL  , OPTIONAL, INTENT(IN) :: read_access
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: scalar_ref
+      REAL (KIND=8) , OPTIONAL, INTENT(IN) :: scale_factor
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: standard_name
+      LOGICAL  , OPTIONAL, INTENT(IN) :: ts_enabled
+      TYPE(xios_duration)  , OPTIONAL, INTENT(IN) :: ts_split_freq
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: unit
+      REAL (KIND=8) , OPTIONAL, INTENT(IN) :: valid_max
+      REAL (KIND=8) , OPTIONAL, INTENT(IN) :: valid_min
+
+
+  END SUBROUTINE xios_set_field_attr_hdl
+
+
+  SUBROUTINE xios_set_fieldgroup_attr  &
+    ( fieldgroup_id, add_offset, axis_ref, build_workflow_graph, cell_methods, cell_methods_mode  &
+    , check_if_active, comment, compression_level, default_value, detect_missing_value, domain_ref  &
+    , enabled, expr, field_ref, freq_offset, freq_op, grid_path, grid_ref, group_ref, indexed_output  &
+    , level, long_name, name, operation, prec, read_access, scalar_ref, scale_factor, standard_name  &
+    , ts_enabled, ts_split_freq, unit, valid_max, valid_min )
+
+    IMPLICIT NONE
+      TYPE(xios_fieldgroup)  :: fieldgroup_hdl
+      CHARACTER(LEN=*), INTENT(IN) ::fieldgroup_id
+      REAL (KIND=8) , OPTIONAL, INTENT(IN) :: add_offset
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: axis_ref
+      LOGICAL  , OPTIONAL, INTENT(IN) :: build_workflow_graph
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: cell_methods
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: cell_methods_mode
+      LOGICAL  , OPTIONAL, INTENT(IN) :: check_if_active
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: comment
+      INTEGER  , OPTIONAL, INTENT(IN) :: compression_level
+      REAL (KIND=8) , OPTIONAL, INTENT(IN) :: default_value
+      LOGICAL  , OPTIONAL, INTENT(IN) :: detect_missing_value
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: domain_ref
+      LOGICAL  , OPTIONAL, INTENT(IN) :: enabled
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: expr
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: field_ref
+      TYPE(xios_duration)  , OPTIONAL, INTENT(IN) :: freq_offset
+      TYPE(xios_duration)  , OPTIONAL, INTENT(IN) :: freq_op
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: grid_path
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: grid_ref
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: group_ref
+      LOGICAL  , OPTIONAL, INTENT(IN) :: indexed_output
+      INTEGER  , OPTIONAL, INTENT(IN) :: level
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: long_name
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: name
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: operation
+      INTEGER  , OPTIONAL, INTENT(IN) :: prec
+      LOGICAL  , OPTIONAL, INTENT(IN) :: read_access
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: scalar_ref
+      REAL (KIND=8) , OPTIONAL, INTENT(IN) :: scale_factor
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: standard_name
+      LOGICAL  , OPTIONAL, INTENT(IN) :: ts_enabled
+      TYPE(xios_duration)  , OPTIONAL, INTENT(IN) :: ts_split_freq
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: unit
+      REAL (KIND=8) , OPTIONAL, INTENT(IN) :: valid_max
+      REAL (KIND=8) , OPTIONAL, INTENT(IN) :: valid_min
+
+  END SUBROUTINE xios_set_fieldgroup_attr
+
+  SUBROUTINE xios_set_fieldgroup_attr_hdl  &
+    ( fieldgroup_hdl, add_offset, axis_ref, build_workflow_graph, cell_methods, cell_methods_mode  &
+    , check_if_active, comment, compression_level, default_value, detect_missing_value, domain_ref  &
+    , enabled, expr, field_ref, freq_offset, freq_op, grid_path, grid_ref, group_ref, indexed_output  &
+    , level, long_name, name, operation, prec, read_access, scalar_ref, scale_factor, standard_name  &
+    , ts_enabled, ts_split_freq, unit, valid_max, valid_min )
+
+    IMPLICIT NONE
+      TYPE(xios_fieldgroup) , INTENT(IN) :: fieldgroup_hdl
+      REAL (KIND=8) , OPTIONAL, INTENT(IN) :: add_offset
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: axis_ref
+      LOGICAL  , OPTIONAL, INTENT(IN) :: build_workflow_graph
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: cell_methods
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: cell_methods_mode
+      LOGICAL  , OPTIONAL, INTENT(IN) :: check_if_active
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: comment
+      INTEGER  , OPTIONAL, INTENT(IN) :: compression_level
+      REAL (KIND=8) , OPTIONAL, INTENT(IN) :: default_value
+      LOGICAL  , OPTIONAL, INTENT(IN) :: detect_missing_value
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: domain_ref
+      LOGICAL  , OPTIONAL, INTENT(IN) :: enabled
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: expr
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: field_ref
+      TYPE(xios_duration)  , OPTIONAL, INTENT(IN) :: freq_offset
+      TYPE(xios_duration)  , OPTIONAL, INTENT(IN) :: freq_op
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: grid_path
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: grid_ref
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: group_ref
+      LOGICAL  , OPTIONAL, INTENT(IN) :: indexed_output
+      INTEGER  , OPTIONAL, INTENT(IN) :: level
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: long_name
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: name
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: operation
+      INTEGER  , OPTIONAL, INTENT(IN) :: prec
+      LOGICAL  , OPTIONAL, INTENT(IN) :: read_access
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: scalar_ref
+      REAL (KIND=8) , OPTIONAL, INTENT(IN) :: scale_factor
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: standard_name
+      LOGICAL  , OPTIONAL, INTENT(IN) :: ts_enabled
+      TYPE(xios_duration)  , OPTIONAL, INTENT(IN) :: ts_split_freq
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: unit
+      REAL (KIND=8) , OPTIONAL, INTENT(IN) :: valid_max
+      REAL (KIND=8) , OPTIONAL, INTENT(IN) :: valid_min
+
+  END SUBROUTINE xios_set_fieldgroup_attr_hdl
+
+
+  SUBROUTINE xios_set_file_attr  &
+    ( file_id, append, comment, compression_level, convention, convention_str, cyclic, description  &
+    , enabled, format, min_digits, mode, name, name_suffix, output_freq, output_level, par_access  &
+    , read_metadata_par, record_offset, split_end_offset, split_freq, split_freq_format, split_last_date  &
+    , split_start_offset, sync_freq, time_counter, time_counter_name, time_stamp_format, time_stamp_name  &
+    , time_units, timeseries, ts_prefix, type, uuid_format, uuid_name )
+
+    IMPLICIT NONE
+      TYPE(xios_file)  :: file_hdl
+      CHARACTER(LEN=*), INTENT(IN) ::file_id
+      LOGICAL  , OPTIONAL, INTENT(IN) :: append
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: comment
+      INTEGER  , OPTIONAL, INTENT(IN) :: compression_level
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: convention
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: convention_str
+      LOGICAL  , OPTIONAL, INTENT(IN) :: cyclic
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: description
+      LOGICAL  , OPTIONAL, INTENT(IN) :: enabled
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: format
+      INTEGER  , OPTIONAL, INTENT(IN) :: min_digits
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: mode
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: name
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: name_suffix
+      TYPE(xios_duration)  , OPTIONAL, INTENT(IN) :: output_freq
+      INTEGER  , OPTIONAL, INTENT(IN) :: output_level
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: par_access
+      LOGICAL  , OPTIONAL, INTENT(IN) :: read_metadata_par
+      INTEGER  , OPTIONAL, INTENT(IN) :: record_offset
+      TYPE(xios_duration)  , OPTIONAL, INTENT(IN) :: split_end_offset
+      TYPE(xios_duration)  , OPTIONAL, INTENT(IN) :: split_freq
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: split_freq_format
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: split_last_date
+      TYPE(xios_duration)  , OPTIONAL, INTENT(IN) :: split_start_offset
+      TYPE(xios_duration)  , OPTIONAL, INTENT(IN) :: sync_freq
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: time_counter
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: time_counter_name
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: time_stamp_format
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: time_stamp_name
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: time_units
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: timeseries
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: ts_prefix
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: type
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: uuid_format
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: uuid_name
+
+  END SUBROUTINE xios_set_file_attr
+
+  SUBROUTINE xios_set_file_attr_hdl  &
+    ( file_hdl, append, comment, compression_level, convention, convention_str, cyclic, description  &
+    , enabled, format, min_digits, mode, name, name_suffix, output_freq, output_level, par_access  &
+    , read_metadata_par, record_offset, split_end_offset, split_freq, split_freq_format, split_last_date  &
+    , split_start_offset, sync_freq, time_counter, time_counter_name, time_stamp_format, time_stamp_name  &
+    , time_units, timeseries, ts_prefix, type, uuid_format, uuid_name )
+
+    IMPLICIT NONE
+      TYPE(xios_file) , INTENT(IN) :: file_hdl
+      LOGICAL  , OPTIONAL, INTENT(IN) :: append
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: comment
+      INTEGER  , OPTIONAL, INTENT(IN) :: compression_level
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: convention
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: convention_str
+      LOGICAL  , OPTIONAL, INTENT(IN) :: cyclic
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: description
+      LOGICAL  , OPTIONAL, INTENT(IN) :: enabled
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: format
+      INTEGER  , OPTIONAL, INTENT(IN) :: min_digits
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: mode
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: name
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: name_suffix
+      TYPE(xios_duration)  , OPTIONAL, INTENT(IN) :: output_freq
+      INTEGER  , OPTIONAL, INTENT(IN) :: output_level
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: par_access
+      LOGICAL  , OPTIONAL, INTENT(IN) :: read_metadata_par
+      INTEGER  , OPTIONAL, INTENT(IN) :: record_offset
+      TYPE(xios_duration)  , OPTIONAL, INTENT(IN) :: split_end_offset
+      TYPE(xios_duration)  , OPTIONAL, INTENT(IN) :: split_freq
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: split_freq_format
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: split_last_date
+      TYPE(xios_duration)  , OPTIONAL, INTENT(IN) :: split_start_offset
+      TYPE(xios_duration)  , OPTIONAL, INTENT(IN) :: sync_freq
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: time_counter
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: time_counter_name
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: time_stamp_format
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: time_stamp_name
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: time_units
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: timeseries
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: ts_prefix
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: type
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: uuid_format
+      CHARACTER(len = *) , OPTIONAL, INTENT(IN) :: uuid_name
+
+  END SUBROUTINE xios_set_file_attr_hdl
+
+
+  SUBROUTINE xios_is_defined_domain_attr  &
+    ( domain_id, area, bounds_lat_1d, bounds_lat_2d, bounds_lat_name, bounds_lon_1d, bounds_lon_2d  &
+    , bounds_lon_name, comment, data_dim, data_i_index, data_ibegin, data_j_index, data_jbegin, data_ni  &
+    , data_nj, dim_i_name, dim_j_name, domain_ref, i_index, ibegin, j_index, jbegin, lat_name, latvalue_1d  &
+    , latvalue_2d, lon_name, long_name, lonvalue_1d, lonvalue_2d, mask_1d, mask_2d, name, ni, ni_glo  &
+    , nj, nj_glo, nvertex, prec, radius, standard_name, type )
+
+    IMPLICIT NONE
+      CHARACTER(LEN=*), INTENT(IN) ::domain_id
+      LOGICAL, OPTIONAL, INTENT(OUT) :: area
+      LOGICAL, OPTIONAL, INTENT(OUT) :: bounds_lat_1d
+      LOGICAL, OPTIONAL, INTENT(OUT) :: bounds_lat_2d
+      LOGICAL, OPTIONAL, INTENT(OUT) :: bounds_lat_name
+      LOGICAL, OPTIONAL, INTENT(OUT) :: bounds_lon_1d
+      LOGICAL, OPTIONAL, INTENT(OUT) :: bounds_lon_2d
+      LOGICAL, OPTIONAL, INTENT(OUT) :: bounds_lon_name
+      LOGICAL, OPTIONAL, INTENT(OUT) :: comment
+      LOGICAL, OPTIONAL, INTENT(OUT) :: data_dim
+      LOGICAL, OPTIONAL, INTENT(OUT) :: data_i_index
+      LOGICAL, OPTIONAL, INTENT(OUT) :: data_ibegin
+      LOGICAL, OPTIONAL, INTENT(OUT) :: data_j_index
+      LOGICAL, OPTIONAL, INTENT(OUT) :: data_jbegin
+      LOGICAL, OPTIONAL, INTENT(OUT) :: data_ni
+      LOGICAL, OPTIONAL, INTENT(OUT) :: data_nj
+      LOGICAL, OPTIONAL, INTENT(OUT) :: dim_i_name
+      LOGICAL, OPTIONAL, INTENT(OUT) :: dim_j_name
+      LOGICAL, OPTIONAL, INTENT(OUT) :: domain_ref
+      LOGICAL, OPTIONAL, INTENT(OUT) :: i_index
+      LOGICAL, OPTIONAL, INTENT(OUT) :: ibegin
+      LOGICAL, OPTIONAL, INTENT(OUT) :: j_index
+      LOGICAL, OPTIONAL, INTENT(OUT) :: jbegin
+      LOGICAL, OPTIONAL, INTENT(OUT) :: lat_name
+      LOGICAL, OPTIONAL, INTENT(OUT) :: latvalue_1d
+      LOGICAL, OPTIONAL, INTENT(OUT) :: latvalue_2d
+      LOGICAL, OPTIONAL, INTENT(OUT) :: lon_name
+      LOGICAL, OPTIONAL, INTENT(OUT) :: long_name
+      LOGICAL, OPTIONAL, INTENT(OUT) :: lonvalue_1d
+      LOGICAL, OPTIONAL, INTENT(OUT) :: lonvalue_2d
+      LOGICAL, OPTIONAL, INTENT(OUT) :: mask_1d
+      LOGICAL, OPTIONAL, INTENT(OUT) :: mask_2d
+      LOGICAL, OPTIONAL, INTENT(OUT) :: name
+      LOGICAL, OPTIONAL, INTENT(OUT) :: ni
+      LOGICAL, OPTIONAL, INTENT(OUT) :: ni_glo
+      LOGICAL, OPTIONAL, INTENT(OUT) :: nj
+      LOGICAL, OPTIONAL, INTENT(OUT) :: nj_glo
+      LOGICAL, OPTIONAL, INTENT(OUT) :: nvertex
+      LOGICAL, OPTIONAL, INTENT(OUT) :: prec
+      LOGICAL, OPTIONAL, INTENT(OUT) :: radius
+      LOGICAL, OPTIONAL, INTENT(OUT) :: standard_name
+      LOGICAL, OPTIONAL, INTENT(OUT) :: type
+
+      area = .FALSE.
+      bounds_lat_1d = .FALSE.
+      bounds_lat_2d = .FALSE.
+      bounds_lat_name = .FALSE.
+      bounds_lon_1d = .FALSE.
+      bounds_lon_2d = .FALSE.
+      bounds_lon_name = .FALSE.
+      comment = .FALSE.
+      data_dim = .FALSE.
+      data_i_index = .FALSE.
+      data_ibegin = .FALSE.
+      data_j_index = .FALSE.
+      data_jbegin = .FALSE.
+      data_ni = .FALSE.
+      data_nj = .FALSE.
+      dim_i_name = .FALSE.
+      dim_j_name = .FALSE.
+      domain_ref = .FALSE.
+      i_index = .FALSE.
+      ibegin = .FALSE.
+      j_index = .FALSE.
+      jbegin = .FALSE.
+      lat_name = .FALSE.
+      latvalue_1d = .FALSE.
+      latvalue_2d = .FALSE.
+      lon_name = .FALSE.
+      long_name = .FALSE.
+      lonvalue_1d = .FALSE.
+      lonvalue_2d = .FALSE.
+      mask_1d = .FALSE.
+      mask_2d = .FALSE.
+      name = .FALSE.
+      ni = .FALSE.
+      ni_glo = .FALSE.
+      nj = .FALSE.
+      nj_glo = .FALSE.
+      nvertex = .FALSE.
+      prec = .FALSE.
+      radius = .FALSE.
+      standard_name = .FALSE.
+      type = .FALSE.
+
+  END SUBROUTINE xios_is_defined_domain_attr
+
+  SUBROUTINE xios_is_defined_domain_attr_hdl  &
+    ( domain_hdl, area, bounds_lat_1d, bounds_lat_2d, bounds_lat_name, bounds_lon_1d, bounds_lon_2d  &
+    , bounds_lon_name, comment, data_dim, data_i_index, data_ibegin, data_j_index, data_jbegin, data_ni  &
+    , data_nj, dim_i_name, dim_j_name, domain_ref, i_index, ibegin, j_index, jbegin, lat_name, latvalue_1d  &
+    , latvalue_2d, lon_name, long_name, lonvalue_1d, lonvalue_2d, mask_1d, mask_2d, name, ni, ni_glo  &
+    , nj, nj_glo, nvertex, prec, radius, standard_name, type )
+
+    IMPLICIT NONE 
+      TYPE(xios_domain), INTENT(IN) :: domain_hdl
+      LOGICAL, OPTIONAL, INTENT(OUT) :: area
+      LOGICAL, OPTIONAL, INTENT(OUT) :: bounds_lat_1d
+      LOGICAL, OPTIONAL, INTENT(OUT) :: bounds_lat_2d
+      LOGICAL, OPTIONAL, INTENT(OUT) :: bounds_lat_name
+      LOGICAL, OPTIONAL, INTENT(OUT) :: bounds_lon_1d
+      LOGICAL, OPTIONAL, INTENT(OUT) :: bounds_lon_2d
+      LOGICAL, OPTIONAL, INTENT(OUT) :: bounds_lon_name
+      LOGICAL, OPTIONAL, INTENT(OUT) :: comment
+      LOGICAL, OPTIONAL, INTENT(OUT) :: data_dim
+      LOGICAL, OPTIONAL, INTENT(OUT) :: data_i_index
+      LOGICAL, OPTIONAL, INTENT(OUT) :: data_ibegin
+      LOGICAL, OPTIONAL, INTENT(OUT) :: data_j_index
+      LOGICAL, OPTIONAL, INTENT(OUT) :: data_jbegin
+      LOGICAL, OPTIONAL, INTENT(OUT) :: data_ni
+      LOGICAL, OPTIONAL, INTENT(OUT) :: data_nj
+      LOGICAL, OPTIONAL, INTENT(OUT) :: dim_i_name
+      LOGICAL, OPTIONAL, INTENT(OUT) :: dim_j_name
+      LOGICAL, OPTIONAL, INTENT(OUT) :: domain_ref
+      LOGICAL, OPTIONAL, INTENT(OUT) :: i_index
+      LOGICAL, OPTIONAL, INTENT(OUT) :: ibegin
+      LOGICAL, OPTIONAL, INTENT(OUT) :: j_index
+      LOGICAL, OPTIONAL, INTENT(OUT) :: jbegin
+      LOGICAL, OPTIONAL, INTENT(OUT) :: lat_name
+      LOGICAL, OPTIONAL, INTENT(OUT) :: latvalue_1d
+      LOGICAL, OPTIONAL, INTENT(OUT) :: latvalue_2d
+      LOGICAL, OPTIONAL, INTENT(OUT) :: lon_name
+      LOGICAL, OPTIONAL, INTENT(OUT) :: long_name
+      LOGICAL, OPTIONAL, INTENT(OUT) :: lonvalue_1d
+      LOGICAL, OPTIONAL, INTENT(OUT) :: lonvalue_2d
+      LOGICAL, OPTIONAL, INTENT(OUT) :: mask_1d
+      LOGICAL, OPTIONAL, INTENT(OUT) :: mask_2d
+      LOGICAL, OPTIONAL, INTENT(OUT) :: name
+      LOGICAL, OPTIONAL, INTENT(OUT) :: ni
+      LOGICAL, OPTIONAL, INTENT(OUT) :: ni_glo
+      LOGICAL, OPTIONAL, INTENT(OUT) :: nj
+      LOGICAL, OPTIONAL, INTENT(OUT) :: nj_glo
+      LOGICAL, OPTIONAL, INTENT(OUT) :: nvertex
+      LOGICAL, OPTIONAL, INTENT(OUT) :: prec
+      LOGICAL, OPTIONAL, INTENT(OUT) :: radius
+      LOGICAL, OPTIONAL, INTENT(OUT) :: standard_name
+      LOGICAL, OPTIONAL, INTENT(OUT) :: type
+
+      area = .FALSE.
+      bounds_lat_1d = .FALSE.
+      bounds_lat_2d = .FALSE.
+      bounds_lat_name = .FALSE.
+      bounds_lon_1d = .FALSE.
+      bounds_lon_2d = .FALSE.
+      bounds_lon_name = .FALSE.
+      comment = .FALSE.
+      data_dim = .FALSE.
+      data_i_index = .FALSE.
+      data_ibegin = .FALSE.
+      data_j_index = .FALSE.
+      data_jbegin = .FALSE.
+      data_ni = .FALSE.
+      data_nj = .FALSE.
+      dim_i_name = .FALSE.
+      dim_j_name = .FALSE.
+      domain_ref = .FALSE.
+      i_index = .FALSE.
+      ibegin = .FALSE.
+      j_index = .FALSE.
+      jbegin = .FALSE.
+      lat_name = .FALSE.
+      latvalue_1d = .FALSE.
+      latvalue_2d = .FALSE.
+      lon_name = .FALSE.
+      long_name = .FALSE.
+      lonvalue_1d = .FALSE.
+      lonvalue_2d = .FALSE.
+      mask_1d = .FALSE.
+      mask_2d = .FALSE.
+      name = .FALSE.
+      ni = .FALSE.
+      ni_glo = .FALSE.
+      nj = .FALSE.
+      nj_glo = .FALSE.
+      nvertex = .FALSE.
+      prec = .FALSE.
+      radius = .FALSE.
+      standard_name = .FALSE.
+      type = .FALSE.
+
+  END SUBROUTINE xios_is_defined_domain_attr_hdl
+
+  SUBROUTINE xios_get_field_attr  &
+    ( field_id, add_offset, axis_ref, build_workflow_graph, cell_methods, cell_methods_mode, check_if_active  &
+    , comment, compression_level, default_value, detect_missing_value, domain_ref, enabled, expr  &
+    , field_ref, freq_offset, freq_op, grid_path, grid_ref, indexed_output, level, long_name, name  &
+    , operation, prec, read_access, scalar_ref, scale_factor, standard_name, ts_enabled, ts_split_freq  &
+    , unit, valid_max, valid_min )
+
+    IMPLICIT NONE
+      TYPE(xios_field)  :: field_hdl
+      CHARACTER(LEN=*), INTENT(IN) ::field_id
+      REAL (KIND=8) , OPTIONAL, INTENT(OUT) :: add_offset
+      CHARACTER(len = *) , OPTIONAL, INTENT(OUT) :: axis_ref
+      LOGICAL  , OPTIONAL, INTENT(OUT) :: build_workflow_graph
+      CHARACTER(len = *) , OPTIONAL, INTENT(OUT) :: cell_methods
+      CHARACTER(len = *) , OPTIONAL, INTENT(OUT) :: cell_methods_mode
+      LOGICAL  , OPTIONAL, INTENT(OUT) :: check_if_active
+      CHARACTER(len = *) , OPTIONAL, INTENT(OUT) :: comment
+      INTEGER  , OPTIONAL, INTENT(OUT) :: compression_level
+      REAL (KIND=8) , OPTIONAL, INTENT(OUT) :: default_value
+      LOGICAL  , OPTIONAL, INTENT(OUT) :: detect_missing_value
+      CHARACTER(len = *) , OPTIONAL, INTENT(OUT) :: domain_ref
+      LOGICAL  , OPTIONAL, INTENT(OUT) :: enabled
+      CHARACTER(len = *) , OPTIONAL, INTENT(OUT) :: expr
+      CHARACTER(len = *) , OPTIONAL, INTENT(OUT) :: field_ref
+      TYPE(xios_duration)  , OPTIONAL, INTENT(OUT) :: freq_offset
+      TYPE(xios_duration)  , OPTIONAL, INTENT(OUT) :: freq_op
+      CHARACTER(len = *) , OPTIONAL, INTENT(OUT) :: grid_path
+      CHARACTER(len = *) , OPTIONAL, INTENT(OUT) :: grid_ref
+      LOGICAL  , OPTIONAL, INTENT(OUT) :: indexed_output
+      INTEGER  , OPTIONAL, INTENT(OUT) :: level
+      CHARACTER(len = *) , OPTIONAL, INTENT(OUT) :: long_name
+      CHARACTER(len = *) , OPTIONAL, INTENT(OUT) :: name
+      CHARACTER(len = *) , OPTIONAL, INTENT(OUT) :: operation
+      INTEGER  , OPTIONAL, INTENT(OUT) :: prec
+      LOGICAL  , OPTIONAL, INTENT(OUT) :: read_access
+      CHARACTER(len = *) , OPTIONAL, INTENT(OUT) :: scalar_ref
+      REAL (KIND=8) , OPTIONAL, INTENT(OUT) :: scale_factor
+      CHARACTER(len = *) , OPTIONAL, INTENT(OUT) :: standard_name
+      LOGICAL  , OPTIONAL, INTENT(OUT) :: ts_enabled
+      TYPE(xios_duration)  , OPTIONAL, INTENT(OUT) :: ts_split_freq
+      CHARACTER(len = *) , OPTIONAL, INTENT(OUT) :: unit
+      REAL (KIND=8) , OPTIONAL, INTENT(OUT) :: valid_max
+      REAL (KIND=8) , OPTIONAL, INTENT(OUT) :: valid_min
+
+  END SUBROUTINE xios_get_field_attr
+
+  SUBROUTINE xios_get_field_attr_hdl  &
+    ( field_hdl, add_offset, axis_ref, build_workflow_graph, cell_methods, cell_methods_mode, check_if_active  &
+    , comment, compression_level, default_value, detect_missing_value, domain_ref, enabled, expr  &
+    , field_ref, freq_offset, freq_op, grid_path, grid_ref, indexed_output, level, long_name, name  &
+    , operation, prec, read_access, scalar_ref, scale_factor, standard_name, ts_enabled, ts_split_freq  &
+    , unit, valid_max, valid_min )
+
+    IMPLICIT NONE
+      TYPE(xios_field) , INTENT(IN) :: field_hdl
+      REAL (KIND=8) , OPTIONAL, INTENT(OUT) :: add_offset
+      CHARACTER(len = *) , OPTIONAL, INTENT(OUT) :: axis_ref
+      LOGICAL  , OPTIONAL, INTENT(OUT) :: build_workflow_graph
+      CHARACTER(len = *) , OPTIONAL, INTENT(OUT) :: cell_methods
+      CHARACTER(len = *) , OPTIONAL, INTENT(OUT) :: cell_methods_mode
+      LOGICAL  , OPTIONAL, INTENT(OUT) :: check_if_active
+      CHARACTER(len = *) , OPTIONAL, INTENT(OUT) :: comment
+      INTEGER  , OPTIONAL, INTENT(OUT) :: compression_level
+      REAL (KIND=8) , OPTIONAL, INTENT(OUT) :: default_value
+      LOGICAL  , OPTIONAL, INTENT(OUT) :: detect_missing_value
+      CHARACTER(len = *) , OPTIONAL, INTENT(OUT) :: domain_ref
+      LOGICAL  , OPTIONAL, INTENT(OUT) :: enabled
+      CHARACTER(len = *) , OPTIONAL, INTENT(OUT) :: expr
+      CHARACTER(len = *) , OPTIONAL, INTENT(OUT) :: field_ref
+      TYPE(xios_duration)  , OPTIONAL, INTENT(OUT) :: freq_offset
+      TYPE(xios_duration)  , OPTIONAL, INTENT(OUT) :: freq_op
+      CHARACTER(len = *) , OPTIONAL, INTENT(OUT) :: grid_path
+      CHARACTER(len = *) , OPTIONAL, INTENT(OUT) :: grid_ref
+      LOGICAL  , OPTIONAL, INTENT(OUT) :: indexed_output
+      INTEGER  , OPTIONAL, INTENT(OUT) :: level
+      CHARACTER(len = *) , OPTIONAL, INTENT(OUT) :: long_name
+      CHARACTER(len = *) , OPTIONAL, INTENT(OUT) :: name
+      CHARACTER(len = *) , OPTIONAL, INTENT(OUT) :: operation
+      INTEGER  , OPTIONAL, INTENT(OUT) :: prec
+      LOGICAL  , OPTIONAL, INTENT(OUT) :: read_access
+      CHARACTER(len = *) , OPTIONAL, INTENT(OUT) :: scalar_ref
+      REAL (KIND=8) , OPTIONAL, INTENT(OUT) :: scale_factor
+      CHARACTER(len = *) , OPTIONAL, INTENT(OUT) :: standard_name
+      LOGICAL  , OPTIONAL, INTENT(OUT) :: ts_enabled
+      TYPE(xios_duration)  , OPTIONAL, INTENT(OUT) :: ts_split_freq
+      CHARACTER(len = *) , OPTIONAL, INTENT(OUT) :: unit
+      REAL (KIND=8) , OPTIONAL, INTENT(OUT) :: valid_max
+      REAL (KIND=8) , OPTIONAL, INTENT(OUT) :: valid_min
+
+  END SUBROUTINE xios_get_field_attr_hdl
+      
+END MODULE lmdz_xios
+
+#endif 
Index: LMDZ6/trunk/libf/misc/wxios.F90
===================================================================
--- LMDZ6/trunk/libf/misc/wxios.F90	(revision 4618)
+++ LMDZ6/trunk/libf/misc/wxios.F90	(revision 4619)
@@ -1,14 +1,6 @@
 ! $Id$
-#ifdef CPP_XIOS
+
 MODULE wxios
-    USE xios
-    USE iaxis
-    USE iaxis_attr
-    USE icontext_attr
-    USE idate
-    USE idomain_attr
-    USE ifield_attr
-    USE ifile_attr
-    USE ixml_tree
+    USE lmdz_xios
 
     !Variables disponibles pendant toute l'execution du programme:
@@ -411,10 +403,10 @@
         
         !On récupère le handle:
-        CALL xios_get_domain_handle(dom_id, dom)
+        CALL xios_get_handle(dom_id, dom)
         
         !On parametrise le domaine:
-        CALL xios_set_domain_attr_hdl(dom, ni_glo=nbp_lon, ibegin=0, ni=nbp_lon, type="rectilinear")
-        CALL xios_set_domain_attr_hdl(dom, nj_glo=nbp_lat, jbegin=jj_begin-1, nj=jj_nb, data_dim=2)
-        CALL xios_set_domain_attr_hdl(dom, lonvalue_1d=io_lon(1:nbp_lon), latvalue_1d=io_lat(jj_begin:jj_end))
+        CALL xios_set_attr(dom, ni_glo=nbp_lon, ibegin=0, ni=nbp_lon, type="rectilinear")
+        CALL xios_set_attr(dom, nj_glo=nbp_lat, jbegin=jj_begin-1, nj=jj_nb, data_dim=2)
+        CALL xios_set_attr(dom, lonvalue_1d=io_lon(1:nbp_lon), latvalue_1d=io_lat(jj_begin:jj_end))
         CALL xios_set_domain_attr("dom_out", domain_ref=dom_id)
 
@@ -438,8 +430,8 @@
               WRITE(lunout,*) "wxios_domain_param: mpirank=",mpi_rank," mask(:,jj_nb)=",mask(:,jj_nb)
             ENDIF
-            CALL xios_set_domain_attr_hdl(dom, mask_2d=mask)
-        END IF
-
-         CALL xios_is_defined_domain_attr_hdl(dom,ni_glo=boool)
+            CALL xios_set_attr(dom, mask_2d=mask)
+        END IF
+
+         CALL xios_is_defined_attr(dom,ni_glo=boool)
         !Vérification:
         IF (xios_is_valid_domain(dom_id)) THEN
@@ -480,5 +472,5 @@
 
 !$OMP MASTER
-        CALL xios_get_domain_handle(dom_id, dom)
+        CALL xios_get_handle(dom_id, dom)
         
         !On parametrise le domaine:
@@ -580,6 +572,6 @@
         IF (.NOT.xios_is_valid_file(fname)) THEN
             !On créé le noeud:
-            CALL xios_get_filegroup_handle("defile", x_fg)
-            CALL xios_add_file(x_fg, x_file, fname)
+            CALL xios_get_handle("defile", x_fg)
+            CALL xios_add_child(x_fg, x_file, fname)
         
             !On reformate la fréquence:
@@ -587,5 +579,5 @@
         
             !On configure:
-            CALL xios_set_file_attr_hdl(x_file, name="X"//fname,&
+            CALL xios_set_attr(x_file, name="X"//fname,&
                 output_freq=nffreq, output_level=flvl, enabled=.TRUE.)
        
@@ -636,9 +628,9 @@
         
         !On ajoute le champ:
-        CALL xios_add_field(fieldgroup, field, fieldname)
+        CALL xios_add_child(fieldgroup, field, fieldname)
         !IF (prt_level >= 10) WRITE(lunout,*) "wxios_add_field: ",fieldname,fieldgroup, fieldlongname, fieldunit
         
         !On rentre ses paramètres:
-        CALL xios_set_field_attr_hdl(field, standard_name=fieldlongname, unit=newunit, default_value=def)
+        CALL xios_set_attr(field, standard_name=fieldlongname, unit=newunit, default_value=def)
         IF (prt_level >= 10) WRITE(lunout,*) "wxios_add_field: Field ",trim(fieldname), "cree:"
         IF (prt_level >= 10) WRITE(lunout,*) "wxios_add_field: long_name=",trim(fieldlongname),"; unit=",trim(newunit),";  default_value=",nf90_fill_real
@@ -691,7 +683,7 @@
         !On selectionne le bon groupe de champs:
         IF (fdim.EQ.2) THEN
-          CALL xios_get_fieldgroup_handle("fields_2D", fieldgroup)
+          CALL xios_get_handle("fields_2D", fieldgroup)
         ELSE
-          CALL xios_get_fieldgroup_handle("fields_3D", fieldgroup)
+          CALL xios_get_handle("fields_3D", fieldgroup)
         ENDIF
         
@@ -722,15 +714,15 @@
             !Champ existe déjà, mais pas XML, alors on l'ajoute
             !On ajoute le champ:
-            CALL xios_get_file_handle(fname, f)
-            CALL xios_add_fieldtofile(f, field)
+            CALL xios_get_handle(fname, f)
+            CALL xios_add_child(f, field)
             
             
             !L'operation, sa frequence:
             freq_op%timestep=1
-            CALL xios_set_field_attr_hdl(field, field_ref=fieldname, operation=TRIM(ADJUSTL(operation)), freq_op=freq_op, prec=4)
+            CALL xios_set_attr(field, field_ref=fieldname, operation=TRIM(ADJUSTL(operation)), freq_op=freq_op, prec=4)
 
             
             !On rentre ses paramètres:
-            CALL xios_set_field_attr_hdl(field, level=field_level, enabled=.TRUE.)
+            CALL xios_set_attr(field, level=field_level, enabled=.TRUE.)
             
             IF (fdim.EQ.2) THEN
@@ -744,5 +736,5 @@
                 !Si 3D :
                 !On ajoute l'axe vertical qui va bien:
-                CALL xios_set_field_attr_hdl(field, axis_ref=TRIM(ADJUSTL(axis_id)))
+                CALL xios_set_attr(field, axis_ref=TRIM(ADJUSTL(axis_id)))
                 
                 IF (prt_level >= 10) THEN
@@ -792,3 +784,3 @@
      END SUBROUTINE wxios_close
 END MODULE wxios
-#endif
+
Index: LMDZ6/trunk/libf/phydev/iophy.F90
===================================================================
--- LMDZ6/trunk/libf/phydev/iophy.F90	(revision 4618)
+++ LMDZ6/trunk/libf/phydev/iophy.F90	(revision 4619)
@@ -13,27 +13,13 @@
   
 
-#ifdef CPP_XIOS
 ! interfaces for both IOIPSL and XIOS
   INTERFACE histwrite_phy
     MODULE PROCEDURE histwrite2d_phy,histwrite3d_phy,histwrite2d_xios,histwrite3d_xios
   END INTERFACE
-#else
-! interfaces for IOIPSL
-  INTERFACE histwrite_phy
-    MODULE PROCEDURE histwrite2d_phy,histwrite3d_phy
-  END INTERFACE
-#endif
-
-#ifdef CPP_XIOS
+
 ! interfaces for both IOIPSL and XIOS
   INTERFACE histbeg_phy_all
     MODULE PROCEDURE histbeg_phy, histbeg_phyxios
   END INTERFACE
-#else
-! interfaces for IOIPSL
-  INTERFACE histbeg_phy_all
-    MODULE PROCEDURE histbeg_phy
-  END INTERFACE
-#endif
 
 contains
@@ -51,7 +37,5 @@
   USE ioipsl, only: flio_dom_set
 #endif
-#ifdef CPP_XIOS
-  use wxios, only: wxios_domain_param
-#endif
+  use wxios, only: wxios_domain_param, using_xios
   implicit none
     real,dimension(klon),intent(in) :: rlon
@@ -122,32 +106,32 @@
                       'APPLE',phys_domain_id)
 #endif
-#ifdef CPP_XIOS
-    ! Set values for the mask:
-    IF (mpi_rank == 0) THEN
-        data_ibegin = 0
-    ELSE 
-        data_ibegin = ii_begin - 1
-    END IF
-
-    IF (mpi_rank == mpi_size-1) THEN
-        data_iend = nbp_lon
-    ELSE
-        data_iend = ii_end + 1
-    END IF
-
-    if (prt_level>=10) then
-      write(lunout,*) "init_iophy_new: mpirank=",mpi_rank," iibegin=",ii_begin , " ii_end=",ii_end," jjbegin=",jj_begin," jj_nb=",jj_nb," jj_end=",jj_end
-      write(lunout,*) "init_iophy_new: mpirank=",mpi_rank," nbp_lon=",nbp_lon," nbp_lat=",nbp_lat
-      write(lunout,*) "init_iophy_new: mpirank=",mpi_rank," data_ibegin=",data_ibegin," data_iend=",data_iend
-      write(lunout,*) "init_iophy_new: mpirank=",mpi_rank," data_ibegin=",data_ibegin," data_iend=",data_iend
-      write(lunout,*) "init_iophy_new: mpirank=",mpi_rank," is_south_pole=",is_south_pole_dyn
-    endif
-
-    ! Initialize the XIOS domain coreesponding to this process:
-    CALL wxios_domain_param("dom_glo", is_sequential, nbp_lon, jj_nb, nbp_lon, nbp_lat, &
-                            1, nbp_lon, ii_begin, ii_end, jj_begin, jj_end,             &
-                            klon_mpi+2*(nbp_lon-1), data_ibegin, data_iend,             &
-                            io_lat, io_lon,is_south_pole_dyn,mpi_rank)
-#endif
+    IF (using_xios) THEN
+      ! Set values for the mask:
+      IF (mpi_rank == 0) THEN
+          data_ibegin = 0
+      ELSE 
+          data_ibegin = ii_begin - 1
+      END IF
+
+      IF (mpi_rank == mpi_size-1) THEN
+          data_iend = nbp_lon
+      ELSE
+          data_iend = ii_end + 1
+      END IF
+
+      if (prt_level>=10) then
+        write(lunout,*) "init_iophy_new: mpirank=",mpi_rank," iibegin=",ii_begin , " ii_end=",ii_end," jjbegin=",jj_begin," jj_nb=",jj_nb," jj_end=",jj_end
+        write(lunout,*) "init_iophy_new: mpirank=",mpi_rank," nbp_lon=",nbp_lon," nbp_lat=",nbp_lat
+        write(lunout,*) "init_iophy_new: mpirank=",mpi_rank," data_ibegin=",data_ibegin," data_iend=",data_iend
+        write(lunout,*) "init_iophy_new: mpirank=",mpi_rank," data_ibegin=",data_ibegin," data_iend=",data_iend
+        write(lunout,*) "init_iophy_new: mpirank=",mpi_rank," is_south_pole=",is_south_pole_dyn
+      endif
+
+      ! Initialize the XIOS domain coreesponding to this process:
+      CALL wxios_domain_param("dom_glo", is_sequential, nbp_lon, jj_nb, nbp_lon, nbp_lat, &
+                              1, nbp_lon, ii_begin, ii_end, jj_begin, jj_end,             &
+                              klon_mpi+2*(nbp_lon-1), data_ibegin, data_iend,             &
+                              io_lat, io_lon,is_south_pole_dyn,mpi_rank)
+    ENDIF
 !$OMP END MASTER
       
@@ -184,5 +168,4 @@
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
-#ifdef CPP_XIOS
 
 ! SUBROUTINE histbeg_phyxios(name,itau0,zjulian,dtime,ffreq,lev,nhori,nid_day)
@@ -213,5 +196,4 @@
   END SUBROUTINE histbeg_phyxios
 
-#endif
 
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -339,10 +321,10 @@
 
 ! VERSION DES HISTWRITE DEDIEES AU TOUT-XIOS-XML DEJA UTILISEE DANS PHYDEV
-#ifdef CPP_XIOS
+
   SUBROUTINE histwrite2d_xios(field_name,field)
   USE dimphy, only: klon
   USE mod_phys_lmdz_para, only: gather_omp, grid1Dto2D_mpi, &
                                 jj_nb, klon_mpi
-  USE xios, only: xios_send_field
+  USE lmdz_xios, only: xios_send_field
   USE print_control_mod, ONLY: prt_level, lunout
   USE mod_grid_phy_lmdz, ONLY: nbp_lon
@@ -368,15 +350,14 @@
     IF (prt_level >= 10) WRITE(lunout,*)'End histrwrite2d_xios ',trim(field_name)
   END SUBROUTINE histwrite2d_xios
-#endif
 
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
 ! VERSION DES HISTWRITE DEDIEES AU TOUT-XIOS-XML DEJA UTILISEE DANS PHYDEV
-#ifdef CPP_XIOS
+
   SUBROUTINE histwrite3d_xios(field_name, field)
   USE dimphy, only: klon, klev
   USE mod_phys_lmdz_para, only: gather_omp, grid1Dto2D_mpi, &
                                 jj_nb, klon_mpi
-  USE xios, only: xios_send_field
+  USE lmdz_xios, only: xios_send_field
   USE print_control_mod, ONLY: prt_level,lunout
   USE mod_grid_phy_lmdz, ONLY: nbp_lon
@@ -407,5 +388,4 @@
     IF (prt_level >= 10) write(lunout,*)'End histrwrite3d_xios ',trim(field_name)
   END SUBROUTINE histwrite3d_xios
-#endif
 
 end module iophy
Index: LMDZ6/trunk/libf/phydev/physiq_mod.F90
===================================================================
--- LMDZ6/trunk/libf/phydev/physiq_mod.F90	(revision 4618)
+++ LMDZ6/trunk/libf/phydev/physiq_mod.F90	(revision 4619)
@@ -23,9 +23,7 @@
       USE mod_grid_phy_lmdz, ONLY: nbp_lon,nbp_lat
 
-#ifdef CPP_XIOS
-      USE xios, ONLY: xios_update_calendar
+      USE lmdz_xios, ONLY: xios_update_calendar, using_xios
       USE wxios, only: wxios_add_vaxis, wxios_set_cal, wxios_closedef
       USE iophy, ONLY: histwrite_phy
-#endif
 
       IMPLICIT none
@@ -126,15 +124,15 @@
 #endif
 
-#ifdef CPP_XIOS
+    IF (using_xios) THEN
 !XIOS
-    ! Declare available vertical axes to be used in output files:    
-    CALL wxios_add_vaxis("presnivs", klev, presnivs)
+      ! Declare available vertical axes to be used in output files:    
+      CALL wxios_add_vaxis("presnivs", klev, presnivs)
 
-    ! Declare calendar and time step
-    CALL wxios_set_cal(dtime,"earth_360d",1,1,1,0.0,1,1,1,0.0)
+      ! Declare calendar and time step
+      CALL wxios_set_cal(dtime,"earth_360d",1,1,1,0.0,1,1,1,0.0)
     
-    !Finalize the context:
-    CALL wxios_closedef()
-#endif
+      !Finalize the context:
+      CALL wxios_closedef()
+    ENDIF
 !$OMP END MASTER
 !$OMP BARRIER
@@ -176,10 +174,10 @@
 
 !XIOS
-#ifdef CPP_XIOS
-!$OMP MASTER
+IF (using_xios) THEN
+  !$OMP MASTER
     !Increment XIOS time
     CALL xios_update_calendar(itau)
-!$OMP END MASTER
-!$OMP BARRIER
+  !$OMP END MASTER
+  !$OMP BARRIER
 
     !Send fields to XIOS: (NB these fields must also be defined as
@@ -190,5 +188,5 @@
     CALL histwrite_phy("v",v)
     CALL histwrite_phy("ps",paprs(:,1))
-#endif
+ENDIF
 
 ! if lastcall, then it is time to write "restartphy.nc" file
Index: LMDZ6/trunk/libf/phylmd/Dust/phys_output_write_spl_mod.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/Dust/phys_output_write_spl_mod.F90	(revision 4618)
+++ LMDZ6/trunk/libf/phylmd/Dust/phys_output_write_spl_mod.F90	(revision 4619)
@@ -389,10 +389,7 @@
     USE iophy, ONLY: set_itau_iophy, histwrite_phy
     USE netcdf, ONLY: nf90_fill_real
-
-#ifdef CPP_XIOS
     ! ug Pour les sorties XIOS
-    USE xios, ONLY: xios_update_calendar
-    USE wxios, ONLY: wxios_closedef, missing_val
-#endif
+    USE lmdz_xios, ONLY: xios_update_calendar, using_xios
+    USE wxios, ONLY: wxios_closedef, missing_val_xios => missing_val
     USE phys_cal_mod, ONLY : mth_len
 
@@ -438,9 +435,12 @@
     INTEGER, DIMENSION(iim*jjmp1*klev) :: ndex3d
     REAL, PARAMETER :: dobson_u = 2.1415e-05 ! Dobson unit, in kg m-2
-!   REAL, PARAMETER :: missing_val=nf90_fill_real
-#ifndef CPP_XIOS
     REAL :: missing_val
-#endif
     REAL, PARAMETER :: un_jour=86400.
+
+    IF (using_xios) THEN
+      missing_val=missing_val_xios
+    ELSE
+      missing_val=nf90_fill_real
+    ENDIF
 
     ! On calcul le nouveau tau:
@@ -460,16 +460,17 @@
     ! ug la boucle qui suit ne sert qu'une fois, pour l'initialisation, sinon il n'y a toujours qu'un seul passage:
     DO iinit=1, iinitend
-#ifdef CPP_XIOS
-       !$OMP MASTER
-       IF (vars_defined) THEN
-          IF (prt_level >= 10) THEN
-             write(lunout,*)"phys_output_write: call xios_update_calendar, itau_w=",itau_w
-          ENDIF
-!          CALL xios_update_calendar(itau_w)
-          CALL xios_update_calendar(itap)
-       ENDIF
-       !$OMP END MASTER
-       !$OMP BARRIER
-#endif
+       IF (using_xios) THEN
+         !$OMP MASTER
+         IF (vars_defined) THEN
+            IF (prt_level >= 10) THEN
+               write(lunout,*)"phys_output_write: call xios_update_calendar, itau_w=",itau_w
+            ENDIF
+!           CALL xios_update_calendar(itau_w)
+            CALL xios_update_calendar(itap)
+         ENDIF
+         !$OMP END MASTER
+         !$OMP BARRIER
+       ENDIF !using_xios
+
        ! On procède à l'écriture ou à la définition des nombreuses variables:
 !!! Champs 1D !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -828,38 +829,37 @@
 
 #ifdef CPP_IOIPSL
-#ifndef CPP_XIOS
-  IF (.NOT.ok_all_xml) THEN
-       ! ATTENTION, LES ANCIENS HISTWRITE ONT ETES CONSERVES EN ATTENDANT MIEUX:
-       ! Champs interpolles sur des niveaux de pression
-       missing_val=missing_val_nf90
-       DO iff=1, nfiles
-          ll=0
-          DO k=1, nlevSTD
-             bb2=clevSTD(k) 
-             IF (bb2.EQ."850".OR.bb2.EQ."700".OR. &
-                  bb2.EQ."500".OR.bb2.EQ."200".OR. &
-                  bb2.EQ."100".OR. &
-                  bb2.EQ."50".OR.bb2.EQ."10") THEN
-
-                ! a refaire correctement !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-                ll=ll+1
-                CALL histwrite_phy(o_uSTDlevs(ll),uwriteSTD(:,k,iff), iff)
-                CALL histwrite_phy(o_vSTDlevs(ll),vwriteSTD(:,k,iff), iff)
-                CALL histwrite_phy(o_wSTDlevs(ll),wwriteSTD(:,k,iff), iff)
-                CALL histwrite_phy(o_zSTDlevs(ll),phiwriteSTD(:,k,iff), iff)
-                CALL histwrite_phy(o_qSTDlevs(ll),qwriteSTD(:,k,iff), iff)
-                CALL histwrite_phy(o_tSTDlevs(ll),twriteSTD(:,k,iff), iff)
-
-             ENDIF !(bb2.EQ."850".OR.bb2.EQ."700".OR.
-          ENDDO
-       ENDDO
-  ENDIF
+  IF (.NOT. using_xios) THEN
+    IF (.NOT.ok_all_xml) THEN
+         ! ATTENTION, LES ANCIENS HISTWRITE ONT ETES CONSERVES EN ATTENDANT MIEUX:
+         ! Champs interpolles sur des niveaux de pression
+         DO iff=1, nfiles
+           ll=0
+            DO k=1, nlevSTD
+               bb2=clevSTD(k) 
+               IF (bb2.EQ."850".OR.bb2.EQ."700".OR. &
+                    bb2.EQ."500".OR.bb2.EQ."200".OR. &
+                    bb2.EQ."100".OR. &
+                    bb2.EQ."50".OR.bb2.EQ."10") THEN
+
+                  ! a refaire correctement !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+                  ll=ll+1
+                  CALL histwrite_phy(o_uSTDlevs(ll),uwriteSTD(:,k,iff), iff)
+                  CALL histwrite_phy(o_vSTDlevs(ll),vwriteSTD(:,k,iff), iff)
+                  CALL histwrite_phy(o_wSTDlevs(ll),wwriteSTD(:,k,iff), iff)
+                  CALL histwrite_phy(o_zSTDlevs(ll),phiwriteSTD(:,k,iff), iff)
+                  CALL histwrite_phy(o_qSTDlevs(ll),qwriteSTD(:,k,iff), iff)
+                  CALL histwrite_phy(o_tSTDlevs(ll),twriteSTD(:,k,iff), iff)
+
+               ENDIF !(bb2.EQ."850".OR.bb2.EQ."700".OR.
+            ENDDO
+         ENDDO
+    ENDIF
+  ENDIF !.NOT.using_xios
 #endif
-#endif
-
-#ifdef CPP_XIOS
-  IF (ok_all_xml) THEN
-!XIOS  CALL xios_get_field_attr("u850",default_value=missing_val)
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+  IF (using_xios) THEN
+    IF (ok_all_xml) THEN
+  !XIOS  CALL xios_get_field_attr("u850",default_value=missing_val)
+  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
           ll=0
           DO k=1, nlevSTD
@@ -878,6 +878,6 @@
              ENDIF !(bb2.EQ."850".OR.bb2.EQ."700".OR.
           ENDDO
-  ENDIF
-#endif
+    ENDIF
+  ENDIF !using_xios
        IF (vars_defined) THEN
           DO i=1, klon
@@ -1471,9 +1471,9 @@
 !!!!!!!!!!!! Sorties niveaux de pression NMC !!!!!!!!!!!!!!!!!!!!
 #ifdef CPP_IOIPSL
-#ifndef CPP_XIOS
-  IF (.NOT.ok_all_xml) THEN 
-       ! ATTENTION, LES ANCIENS HISTWRITE ONT ETES CONSERVES EN ATTENDANT MIEUX:
-       ! Champs interpolles sur des niveaux de pression
-       missing_val=missing_val_nf90
+
+  IF (.NOT. using_xios) THEN
+    IF (.NOT.ok_all_xml) THEN 
+         ! ATTENTION, LES ANCIENS HISTWRITE ONT ETES CONSERVES EN ATTENDANT MIEUX:
+         ! Champs interpolles sur des niveaux de pression
        DO iff=7, nfiles-1 !--here we deal with files 7,8 and 9
 
@@ -1539,8 +1539,9 @@
           CALL histwrite_phy(o_TxT,T2sumSTD(:,:,iff-6),iff)
        ENDDO !nfiles
+    ENDIF
   ENDIF
 #endif
-#endif
-#ifdef CPP_XIOS
+
+IF (using_xios) THEN
   IF (ok_all_xml) THEN 
 !      DO iff=7, nfiles
@@ -1607,6 +1608,6 @@
           CALL histwrite_phy(o_TxT,T2STD(:,:))
 !      ENDDO !nfiles
-  ENDIF
-#endif
+    ENDIF
+  ENDIF !using_xios
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            itr = 0
@@ -1651,8 +1652,6 @@
           ENDDO !  iff
 #endif
-#ifdef CPP_XIOS
           !On finalise l'initialisation:
-          CALL wxios_closedef()
-#endif
+          IF (using_xios) CALL wxios_closedef()
 
           !$OMP END MASTER
Index: LMDZ6/trunk/libf/phylmd/cosp/cosp_output_mod.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/cosp/cosp_output_mod.F90	(revision 4618)
+++ LMDZ6/trunk/libf/phylmd/cosp/cosp_output_mod.F90	(revision 4619)
@@ -235,9 +235,6 @@
   USE time_phylmdz_mod, ONLY: day_ref, annee_ref, day_ini, start_time, itau_phy
   USE print_control_mod, ONLY: lunout
-
-#ifdef CPP_XIOS
-    ! ug Pour les sorties XIOS
-    USE wxios
-#endif
+  ! ug Pour les sorties XIOS
+  USE wxios
 
   IMPLICIT NONE
@@ -263,11 +260,9 @@
 !!! Variables d'entree
 
-#ifdef CPP_XIOS
-    ! ug Variables utilisées pour récupérer le calendrier pour xios
-    INTEGER :: x_an, x_mois, x_jour
-    REAL :: x_heure
-    INTEGER :: ini_an, ini_mois, ini_jour
-    REAL :: ini_heure
-#endif
+  ! ug Variables utilisées pour récupérer le calendrier pour xios
+  INTEGER :: x_an, x_mois, x_jour
+  REAL :: x_heure
+  INTEGER :: ini_an, ini_mois, ini_jour
+  REAL :: ini_heure
 
     WRITE(lunout,*) 'Debut cosp_output_mod.F90'
@@ -316,39 +311,39 @@
     CALL ymds2ju(annee_ref, 1, day_ini, start_time, zjulian_start)
 
-#ifdef CPP_XIOS
+    IF (using_xios) THEN
     
-! recuperer la valeur indefine Xios
-!    CALL xios_get_field_attr("clcalipso",default_value=Cosp_fill_value)
-!         Cosp_fill_value=missing_val
-          Cosp_fill_value=0.
-         print*,'Cosp_fill_value=',Cosp_fill_value
-!    if (use_vgrid) then
-!      print*,'vgrid%Nlvgrid, vgrid%z = ',vgrid%Nlvgrid, vgrid%z
-        CALL wxios_add_vaxis("height", vgrid%Nlvgrid, vgrid%z)
-     print*,'wxios_add_vaxis '
-!    else
-!         WRITE(lunout,*) 'wxios_add_vaxis "presnivs", vgrid%Nlvgrid ',vgrid%Nlvgrid
-!        CALL wxios_add_vaxis("presnivs", vgrid%Nlvgrid, presnivs)
-!    endif
-    WRITE(lunout,*) 'wxios_add_vaxis height_mlev, Nlevlmdz ',Nlevlmdz
-    CALL wxios_add_vaxis("height_mlev", Nlevlmdz, vgrid%mz)
-    WRITE(lunout,*) 'wxios_add_vaxis sza, PARASOL_NREFL ',PARASOL_NREFL
-    CALL wxios_add_vaxis("sza", PARASOL_NREFL, PARASOL_SZA)
-    WRITE(lunout,*) 'wxios_add_vaxis pressure2 ',7
-    CALL wxios_add_vaxis("pressure2", 7, ISCCP_PC)
-    WRITE(lunout,*) 'wxios_add_vaxis column ',Ncolumns
-    CALL wxios_add_vaxis("column", Ncolumns, column_ax)
-
-! AI nov 2015
-   CALL wxios_add_vaxis("temp", LIDAR_NTEMP, LIDAR_PHASE_TEMP)
-   CALL wxios_add_vaxis("cth", MISR_N_CTH, MISR_CTH)
-   CALL wxios_add_vaxis("dbze", DBZE_BINS, dbze_ax) 
-   CALL wxios_add_vaxis("scatratio", SR_BINS, sratio_ax)
-   CALL wxios_add_vaxis("ReffIce", numMODISReffIceBins, reffICE_binCenters)
-   CALL wxios_add_vaxis("ReffLiq", numMODISReffLiqBins, reffLIQ_binCenters)
-   print*,'reffICE_binCenters=',reffICE_binCenters
-   CALL wxios_add_vaxis("tau", 7, ISCCP_TAU)
-
-#endif
+  ! recuperer la valeur indefine Xios
+  !    CALL xios_get_field_attr("clcalipso",default_value=Cosp_fill_value)
+  !         Cosp_fill_value=missing_val
+            Cosp_fill_value=0.
+           print*,'Cosp_fill_value=',Cosp_fill_value
+  !    if (use_vgrid) then
+  !      print*,'vgrid%Nlvgrid, vgrid%z = ',vgrid%Nlvgrid, vgrid%z
+          CALL wxios_add_vaxis("height", vgrid%Nlvgrid, vgrid%z)
+       print*,'wxios_add_vaxis '
+  !    else
+  !         WRITE(lunout,*) 'wxios_add_vaxis "presnivs", vgrid%Nlvgrid ',vgrid%Nlvgrid
+  !        CALL wxios_add_vaxis("presnivs", vgrid%Nlvgrid, presnivs)
+  !    endif
+      WRITE(lunout,*) 'wxios_add_vaxis height_mlev, Nlevlmdz ',Nlevlmdz
+      CALL wxios_add_vaxis("height_mlev", Nlevlmdz, vgrid%mz)
+      WRITE(lunout,*) 'wxios_add_vaxis sza, PARASOL_NREFL ',PARASOL_NREFL
+      CALL wxios_add_vaxis("sza", PARASOL_NREFL, PARASOL_SZA)
+      WRITE(lunout,*) 'wxios_add_vaxis pressure2 ',7
+      CALL wxios_add_vaxis("pressure2", 7, ISCCP_PC)
+      WRITE(lunout,*) 'wxios_add_vaxis column ',Ncolumns
+      CALL wxios_add_vaxis("column", Ncolumns, column_ax)
+
+  ! AI nov 2015
+     CALL wxios_add_vaxis("temp", LIDAR_NTEMP, LIDAR_PHASE_TEMP)
+     CALL wxios_add_vaxis("cth", MISR_N_CTH, MISR_CTH)
+     CALL wxios_add_vaxis("dbze", DBZE_BINS, dbze_ax) 
+     CALL wxios_add_vaxis("scatratio", SR_BINS, sratio_ax)
+     CALL wxios_add_vaxis("ReffIce", numMODISReffIceBins, reffICE_binCenters)
+     CALL wxios_add_vaxis("ReffLiq", numMODISReffLiqBins, reffLIQ_binCenters)
+     print*,'reffICE_binCenters=',reffICE_binCenters
+     CALL wxios_add_vaxis("tau", 7, ISCCP_TAU)
+
+  ENDIF
    
     zdtimemoy_cosp = freq_COSP         ! Frequence ou l on moyenne
@@ -363,10 +358,10 @@
 !                    nhoricosp(iff),cosp_nidfiles(iff)
 
-#ifdef CPP_XIOS
-        IF (.not. ok_all_xml) then
-         WRITE(lunout,*) 'wxios_add_file ',cosp_outfilenames(iff)
-         CALL wxios_add_file(cosp_outfilenames(iff),chfreq(iff),10)
-        ENDIF
-#endif
+         IF (using_xios) THEN
+           IF (.not. ok_all_xml) then
+             WRITE(lunout,*) 'wxios_add_file ',cosp_outfilenames(iff)
+             CALL wxios_add_file(cosp_outfilenames(iff),chfreq(iff),10)
+           ENDIF
+         ENDIF
 
 #ifndef CPP_IOIPSL_NO_OUTPUT 
Index: LMDZ6/trunk/libf/phylmd/cosp/cosp_output_write_mod.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/cosp/cosp_output_write_mod.F90	(revision 4618)
+++ LMDZ6/trunk/libf/phylmd/cosp/cosp_output_write_mod.F90	(revision 4619)
@@ -26,9 +26,6 @@
     USE time_phylmdz_mod, ONLY: itau_phy, start_time, day_step_phy
     USE print_control_mod, ONLY: lunout,prt_level
-
-#ifdef CPP_XIOS
     USE wxios, only: wxios_closedef
-    USE xios, only: xios_update_calendar, xios_field_is_active
-#endif
+    USE lmdz_xios, only: xios_update_calendar, xios_field_is_active, using_xios
   IMPLICIT NONE  
 !!! Variables d'entree
@@ -58,9 +55,9 @@
   real, dimension(Npoints,MISR_N_CTH,7) :: tmp_fi4da_misr
 
-#ifdef CPP_XIOS
-  missing_val=missing_cosp
-#else
-  missing_val=0.
-#endif
+  IF (using_xios) THEN
+    missing_val=missing_cosp
+  ELSE
+    missing_val=0.
+  ENDIF
 
   Nlevout = vgrid%Nlvgrid
@@ -90,5 +87,5 @@
 !   endif
 
-!!#ifdef CPP_XIOS
+!!IF (using_xios) THEN
 ! !$OMP MASTER
 !IF (cosp_varsdefined) THEN
@@ -101,5 +98,5 @@
 !  !$OMP END MASTER
 !  !$OMP BARRIER
-!!#endif
+!!ENDIF
 
 !!!! Sorties Calipso
@@ -163,23 +160,24 @@
    if (cfg%Lproftemp) CALL histwrite3d_cosp(o_proftemp,stlidar%proftemp,nvert)                    !TIBO
 
-#ifdef CPP_XIOS
-   do icl=1,SR_BINS
-      tmp_fi4da_cfadL(:,:,icl)=stlidar%cfad_sr(:,icl,:)
-   enddo
-!   if (cfg%LcfadLidarsr532) CALL histwrite4d_cosp(o_cfad_lidarsr532,stlidar%cfad_sr)
-   if (cfg%LcfadLidarsr532) CALL histwrite4d_cosp(o_cfad_lidarsr532,tmp_fi4da_cfadL)
-   if (cfg%LprofSR) CALL histwrite4d_cosp(o_profSR,stlidar%profSR)                              !TIBO
-#else
-   if (cfg%LcfadLidarsr532) then
+   IF (using_xios) THEN
      do icl=1,SR_BINS
-        CALL histwrite3d_cosp(o_cfad_lidarsr532,stlidar%cfad_sr(:,icl,:),nvert,icl)
+        tmp_fi4da_cfadL(:,:,icl)=stlidar%cfad_sr(:,icl,:)
      enddo
-   endif
-   if (cfg%LprofSR) then
-     do icl=1,Ncolumns                                                              !TIBO
-        CALL histwrite3d_cosp(o_profSR,stlidar%profSR(:,icl,:),nvert,icl)           !TIBO
-     enddo                                                                          !TIBO
-   endif
-#endif
+  !   if (cfg%LcfadLidarsr532) CALL histwrite4d_cosp(o_cfad_lidarsr532,stlidar%cfad_sr)
+     if (cfg%LcfadLidarsr532) CALL histwrite4d_cosp(o_cfad_lidarsr532,tmp_fi4da_cfadL)
+     if (cfg%LprofSR) CALL histwrite4d_cosp(o_profSR,stlidar%profSR)                              !TIBO
+   ELSE
+     if (cfg%LcfadLidarsr532) then
+       do icl=1,SR_BINS
+          CALL histwrite3d_cosp(o_cfad_lidarsr532,stlidar%cfad_sr(:,icl,:),nvert,icl)
+       enddo
+     endif
+     if (cfg%LprofSR) then
+       do icl=1,Ncolumns                                                              !TIBO
+          CALL histwrite3d_cosp(o_profSR,stlidar%profSR(:,icl,:),nvert,icl)           !TIBO
+       enddo                                                                          !TIBO
+      endif
+   ENDIF
+
    if (cfg%LparasolRefl) CALL histwrite3d_cosp(o_parasol_refl,stlidar%parasolrefl,nvertp)
 
@@ -201,13 +199,13 @@
   endif
 
-#ifdef CPP_XIOS
-   if (cfg%Latb532) CALL histwrite4d_cosp(o_atb532,sglidar%beta_tot)
-#else
-   if (cfg%Latb532) then  
-     do icl=1,Ncolumns 
-        CALL histwrite3d_cosp(o_atb532,sglidar%beta_tot(:,icl,:),nvertmcosp,icl)
-     enddo
-   endif 
-#endif
+   IF (using_xios) THEN
+     if (cfg%Latb532) CALL histwrite4d_cosp(o_atb532,sglidar%beta_tot)
+   ELSE
+     if (cfg%Latb532) then  
+       do icl=1,Ncolumns 
+          CALL histwrite3d_cosp(o_atb532,sglidar%beta_tot(:,icl,:),nvertmcosp,icl)
+       enddo
+     endif 
+   ENDIF
 
    if (cfg%LlidarBetaMol532) CALL histwrite3d_cosp(o_beta_mol532,sglidar%beta_mol,nvertmcosp) 
@@ -219,23 +217,23 @@
 
    where(stradar%cfad_ze == R_UNDEF) stradar%cfad_ze = missing_val
-#ifdef CPP_XIOS
-   do icl=1,DBZE_BINS
-     tmp_fi4da_cfadR(:,:,icl)=stradar%cfad_ze(:,icl,:)
-   enddo
-   if (cfg%Ldbze94) CALL histwrite4d_cosp(o_dbze94,sgradar%Ze_tot)
-!   if (cfg%LcfadDbze94) CALL histwrite4d_cosp(o_cfadDbze94,stradar%cfad_ze)
-   if (cfg%LcfadDbze94) CALL histwrite4d_cosp(o_cfadDbze94,tmp_fi4da_cfadR)
-#else
-   if (cfg%Ldbze94) then
-    do icl=1,Ncolumns
-       CALL histwrite3d_cosp(o_dbze94,sgradar%Ze_tot(:,icl,:),nvert,icl)
-    enddo
-   endif
-   if (cfg%LcfadDbze94) then
-    do icl=1,DBZE_BINS
-    CALL histwrite3d_cosp(o_cfadDbze94,stradar%cfad_ze(:,icl,:),nvert,icl)
-    enddo
-   endif
-#endif
+   IF (using_xios) THEN
+     do icl=1,DBZE_BINS
+       tmp_fi4da_cfadR(:,:,icl)=stradar%cfad_ze(:,icl,:)
+     enddo
+     if (cfg%Ldbze94) CALL histwrite4d_cosp(o_dbze94,sgradar%Ze_tot)
+  !  if (cfg%LcfadDbze94) CALL histwrite4d_cosp(o_cfadDbze94,stradar%cfad_ze)
+     if (cfg%LcfadDbze94) CALL histwrite4d_cosp(o_cfadDbze94,tmp_fi4da_cfadR)
+   ELSE
+     if (cfg%Ldbze94) then
+       do icl=1,Ncolumns
+         CALL histwrite3d_cosp(o_dbze94,sgradar%Ze_tot(:,icl,:),nvert,icl)
+       enddo
+     endif
+     if (cfg%LcfadDbze94) then
+       do icl=1,DBZE_BINS
+         CALL histwrite3d_cosp(o_cfadDbze94,stradar%cfad_ze(:,icl,:),nvert,icl)
+       enddo
+     endif
+   ENDIF
  endif
 ! endif pour radar
@@ -264,13 +262,13 @@
 
    CALL histwrite2d_cosp(o_sunlit,gbx%sunlit)
-#ifdef CPP_XIOS
-  if (cfg%Lclisccp) CALL histwrite4d_cosp(o_clisccp2,isccp%fq_isccp)
-#else
-   if (cfg%Lclisccp) then
-     do icl=1,7
-       CALL histwrite3d_cosp(o_clisccp2,isccp%fq_isccp(:,icl,:),nvertisccp,icl) 
-     enddo
-   endif
-#endif
+   IF (using_xios) THEN
+     if (cfg%Lclisccp) CALL histwrite4d_cosp(o_clisccp2,isccp%fq_isccp)
+   ELSE
+     if (cfg%Lclisccp) then
+       do icl=1,7
+         CALL histwrite3d_cosp(o_clisccp2,isccp%fq_isccp(:,icl,:),nvertisccp,icl) 
+       enddo
+     endif
+   ENDIF
 
    if (cfg%Lboxtauisccp) CALL histwrite3d_cosp(o_boxtauisccp,isccp%boxtau,nvertcol)
@@ -288,17 +286,17 @@
    where(misr%fq_MISR == R_UNDEF) misr%fq_MISR = missing_val
 
-#ifdef CPP_XIOS
-   do icl=1,MISR_N_CTH
-      tmp_fi4da_misr(:,icl,:)=misr%fq_MISR(:,:,icl)
-   enddo
-!   if (cfg%LclMISR) CALL histwrite4d_cosp(o_clMISR,misr%fq_MISR)
-   if (cfg%LclMISR) CALL histwrite4d_cosp(o_clMISR,tmp_fi4da_misr)
-#else
-   if (cfg%LclMISR) then
-    do icl=1,7 
-      CALL histwrite3d_cosp(o_clMISR,misr%fq_MISR(:,icl,:),nvertmisr,icl)
-    enddo
-   endif
-#endif
+   IF (using_xios) THEN
+     do icl=1,MISR_N_CTH
+        tmp_fi4da_misr(:,icl,:)=misr%fq_MISR(:,:,icl)
+     enddo
+  !   if (cfg%LclMISR) CALL histwrite4d_cosp(o_clMISR,misr%fq_MISR)
+     if (cfg%LclMISR) CALL histwrite4d_cosp(o_clMISR,tmp_fi4da_misr)
+   ELSE
+     if (cfg%LclMISR) then
+      do icl=1,7 
+        CALL histwrite3d_cosp(o_clMISR,misr%fq_MISR(:,icl,:),nvertmisr,icl)
+      enddo
+     endif
+   ENDIF
  endif
 ! endif pour Misr
@@ -365,14 +363,14 @@
           modis%Optical_Thickness_vs_Cloud_Top_Pressure = missing_val
 
-#ifdef CPP_XIOS
-   if (cfg%Lclmodis) CALL histwrite4d_cosp(o_clmodis,modis%Optical_Thickness_vs_Cloud_Top_Pressure)
-#else
-  if (cfg%Lclmodis) then
-   do icl=1,7
-   CALL histwrite3d_cosp(o_clmodis, &
-     modis%Optical_Thickness_vs_Cloud_Top_Pressure(:,icl,:),nvertisccp,icl)           
-   enddo
-  endif 
-#endif
+   IF (using_xios) THEN
+     if (cfg%Lclmodis) CALL histwrite4d_cosp(o_clmodis,modis%Optical_Thickness_vs_Cloud_Top_Pressure)
+   ELSE
+     if (cfg%Lclmodis) then
+       do icl=1,7
+         CALL histwrite3d_cosp(o_clmodis, &
+         modis%Optical_Thickness_vs_Cloud_Top_Pressure(:,icl,:),nvertisccp,icl)           
+       enddo
+      endif 
+   ENDIF
 
     where(modis%Optical_Thickness_vs_ReffIce == R_UNDEF) &
@@ -382,21 +380,21 @@
           modis%Optical_Thickness_vs_ReffLiq = missing_val
 
-#ifdef CPP_XIOS
-  if (cfg%Lcrimodis) CALL histwrite4d_cosp(o_crimodis,modis%Optical_Thickness_vs_ReffIce)
-  if (cfg%Lcrlmodis) CALL histwrite4d_cosp(o_crlmodis,modis%Optical_Thickness_vs_ReffLiq)
-#else
-  if (cfg%Lcrimodis) then
-    do icl=1,7
-     CALL histwrite3d_cosp(o_crimodis, &
-          modis%Optical_Thickness_vs_ReffIce(:,icl,:),nvertReffIce,icl)
-    enddo
-  endif
-  if (cfg%Lcrlmodis) then
-    do icl=1,7 
-     CALL histwrite3d_cosp(o_crlmodis, &
-          modis%Optical_Thickness_vs_ReffLiq(:,icl,:),nvertReffLiq,icl)
-    enddo
-  endif 
-#endif
+   IF (using_xios) THEN
+     if (cfg%Lcrimodis) CALL histwrite4d_cosp(o_crimodis,modis%Optical_Thickness_vs_ReffIce)
+     if (cfg%Lcrlmodis) CALL histwrite4d_cosp(o_crlmodis,modis%Optical_Thickness_vs_ReffLiq)
+   ELSE
+     if (cfg%Lcrimodis) then
+       do icl=1,7
+         CALL histwrite3d_cosp(o_crimodis, &
+            modis%Optical_Thickness_vs_ReffIce(:,icl,:),nvertReffIce,icl)
+       enddo
+     endif
+     if (cfg%Lcrlmodis) then
+       do icl=1,7 
+         CALL histwrite3d_cosp(o_crlmodis, &
+            modis%Optical_Thickness_vs_ReffLiq(:,icl,:),nvertReffLiq,icl)
+       enddo
+     endif 
+   ENDIF
  endif !modis
 
@@ -410,9 +408,4 @@
             ENDDO !  iff
 #endif
-! Fermeture dans phys_output_write
-!#ifdef CPP_XIOS
-            !On finalise l'initialisation:
-            !CALL wxios_closedef()
-!#endif
 
 !$OMP END MASTER
@@ -451,7 +444,5 @@
     USE mod_grid_phy_lmdz, ONLY: nbp_lon
     USE print_control_mod, ONLY: lunout,prt_level
-#ifdef CPP_XIOS
-  USE wxios
-#endif
+    USE wxios
 
     IMPLICIT NONE
@@ -485,15 +476,15 @@
     ENDIF
 
-#ifdef CPP_XIOS
-     IF (.not. ok_all_xml) then
-       IF ( var%cles(iff) ) THEN
-         if (prt_level >= 10) then
-              WRITE(lunout,*)'Appel wxios_add_field_to_file var%name =',var%name 
-         endif
-        CALL wxios_add_field_to_file(var%name, 2, cosp_nidfiles(iff), cosp_outfilenames(iff), &
+    IF (using_xios) THEN
+      IF (.not. ok_all_xml) then
+        IF ( var%cles(iff) ) THEN
+          if (prt_level >= 10) then
+            WRITE(lunout,*)'Appel wxios_add_field_to_file var%name =',var%name 
+          endif
+          CALL wxios_add_field_to_file(var%name, 2, cosp_nidfiles(iff), cosp_outfilenames(iff), &
                                      var%description, var%unit, 1, typeecrit)
-       ENDIF
-     ENDIF
-#endif
+        ENDIF
+      ENDIF
+    ENDIF
 
 #ifndef CPP_IOIPSL_NO_OUTPUT 
@@ -514,9 +505,5 @@
     USE mod_grid_phy_lmdz, ONLY: nbp_lon
     USE print_control_mod, ONLY: lunout,prt_level
-
-#ifdef CPP_XIOS
-  USE wxios
-#endif
-
+    USE wxios
 
     IMPLICIT NONE
@@ -591,5 +578,5 @@
     ENDIF
 
-#ifdef CPP_XIOS
+    IF (using_xios) THEN
       IF (.not. ok_all_xml) then
         IF ( var%cles(iff) ) THEN
@@ -601,5 +588,5 @@
         ENDIF
       ENDIF
-#endif
+    ENDIF
 
 #ifndef CPP_IOIPSL_NO_OUTPUT
@@ -621,8 +608,5 @@
   USE mod_grid_phy_lmdz, ONLY: nbp_lon
   USE print_control_mod, ONLY: lunout,prt_level
-
-#ifdef CPP_XIOS
-  USE xios, only: xios_send_field
-#endif
+  USE lmdz_xios, only: xios_send_field, using_xios
 
   IMPLICIT NONE
@@ -672,6 +656,6 @@
         CALL histwrite(cosp_nidfiles(iff),var%name,itau_iocosp,Field2d,nbp_lon*jj_nb,index2d) 
 #endif
-                deallocate(index2d)
-#ifdef CPP_XIOS
+            deallocate(index2d)
+            IF (using_xios) THEN
               IF (.not. ok_all_xml) then
                  if (firstx) then
@@ -683,9 +667,9 @@
                  endif
               ENDIF
-#endif
-           ENDIF
+            ENDIF
+          ENDIF
       ENDDO 
 
-#ifdef CPP_XIOS
+    IF (using_xios) THEN
       IF (ok_all_xml) THEN
         if (prt_level >= 1) then
@@ -694,5 +678,5 @@
        CALL xios_send_field(var%name, Field2d)
       ENDIF
-#endif
+    ENDIF
 
 !$OMP END MASTER   
@@ -710,9 +694,5 @@
   USE mod_grid_phy_lmdz, ONLY: nbp_lon
   USE print_control_mod, ONLY: lunout,prt_level
-
-#ifdef CPP_XIOS
-  USE xios, only: xios_send_field
-#endif
-
+  USE lmdz_xios, only: xios_send_field, using_xios
 
   IMPLICIT NONE
@@ -776,5 +756,5 @@
 #endif
 
-#ifdef CPP_XIOS
+        IF (using_xios) THEN
           IF (.not. ok_all_xml) then
            IF (firstx) THEN
@@ -784,14 +764,15 @@
            ENDIF
           ENDIF
-#endif
+        ENDIF
          deallocate(index3d)
         ENDIF
       ENDDO
-#ifdef CPP_XIOS
+
+  IF (using_xios) THEN
     IF (ok_all_xml) THEN
      CALL xios_send_field(nom, Field3d(:,:,1:nlev))
      IF (prt_level >= 1) WRITE(lunout,*)'xios_send_field ',var%name
     ENDIF
-#endif
+  ENDIF
 
 !$OMP END MASTER   
@@ -809,9 +790,5 @@
   USE mod_grid_phy_lmdz, ONLY: nbp_lon
   USE print_control_mod, ONLY: lunout,prt_level
-
-#ifdef CPP_XIOS
-  USE xios, only: xios_send_field
-#endif
-
+  USE lmdz_xios, only: xios_send_field, using_xios
 
   IMPLICIT NONE
@@ -842,10 +819,10 @@
     CALL grid1Dto2D_mpi(buffer_omp,field4d)
 
-#ifdef CPP_XIOS
+   IF (using_xios) THEN
 !    IF (ok_all_xml) THEN
      CALL xios_send_field(var%name, Field4d(:,:,1:nlev,1:nlev2))
      IF (prt_level >= 1) WRITE(lunout,*)'xios_send_field ',var%name
 !    ENDIF
-#endif
+   ENDIF
 
 !$OMP END MASTER   
Index: LMDZ6/trunk/libf/phylmd/cosp/cosp_read_otputkeys.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/cosp/cosp_read_otputkeys.F90	(revision 4618)
+++ LMDZ6/trunk/libf/phylmd/cosp/cosp_read_otputkeys.F90	(revision 4619)
@@ -226,8 +226,5 @@
 
  SUBROUTINE READ_COSP_OUTPUT_NL(itap,cosp_nl,cfg)
-
-#ifdef CPP_XIOS
-    USE xios, ONLY: xios_field_is_active
-#endif
+    USE lmdz_xios, ONLY: xios_field_is_active, using_xios
   implicit none
   character(len=*),intent(in) :: cosp_nl
@@ -746,12 +743,8 @@
     USE MOD_COSP_CONSTANTS
     USE MOD_COSP_TYPES
-#ifdef CPP_XIOS
-    USE xios, ONLY: xios_field_is_active
-#endif
+    USE lmdz_xios, ONLY: xios_field_is_active,using_xios
   implicit none
   type(cosp_config),intent(out) :: cfg
   integer :: i
-
-#ifdef CPP_XIOS
 
  logical :: Lradar_sim,Llidar_sim,Lisccp_sim,Lmodis_sim,Lmisr_sim,Lrttov_sim, Lstats, &
@@ -776,7 +769,9 @@
   character(len=32) :: out_list(N_OUT_LIST)
 
-  do i=1,N_OUT_LIST
-    cfg%out_list(i)=''
-  enddo
+  IF (using_xios) THEN
+    
+    do i=1,N_OUT_LIST
+      cfg%out_list(i)=''
+    enddo
 
     LcfadDbze94   = .false.
@@ -1232,5 +1227,5 @@
   cfg%Lrttov_sim = Lrttov_sim
 
-#endif
+ ENDIF ! using_xios
 
   END SUBROUTINE read_xiosfieldactive
Index: LMDZ6/trunk/libf/phylmd/cosp/mod_cosp.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/cosp/mod_cosp.F90	(revision 4618)
+++ LMDZ6/trunk/libf/phylmd/cosp/mod_cosp.F90	(revision 4619)
@@ -23,5 +23,5 @@
 ! OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-INCLUDE "cosp_defs.h"
+#include "cosp_defs.h"
 MODULE MOD_COSP
   USE MOD_COSP_TYPES
Index: LMDZ6/trunk/libf/phylmd/cosp/mod_cosp_constants.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/cosp/mod_cosp_constants.F90	(revision 4618)
+++ LMDZ6/trunk/libf/phylmd/cosp/mod_cosp_constants.F90	(revision 4619)
@@ -33,5 +33,5 @@
 ! 
 
-INCLUDE "cosp_defs.h"
+#INCLUDE "cosp_defs.h"
 MODULE MOD_COSP_CONSTANTS
     IMPLICIT NONE
Index: LMDZ6/trunk/libf/phylmd/cosp/mod_cosp_simulator.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/cosp/mod_cosp_simulator.F90	(revision 4618)
+++ LMDZ6/trunk/libf/phylmd/cosp/mod_cosp_simulator.F90	(revision 4619)
@@ -31,5 +31,5 @@
 !
 
-INCLUDE "cosp_defs.h" 
+#include "cosp_defs.h" 
 MODULE MOD_COSP_SIMULATOR
   USE MOD_COSP_CONSTANTS, ONLY: I_RADAR, I_LIDAR, I_ISCCP, I_MISR, I_MODIS, &
Index: LMDZ6/trunk/libf/phylmd/cosp/mod_cosp_stats.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/cosp/mod_cosp_stats.F90	(revision 4618)
+++ LMDZ6/trunk/libf/phylmd/cosp/mod_cosp_stats.F90	(revision 4619)
@@ -36,5 +36,5 @@
 !
 !
-INCLUDE "cosp_defs.h" 
+#include "cosp_defs.h" 
 MODULE MOD_COSP_STATS
   USE MOD_COSP_CONSTANTS
Index: LMDZ6/trunk/libf/phylmd/cosp/phys_cosp.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/cosp/phys_cosp.F90	(revision 4618)
+++ LMDZ6/trunk/libf/phylmd/cosp/phys_cosp.F90	(revision 4619)
@@ -73,5 +73,5 @@
 
 !! AI rajouter
-  INCLUDE "cosp_defs.h" 
+#include "cosp_defs.h" 
   USE MOD_COSP_CONSTANTS
   USE MOD_COSP_TYPES
@@ -84,7 +84,5 @@
   use cosp_output_write_mod
 !  use MOD_COSP_Modis_Simulator, only : cosp_modis 
-#ifdef CPP_XIOS
-    USE xios, ONLY: xios_field_is_active
-#endif
+  USE lmdz_xios, ONLY: xios_field_is_active, using_xios
   use cosp_read_otputkeys
 
@@ -183,9 +181,10 @@
 
 ! Clefs Outputs initialisation
-#ifdef CPP_XIOS
-  call cosp_outputkeys_init(cfg)
-#else
-  call read_cosp_output_nl(itap,cosp_output_nl,cfg)
-#endif
+  IF (using_xios) THEN
+    call cosp_outputkeys_init(cfg)
+  ELSE
+    call read_cosp_output_nl(itap,cosp_output_nl,cfg)
+  ENDIF
+
 !!!   call cosp_outputkeys_test(cfg)
   print*,' Cles des differents simulateurs cosp a itap :',itap
@@ -203,7 +202,7 @@
 !!! Ici on modifie les cles logiques pour les outputs selon les champs actives dans les .xml
   if ((itap.gt.1).and.(first_write))then
-#ifdef CPP_XIOS
-    call read_xiosfieldactive(cfg)
-#endif
+   
+    IF (using_xios) call read_xiosfieldactive(cfg)
+  
     first_write=.false.
 
Index: LMDZ6/trunk/libf/phylmd/cosp2/cosp_interface_v1p4.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/cosp2/cosp_interface_v1p4.F90	(revision 4618)
+++ LMDZ6/trunk/libf/phylmd/cosp2/cosp_interface_v1p4.F90	(revision 4619)
@@ -30,5 +30,5 @@
 ! May 2015 - D. Swales - Original version
 ! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-INCLUDE "cosp_defs.h"
+#include "cosp_defs.h"
 MODULE MOD_COSP_INTERFACE_v1p4
   use COSP_KINDS,          only: wp,dp
Index: LMDZ6/trunk/libf/phylmd/cosp2/cosp_output_mod.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/cosp2/cosp_output_mod.F90	(revision 4618)
+++ LMDZ6/trunk/libf/phylmd/cosp2/cosp_output_mod.F90	(revision 4619)
@@ -246,9 +246,6 @@
   USE time_phylmdz_mod, ONLY: day_ref, annee_ref, day_ini, start_time, itau_phy
   USE print_control_mod, ONLY: lunout
-
-#ifdef CPP_XIOS
     ! ug Pour les sorties XIOS
-    USE wxios
-#endif
+  USE wxios
 
   IMPLICIT NONE
@@ -275,11 +272,9 @@
 !!! Variables d'entree
 
-#ifdef CPP_XIOS
-    ! ug Variables utilisées pour récupérer le calendrier pour xios
-    INTEGER :: x_an, x_mois, x_jour
-    REAL :: x_heure
-    INTEGER :: ini_an, ini_mois, ini_jour
-    REAL :: ini_heure
-#endif
+! ug Variables utilisées pour récupérer le calendrier pour xios
+  INTEGER :: x_an, x_mois, x_jour
+  REAL :: x_heure
+  INTEGER :: ini_an, ini_mois, ini_jour
+  REAL :: ini_heure
 
     WRITE(lunout,*) 'Debut cosp_output_mod.F90'
@@ -328,59 +323,59 @@
     CALL ymds2ju(annee_ref, 1, day_ini, start_time, zjulian_start)
 
-#ifdef CPP_XIOS
-    
-! recuperer la valeur indefine Xios
-!    CALL xios_get_field_attr("clcalipso",default_value=Cosp_fill_value)
-!         Cosp_fill_value=missing_val
-          Cosp_fill_value=0.
-         print*,'Cosp_fill_value=',Cosp_fill_value
-
-    CALL wxios_add_vaxis("height", vgrid%Nlvgrid, vgrid%z)
-    print*,'wxios_add_vaxis vgrid%Nlvgrid, vgrid%z',vgrid%Nlvgrid,vgrid%z
-
-    WRITE(lunout,*) 'wxios_add_vaxis height_mlev, Nlevlmdz vgrid%mz ', &
+    IF (using_xios) THEN
+
+  ! recuperer la valeur indefine Xios
+  !    CALL xios_get_field_attr("clcalipso",default_value=Cosp_fill_value)
+  !         Cosp_fill_value=missing_val
+      Cosp_fill_value=0.
+      print*,'Cosp_fill_value=',Cosp_fill_value
+
+      CALL wxios_add_vaxis("height", vgrid%Nlvgrid, vgrid%z)
+      print*,'wxios_add_vaxis vgrid%Nlvgrid, vgrid%z',vgrid%Nlvgrid,vgrid%z
+
+      WRITE(lunout,*) 'wxios_add_vaxis height_mlev, Nlevlmdz vgrid%mz ', &
                      Nlevlmdz,vgrid%mz
-    CALL wxios_add_vaxis("height_mlev", Nlevlmdz, vgrid%mz)
-
-    WRITE(lunout,*) 'wxios_add_vaxis sza, PARASOL_NREFL ', &
-                     PARASOL_NREFL, PARASOL_SZA
-    CALL wxios_add_vaxis("sza", PARASOL_NREFL, PARASOL_SZA)
-
-    WRITE(lunout,*) 'wxios_add_vaxis pressure2 ',7,pres_binCenters
-    CALL wxios_add_vaxis("pressure2", 7, pres_binCenters)
-
-    WRITE(lunout,*) 'wxios_add_vaxis column ',Ncolumns,column_ax
-    CALL wxios_add_vaxis("column", Ncolumns, column_ax)
-
-   WRITE(lunout,*) 'wxios_add_vaxis temp LIDAR_NTEMP, LIDAR_PHASE_TEMP ', &
+      CALL wxios_add_vaxis("height_mlev", Nlevlmdz, vgrid%mz)
+
+      WRITE(lunout,*) 'wxios_add_vaxis sza, PARASOL_NREFL ', &
+                       PARASOL_NREFL, PARASOL_SZA
+      CALL wxios_add_vaxis("sza", PARASOL_NREFL, PARASOL_SZA)
+
+      WRITE(lunout,*) 'wxios_add_vaxis pressure2 ',7,pres_binCenters
+      CALL wxios_add_vaxis("pressure2", 7, pres_binCenters)
+
+      WRITE(lunout,*) 'wxios_add_vaxis column ',Ncolumns,column_ax
+      CALL wxios_add_vaxis("column", Ncolumns, column_ax)
+
+      WRITE(lunout,*) 'wxios_add_vaxis temp LIDAR_NTEMP, LIDAR_PHASE_TEMP ', &
                     LIDAR_NTEMP, LIDAR_PHASE_TEMP
-   CALL wxios_add_vaxis("temp", LIDAR_NTEMP, LIDAR_PHASE_TEMP)
-
-   WRITE(lunout,*) 'wxios_add_vaxis cth16 numMISRHgtBins, misr_histHgtCenters ', & 
-                    numMISRHgtBins, misr_histHgtCenters 
-   CALL wxios_add_vaxis("cth16", numMISRHgtBins, misr_histHgtCenters)
-
-   WRITE(lunout,*) 'wxios_add_vaxis dbze DBZE_BINS, dbze_ax ', &
-                    DBZE_BINS, dbze_ax
-   CALL wxios_add_vaxis("dbze", DBZE_BINS, dbze_ax) 
-
-   WRITE(lunout,*) 'wxios_add_vaxis scatratio SR_BINS, sratio_ax', &
-                   SR_BINS, sratio_ax
-   CALL wxios_add_vaxis("scatratio", SR_BINS, sratio_ax)
-
-   WRITE(lunout,*) 'wxios_add_vaxis ReffIce numMODISReffIceBins, &
-                   reffICE_binCenters',numMODISReffIceBins, reffICE_binCenters
-   CALL wxios_add_vaxis("ReffIce", numMODISReffIceBins, reffICE_binCenters)
-
-   WRITE(lunout,*) 'wxios_add_vaxis ReffLiq numMODISReffLiqBins, &
+      CALL wxios_add_vaxis("temp", LIDAR_NTEMP, LIDAR_PHASE_TEMP)
+
+      WRITE(lunout,*) 'wxios_add_vaxis cth16 numMISRHgtBins, misr_histHgtCenters ', & 
+                      numMISRHgtBins, misr_histHgtCenters 
+      CALL wxios_add_vaxis("cth16", numMISRHgtBins, misr_histHgtCenters)
+
+      WRITE(lunout,*) 'wxios_add_vaxis dbze DBZE_BINS, dbze_ax ', &
+                       DBZE_BINS, dbze_ax
+      CALL wxios_add_vaxis("dbze", DBZE_BINS, dbze_ax) 
+
+      WRITE(lunout,*) 'wxios_add_vaxis scatratio SR_BINS, sratio_ax', &
+                     SR_BINS, sratio_ax
+      CALL wxios_add_vaxis("scatratio", SR_BINS, sratio_ax)
+
+      WRITE(lunout,*) 'wxios_add_vaxis ReffIce numMODISReffIceBins, &
+                     reffICE_binCenters',numMODISReffIceBins, reffICE_binCenters
+     CALL wxios_add_vaxis("ReffIce", numMODISReffIceBins, reffICE_binCenters)
+
+     WRITE(lunout,*) 'wxios_add_vaxis ReffLiq numMODISReffLiqBins, &
                     reffLIQ_binCenters', numMODISReffLiqBins, reffLIQ_binCenters
-   CALL wxios_add_vaxis("ReffLiq", numMODISReffLiqBins, reffLIQ_binCenters)
-
-   WRITE(lunout,*) 'wxios_add_vaxis 7, tau_binCenters', &
-                    7, tau_binCenters
-   CALL wxios_add_vaxis("tau", 7, tau_binCenters)
-
-#endif
-   
+     CALL wxios_add_vaxis("ReffLiq", numMODISReffLiqBins, reffLIQ_binCenters)
+
+     WRITE(lunout,*) 'wxios_add_vaxis 7, tau_binCenters', &
+                      7, tau_binCenters
+     CALL wxios_add_vaxis("tau", 7, tau_binCenters)
+
+  ENDIF
+
     zdtimemoy_cosp = freq_COSP         ! Frequence ou l on moyenne
 
@@ -394,10 +389,10 @@
 !                    nhoricosp(iff),cosp_nidfiles(iff)
 
-#ifdef CPP_XIOS
-        IF (.not. ok_all_xml) then
-         WRITE(lunout,*) 'wxios_add_file ',cosp_outfilenames(iff)
-         CALL wxios_add_file(cosp_outfilenames(iff),chfreq(iff),10)
+        IF(using_xios) THEN
+          IF (.not. ok_all_xml) then
+           WRITE(lunout,*) 'wxios_add_file ',cosp_outfilenames(iff)
+           CALL wxios_add_file(cosp_outfilenames(iff),chfreq(iff),10)
+          ENDIF
         ENDIF
-#endif
 
 #ifndef CPP_IOIPSL_NO_OUTPUT 
Index: LMDZ6/trunk/libf/phylmd/cosp2/cosp_output_write_mod.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/cosp2/cosp_output_write_mod.F90	(revision 4618)
+++ LMDZ6/trunk/libf/phylmd/cosp2/cosp_output_write_mod.F90	(revision 4619)
@@ -36,9 +36,6 @@
     USE time_phylmdz_mod, ONLY: itau_phy, start_time, day_step_phy
     USE print_control_mod, ONLY: lunout,prt_level
-
-#ifdef CPP_XIOS
     USE wxios, only: wxios_closedef
-    USE xios, only: xios_update_calendar, xios_field_is_active
-#endif
+    USE lmdz_xios, only: xios_update_calendar, xios_field_is_active, using_xios
   IMPLICIT NONE  
 !!! Variables d'entree
@@ -68,9 +65,9 @@
   real, dimension(Npoints,numMISRHgtBins,7) :: tmp_fi4da_misr
 
-#ifdef CPP_XIOS
-  missing_val=missing_cosp
-#else
-  missing_val=0.
-#endif
+  IF (using_xios) THEN
+    missing_val=missing_cosp
+  ELSE
+    missing_val=0.
+  ENDIF
 
   Nlevout = vgrid%Nlvgrid
@@ -100,5 +97,5 @@
 !   endif
 
-!!#ifdef CPP_XIOS
+!! IF (using_xios) THEN
 ! !$OMP MASTER
 !IF (cosp_varsdefined) THEN
@@ -111,5 +108,5 @@
 !  !$OMP END MASTER
 !  !$OMP BARRIER
-!!#endif
+!! ENDIF
 
 !!!! Sorties Calipso
@@ -173,17 +170,18 @@
 !   if (cfg%Lproftemp) CALL histwrite3d_cosp(o_proftemp,stlidar%proftemp,nvert)                    !TIBO
 
-#ifdef CPP_XIOS
-   do icl=1,SR_BINS
+  IF (using_xios) THEN
+
+    do icl=1,SR_BINS
       tmp_fi4da_cfadL(:,:,icl)=stlidar%cfad_sr(:,icl,:)
-   enddo
+    enddo
 !   if (cfg%LcfadLidarsr532) CALL histwrite4d_cosp(o_cfad_lidarsr532,stlidar%cfad_sr)
-   if (cfg%LcfadLidarsr532) CALL histwrite4d_cosp(o_cfad_lidarsr532,tmp_fi4da_cfadL)
+    if (cfg%LcfadLidarsr532) CALL histwrite4d_cosp(o_cfad_lidarsr532,tmp_fi4da_cfadL)
 !   if (cfg%LprofSR) CALL histwrite4d_cosp(o_profSR,stlidar%profSR)                              !TIBO
-#else
-   if (cfg%LcfadLidarsr532) then
-     do icl=1,SR_BINS
+  ELSE
+    if (cfg%LcfadLidarsr532) then
+      do icl=1,SR_BINS
         CALL histwrite3d_cosp(o_cfad_lidarsr532,stlidar%cfad_sr(:,icl,:),nvert,icl)
-     enddo
-   endif
+      enddo
+    endif
 !   if (cfg%LprofSR) then
 !     do icl=1,Ncolumns                                                              !TIBO
@@ -191,5 +189,6 @@
 !     enddo                                                                          !TIBO
 !   endif
-#endif
+  ENDIF
+
    if (cfg%LparasolRefl) CALL histwrite3d_cosp(o_parasol_refl,stlidar%parasolrefl,nvertp)
 
@@ -211,13 +210,14 @@
   endif
 
-#ifdef CPP_XIOS
-   if (cfg%Latb532) CALL histwrite4d_cosp(o_atb532,sglidar%beta_tot)
-#else
-   if (cfg%Latb532) then  
-     do icl=1,Ncolumns 
+  IF (using_xios) THEN
+
+    if (cfg%Latb532) CALL histwrite4d_cosp(o_atb532,sglidar%beta_tot)
+  ELSE
+    if (cfg%Latb532) then  
+      do icl=1,Ncolumns 
         CALL histwrite3d_cosp(o_atb532,sglidar%beta_tot(:,icl,:),nvertmcosp,icl)
-     enddo
-   endif 
-#endif
+      enddo
+    endif 
+  ENDIF
 
    if (cfg%LlidarBetaMol532) CALL histwrite3d_cosp(o_beta_mol532,sglidar%beta_mol,nvertmcosp) 
@@ -229,23 +229,23 @@
 
    where(stradar%cfad_ze == R_UNDEF) stradar%cfad_ze = missing_val
-#ifdef CPP_XIOS
-   do icl=1,DBZE_BINS
-     tmp_fi4da_cfadR(:,:,icl)=stradar%cfad_ze(:,icl,:)
-   enddo
-   if (cfg%Ldbze94) CALL histwrite4d_cosp(o_dbze94,sgradar%Ze_tot)
-!   if (cfg%LcfadDbze94) CALL histwrite4d_cosp(o_cfadDbze94,stradar%cfad_ze)
-   if (cfg%LcfadDbze94) CALL histwrite4d_cosp(o_cfadDbze94,tmp_fi4da_cfadR)
-#else
-   if (cfg%Ldbze94) then
-    do icl=1,Ncolumns
-       CALL histwrite3d_cosp(o_dbze94,sgradar%Ze_tot(:,icl,:),nvert,icl)
+  IF (using_xios) THEN
+    do icl=1,DBZE_BINS
+      tmp_fi4da_cfadR(:,:,icl)=stradar%cfad_ze(:,icl,:)
     enddo
-   endif
-   if (cfg%LcfadDbze94) then
-    do icl=1,DBZE_BINS
-    CALL histwrite3d_cosp(o_cfadDbze94,stradar%cfad_ze(:,icl,:),nvert,icl)
-    enddo
-   endif
-#endif
+    if (cfg%Ldbze94) CALL histwrite4d_cosp(o_dbze94,sgradar%Ze_tot)
+ !   if (cfg%LcfadDbze94) CALL histwrite4d_cosp(o_cfadDbze94,stradar%cfad_ze)
+    if (cfg%LcfadDbze94) CALL histwrite4d_cosp(o_cfadDbze94,tmp_fi4da_cfadR)
+  ELSE
+    if (cfg%Ldbze94) then
+      do icl=1,Ncolumns
+        CALL histwrite3d_cosp(o_dbze94,sgradar%Ze_tot(:,icl,:),nvert,icl)
+      enddo
+     endif
+     if (cfg%LcfadDbze94) then
+       do icl=1,DBZE_BINS
+         CALL histwrite3d_cosp(o_cfadDbze94,stradar%cfad_ze(:,icl,:),nvert,icl)
+       enddo
+     endif
+  ENDIF
  endif
 ! endif pour radar
@@ -273,14 +273,14 @@
   where(isccp%boxptop == R_UNDEF) isccp%boxptop = missing_val 
 
-   CALL histwrite2d_cosp(o_sunlit,gbx%sunlit)
-#ifdef CPP_XIOS
-  if (cfg%Lclisccp) CALL histwrite4d_cosp(o_clisccp2,isccp%fq_isccp)
-#else
-   if (cfg%Lclisccp) then
-     do icl=1,7
-       CALL histwrite3d_cosp(o_clisccp2,isccp%fq_isccp(:,icl,:),nvertisccp,icl) 
-     enddo
-   endif
-#endif
+  CALL histwrite2d_cosp(o_sunlit,gbx%sunlit)
+  IF (using_xios) THEN
+    if (cfg%Lclisccp) CALL histwrite4d_cosp(o_clisccp2,isccp%fq_isccp)
+  ELSE
+    if (cfg%Lclisccp) then
+      do icl=1,7
+        CALL histwrite3d_cosp(o_clisccp2,isccp%fq_isccp(:,icl,:),nvertisccp,icl) 
+      enddo
+    endif
+  ENDIF
 
    if (cfg%Lboxtauisccp) CALL histwrite3d_cosp(o_boxtauisccp,isccp%boxtau,nvertcol)
@@ -298,17 +298,17 @@
    where(misr%fq_MISR == R_UNDEF) misr%fq_MISR = missing_val
 
-#ifdef CPP_XIOS
-   do icl=1,numMISRHgtBins
+  IF (using_xios) THEN
+    do icl=1,numMISRHgtBins
       tmp_fi4da_misr(:,icl,:)=misr%fq_MISR(:,:,icl)
-   enddo
+    enddo
 !   if (cfg%LclMISR) CALL histwrite4d_cosp(o_clMISR,misr%fq_MISR)
-   if (cfg%LclMISR) CALL histwrite4d_cosp(o_clMISR,tmp_fi4da_misr)
-#else
-   if (cfg%LclMISR) then
-    do icl=1,7 
-      CALL histwrite3d_cosp(o_clMISR,misr%fq_MISR(:,icl,:),nvertmisr,icl)
-    enddo
-   endif
-#endif
+    if (cfg%LclMISR) CALL histwrite4d_cosp(o_clMISR,tmp_fi4da_misr)
+  ELSE
+    if (cfg%LclMISR) then
+      do icl=1,7 
+        CALL histwrite3d_cosp(o_clMISR,misr%fq_MISR(:,icl,:),nvertmisr,icl)
+      enddo
+     endif
+  ENDIF
  endif
 ! endif pour Misr
@@ -375,14 +375,14 @@
           modis%Optical_Thickness_vs_Cloud_Top_Pressure = missing_val
 
-#ifdef CPP_XIOS
-   if (cfg%Lclmodis) CALL histwrite4d_cosp(o_clmodis,modis%Optical_Thickness_vs_Cloud_Top_Pressure)
-#else
-  if (cfg%Lclmodis) then
-   do icl=1,7
-   CALL histwrite3d_cosp(o_clmodis, &
-     modis%Optical_Thickness_vs_Cloud_Top_Pressure(:,icl,:),nvertisccp,icl)           
-   enddo
-  endif 
-#endif
+  IF (using_xios) THEN
+    if (cfg%Lclmodis) CALL histwrite4d_cosp(o_clmodis,modis%Optical_Thickness_vs_Cloud_Top_Pressure)
+  ELSE
+    if (cfg%Lclmodis) then
+     do icl=1,7
+       CALL histwrite3d_cosp(o_clmodis, &
+         modis%Optical_Thickness_vs_Cloud_Top_Pressure(:,icl,:),nvertisccp,icl)           
+     enddo
+    endif 
+  ENDIF
 
     where(modis%Optical_Thickness_vs_ReffIce == R_UNDEF) &
@@ -392,21 +392,21 @@
           modis%Optical_Thickness_vs_ReffLiq = missing_val
 
-#ifdef CPP_XIOS
-  if (cfg%Lclmodis) CALL histwrite4d_cosp(o_crimodis,modis%Optical_Thickness_vs_ReffIce)
-  if (cfg%Lclmodis) CALL histwrite4d_cosp(o_crlmodis,modis%Optical_Thickness_vs_ReffLiq)
-#else
-  if (cfg%Lclmodis) then
-    do icl=1,7
-     CALL histwrite3d_cosp(o_crimodis, &
-          modis%Optical_Thickness_vs_ReffIce(:,icl,:),nvertReffIce,icl)
-    enddo
-  endif
-  if (cfg%Lclmodis) then
-    do icl=1,7 
-     CALL histwrite3d_cosp(o_crlmodis, &
-          modis%Optical_Thickness_vs_ReffLiq(:,icl,:),nvertReffLiq,icl)
-    enddo
-  endif 
-#endif
+    IF (using_xios) THEN
+      if (cfg%Lclmodis) CALL histwrite4d_cosp(o_crimodis,modis%Optical_Thickness_vs_ReffIce)
+      if (cfg%Lclmodis) CALL histwrite4d_cosp(o_crlmodis,modis%Optical_Thickness_vs_ReffLiq)
+    ELSE
+      if (cfg%Lclmodis) then
+        do icl=1,7
+          CALL histwrite3d_cosp(o_crimodis, &
+             modis%Optical_Thickness_vs_ReffIce(:,icl,:),nvertReffIce,icl)
+        enddo
+      endif
+      if (cfg%Lclmodis) then
+        do icl=1,7 
+           CALL histwrite3d_cosp(o_crlmodis, &
+              modis%Optical_Thickness_vs_ReffLiq(:,icl,:),nvertReffLiq,icl)
+        enddo
+      endif 
+  ENDIF !using_xios
  endif !modis
 
@@ -421,8 +421,8 @@
 #endif
 ! Fermeture dans phys_output_write
-!#ifdef CPP_XIOS
+! IF (using_xios) THEN
             !On finalise l'initialisation:
             !CALL wxios_closedef()
-!#endif
+! ELSE
 
 !$OMP END MASTER
@@ -461,7 +461,5 @@
     USE mod_grid_phy_lmdz, ONLY: nbp_lon
     USE print_control_mod, ONLY: lunout,prt_level
-#ifdef CPP_XIOS
-  USE wxios
-#endif
+    USE wxios
 
     IMPLICIT NONE
@@ -495,5 +493,5 @@
     ENDIF
 
-#ifdef CPP_XIOS
+    IF (using_xios) THEN
      IF (.not. ok_all_xml) then
        IF ( var%cles(iff) ) THEN
@@ -505,5 +503,5 @@
        ENDIF
      ENDIF
-#endif
+    ENDIF
 
 #ifndef CPP_IOIPSL_NO_OUTPUT 
@@ -524,9 +522,5 @@
     USE mod_grid_phy_lmdz, ONLY: nbp_lon
     USE print_control_mod, ONLY: lunout,prt_level
-
-#ifdef CPP_XIOS
-  USE wxios
-#endif
-
+    USE wxios
 
     IMPLICIT NONE
@@ -601,5 +595,5 @@
     ENDIF
 
-#ifdef CPP_XIOS
+    IF (using_xios) THEN
       IF (.not. ok_all_xml) then
         IF ( var%cles(iff) ) THEN
@@ -611,5 +605,5 @@
         ENDIF
       ENDIF
-#endif
+    ENDIF
 
 #ifndef CPP_IOIPSL_NO_OUTPUT
@@ -631,8 +625,5 @@
   USE mod_grid_phy_lmdz, ONLY: nbp_lon
   USE print_control_mod, ONLY: lunout,prt_level
-
-#ifdef CPP_XIOS
-  USE xios, only: xios_send_field
-#endif
+  USE lmdz_xios, only: xios_send_field, using_xios
 
   IMPLICIT NONE
@@ -677,5 +668,5 @@
       firstx=.true.
       DO iff=1, 3
-           IF (var%cles(iff) .AND. cosp_outfilekeys(iff)) THEN
+          IF (var%cles(iff) .AND. cosp_outfilekeys(iff)) THEN
                 ALLOCATE(index2d(nbp_lon*jj_nb))
 #ifndef CPP_IOIPSL_NO_OUTPUT
@@ -683,5 +674,5 @@
 #endif
                 deallocate(index2d)
-#ifdef CPP_XIOS
+            IF (using_xios) THEN
               IF (.not. ok_all_xml) then
                  if (firstx) then
@@ -693,9 +684,9 @@
                  endif
               ENDIF
-#endif
-           ENDIF
+            ENDIF
+          ENDIF
       ENDDO 
 
-#ifdef CPP_XIOS
+    IF (using_xios) THEN
       IF (ok_all_xml) THEN
         if (prt_level >= 1) then
@@ -704,5 +695,5 @@
        CALL xios_send_field(var%name, Field2d)
       ENDIF
-#endif
+    ENDIF
 
 !$OMP END MASTER   
@@ -720,9 +711,5 @@
   USE mod_grid_phy_lmdz, ONLY: nbp_lon
   USE print_control_mod, ONLY: lunout,prt_level
-
-#ifdef CPP_XIOS
-  USE xios, only: xios_send_field
-#endif
-
+  USE lmdz_xios, only: xios_send_field, using_xios
 
   IMPLICIT NONE
@@ -786,5 +773,5 @@
 #endif
 
-#ifdef CPP_XIOS
+       IF (using_xios) THEN
           IF (.not. ok_all_xml) then
            IF (firstx) THEN
@@ -794,14 +781,15 @@
            ENDIF
           ENDIF
-#endif
+        ENDIF
          deallocate(index3d)
         ENDIF
       ENDDO
-#ifdef CPP_XIOS
-    IF (ok_all_xml) THEN
-     CALL xios_send_field(nom, Field3d(:,:,1:nlev))
-     IF (prt_level >= 1) WRITE(lunout,*)'xios_send_field ',var%name
+
+    IF (using_xios) THEN
+      IF (ok_all_xml) THEN
+        CALL xios_send_field(nom, Field3d(:,:,1:nlev))
+        IF (prt_level >= 1) WRITE(lunout,*)'xios_send_field ',var%name
+      ENDIF
     ENDIF
-#endif
 
 !$OMP END MASTER   
@@ -819,9 +807,5 @@
   USE mod_grid_phy_lmdz, ONLY: nbp_lon
   USE print_control_mod, ONLY: lunout,prt_level
-
-#ifdef CPP_XIOS
-  USE xios, only: xios_send_field
-#endif
-
+  USE lmdz_xios, only: xios_send_field, using_xios
 
   IMPLICIT NONE
@@ -852,10 +836,10 @@
     CALL grid1Dto2D_mpi(buffer_omp,field4d)
 
-#ifdef CPP_XIOS
+  IF (using_xios) THEN
 !    IF (ok_all_xml) THEN
      CALL xios_send_field(var%name, Field4d(:,:,1:nlev,1:nlev2))
      IF (prt_level >= 1) WRITE(lunout,*)'xios_send_field ',var%name
 !    ENDIF
-#endif
+  ENDIF
 
 !$OMP END MASTER   
Index: LMDZ6/trunk/libf/phylmd/cosp2/cosp_read_otputkeys.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/cosp2/cosp_read_otputkeys.F90	(revision 4618)
+++ LMDZ6/trunk/libf/phylmd/cosp2/cosp_read_otputkeys.F90	(revision 4619)
@@ -228,8 +228,5 @@
 
  SUBROUTINE READ_COSP_OUTPUT_NL(itap,cosp_nl,cfg)
-
-#ifdef CPP_XIOS
-    USE xios, ONLY: xios_field_is_active
-#endif
+  USE lmdz_xios, ONLY: xios_field_is_active, using_xios
   implicit none
   character(len=*),intent(in) :: cosp_nl
@@ -755,12 +752,8 @@
 !    USE MOD_COSP_CONSTANTS
 !    USE MOD_COSP_TYPES
-#ifdef CPP_XIOS
-    USE xios, ONLY: xios_field_is_active
-#endif
+     USE lmdz_xios, ONLY: xios_field_is_active, using_xios
   implicit none
   type(cosp_config),intent(out) :: cfg
   integer :: i
-
-#ifdef CPP_XIOS
 
  logical :: Lradar_sim,Llidar_sim,Lparasol_sim,Lisccp_sim,Lmodis_sim,Lmisr_sim,Lrttov_sim, Lstats, &
@@ -784,4 +777,6 @@
         
   character(len=32) :: out_list(78)
+
+ IF (using_xios) THEN
 
   do i=1,78
@@ -1249,5 +1244,5 @@
  endif 
 
-#endif
+ ENDIF !using_xios
 
   END SUBROUTINE read_xiosfieldactive
Index: LMDZ6/trunk/libf/phylmd/cosp2/phys_cosp2.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/cosp2/phys_cosp2.F90	(revision 4618)
+++ LMDZ6/trunk/libf/phylmd/cosp2/phys_cosp2.F90	(revision 4619)
@@ -83,4 +83,5 @@
   use cosp_output_mod
   use cosp_output_write_mod
+  USE lmdz_xios, ONLY : using_xios
 !  use MOD_COSP_Modis_Simulator, only : cosp_modis 
 !  use mod_cosp_config, only : vgrid_zl,vgrid_zu,vgrid_z
@@ -245,9 +246,9 @@
 
 ! Clefs Outputs initialisation
-#ifdef CPP_XIOS
+ IF (using_xios) THEN
   call cosp_outputkeys_init(cfg)
-#else
+ ELSE
    call read_cosp_output_nl(itap,cosp_output_nl,cfg)
-#endif
+ ENDIF
 
   print*,' Cles des differents simulateurs cosp a itap :',itap
@@ -265,7 +266,6 @@
 !!! Ici on modifie les cles logiques pour les outputs selon les champs actives dans les .xml
   if ((itap.gt.1).and.(first_write))then
-#ifdef CPP_XIOS
-    call read_xiosfieldactive(cfg)
-#endif
+    
+    IF (using_xios)   call read_xiosfieldactive(cfg)
     first_write=.false.
 
Index: LMDZ6/trunk/libf/phylmd/cospv2/lmdz_cosp_interface.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/cospv2/lmdz_cosp_interface.F90	(revision 4618)
+++ LMDZ6/trunk/libf/phylmd/cospv2/lmdz_cosp_interface.F90	(revision 4619)
@@ -67,4 +67,5 @@
   use ioipsl
   use iophy
+  use lmdz_xios, ONLY : using_xios
   use lmdz_cosp_output_mod
   use lmdz_cosp_output_write_mod
@@ -262,9 +263,9 @@
 
 ! Clefs Outputs initialisation
-#ifdef CPP_XIOS
-  call cosp_outputkeys_init(cfg)
-#else
+ IF (using_xios) THEN
+   call cosp_outputkeys_init(cfg)
+ ELSE
    call read_cosp_output_nl(itap,cosp_output_nl,cfg)
-#endif
+ ENDIF
 
   print*,' Cles des differents simulateurs cosp a itap :',itap
@@ -278,29 +279,29 @@
     endif
 
-#ifdef CPP_XIOS
-   print*,'On passe par ifdef CPP_XIOS'
-#else
-if (cosp_init_flag .eq. 0) then
-
-    ! Initialize the distributional parameters for hydrometeors in radar simulator.
-    ! In COSPv1.4, this was declared in cosp_defs.f.
-    if (cloudsat_micro_scheme == 'MMF_v3.5_two_moment')  then
-       ldouble = .true. 
-       lsingle = .false.
+ IF (using_xios) THEN
+   print*,'On passe par using_xios'
+ ELSE
+   if (cosp_init_flag .eq. 0) then
+
+      ! Initialize the distributional parameters for hydrometeors in radar simulator.
+      ! In COSPv1.4, this was declared in cosp_defs.f.
+      if (cloudsat_micro_scheme == 'MMF_v3.5_two_moment')  then
+         ldouble = .true. 
+         lsingle = .false.
+      endif
+      call hydro_class_init(lsingle,ldouble,sd)
+      call quickbeam_optics_init()
+
+      print*,' just before call COSP_INIT, cosp_init_flag =', cosp_init_flag
+      call COSP_INIT(cfg%Lisccp, cfg%Lmodis, cfg%Lmisr, cfg%Lcloudsat, cfg%Lcalipso, &
+         cfg%LgrLidar532, cfg%Latlid, cfg%Lparasol, cfg%Lrttov,          &
+         cloudsat_radar_freq, cloudsat_k2, cloudsat_use_gas_abs,         &
+         cloudsat_do_ray, isccp_topheight, isccp_topheight_direction,    &
+         surface_radar, rcfg_cloudsat, use_vgrid_in, csat_vgrid_in,      &
+         niv_sorties, Nlevels, cloudsat_micro_scheme)
+      cosp_init_flag = 1
+      print*,' just after call COSP_INIT, cosp_init_flag =', cosp_init_flag
     endif
-    call hydro_class_init(lsingle,ldouble,sd)
-    call quickbeam_optics_init()
-
-  print*,' just before call COSP_INIT, cosp_init_flag =', cosp_init_flag
-  call COSP_INIT(cfg%Lisccp, cfg%Lmodis, cfg%Lmisr, cfg%Lcloudsat, cfg%Lcalipso, &
-        cfg%LgrLidar532, cfg%Latlid, cfg%Lparasol, cfg%Lrttov,          &
-        cloudsat_radar_freq, cloudsat_k2, cloudsat_use_gas_abs,         &
-        cloudsat_do_ray, isccp_topheight, isccp_topheight_direction,    &
-        surface_radar, rcfg_cloudsat, use_vgrid_in, csat_vgrid_in,      &
-        niv_sorties, Nlevels, cloudsat_micro_scheme)
-  cosp_init_flag = 1
- print*,' just after call COSP_INIT, cosp_init_flag =', cosp_init_flag
-endif
-#endif
+  ENDIF
 
   print*,'Fin lecture Namelists, debut_cosp =',debut_cosp
@@ -311,7 +312,5 @@
 !!! Ici on modifie les cles logiques pour les outputs selon les champs actives dans les .xml
   if ((itap.ge.1).and.(first_write))then
-#ifdef CPP_XIOS
-    call read_xiosfieldactive(cfg)
-#endif
+    IF (using_xios) call read_xiosfieldactive(cfg)
     first_write=.false.
 
Index: LMDZ6/trunk/libf/phylmd/cospv2/lmdz_cosp_output_mod.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/cospv2/lmdz_cosp_output_mod.F90	(revision 4618)
+++ LMDZ6/trunk/libf/phylmd/cospv2/lmdz_cosp_output_mod.F90	(revision 4619)
@@ -326,9 +326,6 @@
   USE time_phylmdz_mod, ONLY: day_ref, annee_ref, day_ini, start_time, itau_phy
   USE print_control_mod, ONLY: lunout
-
-#ifdef CPP_XIOS
-    ! ug Pour les sorties XIOS
-    USE wxios
-#endif
+  ! ug Pour les sorties XIOS
+  USE wxios
 
   IMPLICIT NONE
@@ -350,11 +347,9 @@
 !!! Variables d'entree
 
-#ifdef CPP_XIOS
-    ! ug Variables utilisées pour récupérer le calendrier pour xios
-    INTEGER :: x_an, x_mois, x_jour
-    REAL :: x_heure
-    INTEGER :: ini_an, ini_mois, ini_jour
-    REAL :: ini_heure
-#endif
+  ! ug Variables utilisées pour récupérer le calendrier pour xios
+  INTEGER :: x_an, x_mois, x_jour
+  REAL :: x_heure
+  INTEGER :: ini_an, ini_mois, ini_jour
+  REAL :: ini_heure
 
     WRITE(lunout,*) 'Debut lmdz_cosp_output_mod.F90'
@@ -401,9 +396,10 @@
     CALL ymds2ju(annee_ref, 1, day_ini, start_time, zjulian_start)
 
-#ifdef CPP_XIOS
+  IF (using_xios) THEN
+
     
-! recuperer la valeur indefine Xios
-!    CALL xios_get_field_attr("clcalipso",default_value=Cosp_fill_value)
-!         Cosp_fill_value=missing_val
+  ! recuperer la valeur indefine Xios
+  !    CALL xios_get_field_attr("clcalipso",default_value=Cosp_fill_value)
+  !         Cosp_fill_value=missing_val
           Cosp_fill_value=0.
          print*,'Cosp_fill_value=',Cosp_fill_value
@@ -426,33 +422,33 @@
     CALL wxios_add_vaxis("column", Ncolumns, column_ax)
 
-   WRITE(lunout,*) 'wxios_add_vaxis temp LIDAR_NTEMP, LIDAR_PHASE_TEMP ', &
-                    LIDAR_NTEMP, LIDAR_PHASE_TEMP
-   CALL wxios_add_vaxis("temp", LIDAR_NTEMP, LIDAR_PHASE_TEMP)
-
-   WRITE(lunout,*) 'wxios_add_vaxis cth16 numMISRHgtBins, misr_histHgtCenters ', & 
+    WRITE(lunout,*) 'wxios_add_vaxis temp LIDAR_NTEMP, LIDAR_PHASE_TEMP ', &
+                     LIDAR_NTEMP, LIDAR_PHASE_TEMP
+    CALL wxios_add_vaxis("temp", LIDAR_NTEMP, LIDAR_PHASE_TEMP)
+
+    WRITE(lunout,*) 'wxios_add_vaxis cth16 numMISRHgtBins, misr_histHgtCenters ', & 
                     numMISRHgtBins, misr_histHgtCenters 
-   CALL wxios_add_vaxis("cth", numMISRHgtBins, misr_histHgtCenters)
-
-   WRITE(lunout,*) 'wxios_add_vaxis dbze CLOUDSAT_DBZE_BINS, cloudsat_binCenters ', &
+    CALL wxios_add_vaxis("cth", numMISRHgtBins, misr_histHgtCenters)
+
+    WRITE(lunout,*) 'wxios_add_vaxis dbze CLOUDSAT_DBZE_BINS, cloudsat_binCenters ', &
                     CLOUDSAT_DBZE_BINS, cloudsat_binCenters
-   CALL wxios_add_vaxis("dbze", CLOUDSAT_DBZE_BINS, cloudsat_binCenters) 
-
-   WRITE(lunout,*) 'wxios_add_vaxis scatratio SR_BINS, calipso_binCenters', &
+    CALL wxios_add_vaxis("dbze", CLOUDSAT_DBZE_BINS, cloudsat_binCenters) 
+
+    WRITE(lunout,*) 'wxios_add_vaxis scatratio SR_BINS, calipso_binCenters', &
                    SR_BINS, calipso_binCenters
-   CALL wxios_add_vaxis("scatratio", SR_BINS, calipso_binCenters)
-
-   WRITE(lunout,*) 'wxios_add_vaxis ReffIce numMODISReffIceBins, &
+    CALL wxios_add_vaxis("scatratio", SR_BINS, calipso_binCenters)
+
+    WRITE(lunout,*) 'wxios_add_vaxis ReffIce numMODISReffIceBins, &
                    reffICE_binCenters',numMODISReffIceBins, reffICE_binCenters
-   CALL wxios_add_vaxis("ReffIce", numMODISReffIceBins, reffICE_binCenters)
-
-   WRITE(lunout,*) 'wxios_add_vaxis ReffLiq numMODISReffLiqBins, &
+    CALL wxios_add_vaxis("ReffIce", numMODISReffIceBins, reffICE_binCenters)
+
+    WRITE(lunout,*) 'wxios_add_vaxis ReffLiq numMODISReffLiqBins, &
                     reffLIQ_binCenters', numMODISReffLiqBins, reffLIQ_binCenters
-   CALL wxios_add_vaxis("ReffLiq", numMODISReffLiqBins, reffLIQ_binCenters)
-
-   WRITE(lunout,*) 'wxios_add_vaxis 7, tau_binCenters', &
+    CALL wxios_add_vaxis("ReffLiq", numMODISReffLiqBins, reffLIQ_binCenters)
+
+    WRITE(lunout,*) 'wxios_add_vaxis 7, tau_binCenters', &
                     7, tau_binCenters
-   CALL wxios_add_vaxis("tau", 7, tau_binCenters)
-
-#endif
+    CALL wxios_add_vaxis("tau", 7, tau_binCenters)
+
+  ENDIF
    
     zdtimemoy_cosp = freq_COSP         ! Frequence ou l on moyenne
@@ -467,10 +463,10 @@
 !                    nhoricosp(iff),cosp_nidfiles(iff)
 
-#ifdef CPP_XIOS
+ IF (using_xios) THEN
         IF (.not. ok_all_xml) then
          WRITE(lunout,*) 'wxios_add_file ',cosp_outfilenames(iff)
          CALL wxios_add_file(cosp_outfilenames(iff),chfreq(iff),10)
         ENDIF
-#endif
+ ENDIF
 
 #ifndef CPP_IOIPSL_NO_OUTPUT 
Index: LMDZ6/trunk/libf/phylmd/cospv2/lmdz_cosp_output_write_mod.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/cospv2/lmdz_cosp_output_write_mod.F90	(revision 4618)
+++ LMDZ6/trunk/libf/phylmd/cospv2/lmdz_cosp_output_write_mod.F90	(revision 4619)
@@ -42,5 +42,5 @@
 
     USE wxios, only: wxios_closedef
-    USE xios, only: xios_update_calendar, xios_field_is_active
+    USE lmdz_xios, only: xios_update_calendar, xios_field_is_active
   IMPLICIT NONE  
 !!! Variables d'entree
@@ -807,5 +807,5 @@
   USE print_control_mod, ONLY: lunout,prt_level
 
-  USE xios, only: xios_send_field
+  USE lmdz_xios, only: xios_send_field
 
   IMPLICIT NONE
@@ -889,5 +889,5 @@
   USE print_control_mod, ONLY: lunout,prt_level
 
-  USE xios, only: xios_send_field
+  USE lmdz_xios, only: xios_send_field
 
 
@@ -980,5 +980,5 @@
   USE print_control_mod, ONLY: lunout,prt_level
 
-  USE xios, only: xios_send_field
+  USE lmdz_xios, only: xios_send_field
 
 
Index: LMDZ6/trunk/libf/phylmd/cospv2/lmdz_cosp_read_outputkeys.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/cospv2/lmdz_cosp_read_outputkeys.F90	(revision 4618)
+++ LMDZ6/trunk/libf/phylmd/cospv2/lmdz_cosp_read_outputkeys.F90	(revision 4619)
@@ -422,8 +422,5 @@
 
  SUBROUTINE READ_COSP_OUTPUT_NL(itap,cosp_nl,cfg)
-
-#ifdef CPP_XIOS
-    USE xios, ONLY: xios_field_is_active
-#endif
+  USE lmdz_xios, ONLY: xios_field_is_active, using_xios
   implicit none
   character(len=*),intent(in) :: cosp_nl
@@ -1020,13 +1017,8 @@
 
  SUBROUTINE read_xiosfieldactive(cfg)
-
-#ifdef CPP_XIOS
-    USE xios, ONLY: xios_field_is_active
-#endif
+  USE lmdz_xios, ONLY: xios_field_is_active, using_xios
   implicit none
   type(cosp_config),intent(inout) :: cfg
   integer :: i
-
-#ifdef CPP_XIOS
 
 !COSPv2 local variables
@@ -1067,4 +1059,6 @@
         
   character(len=32) :: out_list(107)
+
+ IF (using_xios) THEN
 
   do i=1,107
@@ -1717,5 +1711,5 @@
  endif 
 
-#endif
+ ENDIF !using_xios
 
   END SUBROUTINE read_xiosfieldactive
Index: LMDZ6/trunk/libf/phylmd/create_etat0_limit_unstruct.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/create_etat0_limit_unstruct.F90	(revision 4618)
+++ LMDZ6/trunk/libf/phylmd/create_etat0_limit_unstruct.F90	(revision 4619)
@@ -10,6 +10,5 @@
   
   SUBROUTINE init_etat0_limit_unstruct
-#ifdef CPP_XIOS
-  USE xios, ONLY: xios_set_axis_attr, xios_set_fieldgroup_attr, &
+  USE lmdz_xios, ONLY: xios_set_axis_attr, xios_set_fieldgroup_attr, &
                   xios_set_filegroup_attr, xios_set_file_attr
   USE mod_phys_lmdz_para, ONLY: is_omp_master
@@ -49,9 +48,7 @@
       ENDIF  
 
-#endif
   END SUBROUTINE init_etat0_limit_unstruct
   
   SUBROUTINE create_etat0_limit_unstruct
-#ifdef CPP_XIOS
   USE mod_grid_phy_lmdz, ONLY: grid_type, unstructured
   USE create_etat0_unstruct_mod, ONLY: create_etat0_unstruct
@@ -62,5 +59,5 @@
   USE ioipsl_getin_p_mod, ONLY: getin_p
   USE dimphy, ONLY: klon
-  USE xios, ONLY: xios_context_finalize, xios_set_current_context, &
+  USE lmdz_xios, ONLY: xios_context_finalize, xios_set_current_context, &
                   xios_finalize
   USE print_control_mod, ONLY: lunout
@@ -109,5 +106,4 @@
       ENDIF
         
-#endif
   END SUBROUTINE create_etat0_limit_unstruct
   
Index: LMDZ6/trunk/libf/phylmd/create_etat0_unstruct.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/create_etat0_unstruct.F90	(revision 4618)
+++ LMDZ6/trunk/libf/phylmd/create_etat0_unstruct.F90	(revision 4619)
@@ -9,6 +9,5 @@
   
   SUBROUTINE init_create_etat0_unstruct
-#ifdef CPP_XIOS
-  USE xios
+  USE lmdz_xios
   USE netcdf
   USE mod_phys_lmdz_para
@@ -39,6 +38,4 @@
     ENDIF
 
-#endif
-  
   END SUBROUTINE init_create_etat0_unstruct
   
@@ -46,6 +43,5 @@
   SUBROUTINE create_etat0_unstruct
   USE dimphy
-#ifdef CPP_XIOS
-  USE xios
+  USE lmdz_xios
   USE infotrac_phy
   USE fonte_neige_mod
@@ -269,5 +265,4 @@
     CALL phyredem( "startphy.nc" )
 
-#endif
   END SUBROUTINE create_etat0_unstruct
 
Index: LMDZ6/trunk/libf/phylmd/create_limit_unstruct.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/create_limit_unstruct.F90	(revision 4618)
+++ LMDZ6/trunk/libf/phylmd/create_limit_unstruct.F90	(revision 4619)
@@ -10,6 +10,5 @@
   SUBROUTINE create_limit_unstruct
   USE dimphy
-#ifdef CPP_XIOS
-  USE xios
+  USE lmdz_xios
   USE ioipsl,             ONLY : ioget_year_len
   USE time_phylmdz_mod, ONLY : annee_ref
@@ -175,5 +174,4 @@
       CALL xios_send_field("rug_limout", rugos_year_mpi) 
     ENDIF
-#endif
   END SUBROUTINE create_limit_unstruct
   
Index: LMDZ6/trunk/libf/phylmd/iophy.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/iophy.F90	(revision 4618)
+++ LMDZ6/trunk/libf/phylmd/iophy.F90	(revision 4619)
@@ -16,13 +16,7 @@
 !$OMP THREADPRIVATE(itau_iophy)
 
-#ifdef CPP_XIOS
   INTERFACE histwrite_phy
     MODULE PROCEDURE histwrite2d_phy,histwrite3d_phy,histwrite2d_phy_old,histwrite3d_phy_old,histwrite2d_xios,histwrite3d_xios,histwrite0d_xios
   END INTERFACE
-#else
-  INTERFACE histwrite_phy
-    MODULE PROCEDURE histwrite2d_phy,histwrite3d_phy,histwrite2d_phy_old,histwrite3d_phy_old
-  END INTERFACE
-#endif
 
   INTERFACE histbeg_phy_all
@@ -52,7 +46,5 @@
     USE ioipsl, ONLY: flio_dom_set
 #endif
-#ifdef CPP_XIOS
-  use wxios, ONLY: wxios_domain_param, wxios_domain_param_unstructured, wxios_context_init
-#endif
+  use wxios, ONLY: wxios_domain_param, wxios_domain_param_unstructured, wxios_context_init, using_xios
     IMPLICIT NONE
     REAL,DIMENSION(klon),INTENT(IN) :: rlon
@@ -72,14 +64,10 @@
     INTEGER :: data_ibegin, data_iend
 
-#ifdef CPP_XIOS
-      CALL wxios_context_init
-#endif
+    if (using_xios)  CALL wxios_context_init
     
 
     IF (grid_type==unstructured) THEN
     
-#ifdef CPP_XIOS
       CALL wxios_domain_param_unstructured("dom_glo")
-#endif
 
     ELSE
@@ -140,5 +128,5 @@
                       'APPLE',phys_domain_id)
 #endif
-#ifdef CPP_XIOS
+    IF (using_xios) THEN  
       ! Set values for the mask:
       IF (mpi_rank == 0) THEN
@@ -163,10 +151,8 @@
 
       ! Initialize the XIOS domain coreesponding to this process:
-#endif
+    ENDIF
 !$OMP END MASTER
 
-#ifdef CPP_XIOS    
-        CALL wxios_domain_param("dom_glo")
-#endif
+      IF (using_xios) CALL wxios_domain_param("dom_glo")
       
     ENDIF
@@ -227,7 +213,5 @@
   USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
   USE ioipsl, ONLY: histbeg
-#ifdef CPP_XIOS
-  USE wxios, ONLY: wxios_add_file
-#endif
+  USE wxios, ONLY: wxios_add_file, using_xios
   IMPLICIT NONE
   INCLUDE 'clesphys.h'
@@ -251,13 +235,13 @@
   ENDIF
 
-#ifdef CPP_XIOS
-  ! ug OMP en chantier...
-  IF((.NOT. is_using_mpi) .OR. is_mpi_root) THEN
-      ! ug Création du fichier
-    IF (.not. ok_all_xml) THEN
-      CALL wxios_add_file(name, ffreq, lev)
+  IF (using_xios) THEN  
+    ! ug OMP en chantier...
+    IF((.NOT. is_using_mpi) .OR. is_mpi_root) THEN
+        ! ug Création du fichier
+      IF (.not. ok_all_xml) THEN
+        CALL wxios_add_file(name, ffreq, lev)
+      ENDIF
     ENDIF
   ENDIF
-#endif
 !$OMP END MASTER
   
@@ -608,7 +592,5 @@
     USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
     USE aero_mod, ONLY : naero_tot, name_aero_tau
-#ifdef CPP_XIOS
-    USE wxios, ONLY: wxios_add_field_to_file
-#endif
+    USE wxios, ONLY: wxios_add_field_to_file, using_xios
     USE print_control_mod, ONLY: prt_level,lunout
     IMPLICIT NONE
@@ -650,16 +632,16 @@
     IF(.NOT.clef_stations(iff)) THEN  
 
-#ifdef CPP_XIOS
-      IF (.not. ok_all_xml) THEN
-        IF ( var%flag(iff)<=lev_files(iff) ) THEN
-          CALL wxios_add_field_to_file(var%name, 2, iff, phys_out_filenames(iff), &
-          var%description, var%unit, var%flag(iff), typeecrit)
-          IF (prt_level >= 10) THEN
-            WRITE(lunout,*) 'histdef2d: call wxios_add_field_to_file var%name iff: ', &
-                            trim(var%name),iff
+      IF (using_xios) THEN  
+        IF (.not. ok_all_xml) THEN
+          IF ( var%flag(iff)<=lev_files(iff) ) THEN
+            CALL wxios_add_field_to_file(var%name, 2, iff, phys_out_filenames(iff), &
+            var%description, var%unit, var%flag(iff), typeecrit)
+            IF (prt_level >= 10) THEN
+              WRITE(lunout,*) 'histdef2d: call wxios_add_field_to_file var%name iff: ', &
+                              trim(var%name),iff
+            ENDIF
           ENDIF
         ENDIF
       ENDIF
-#endif
 #ifndef CPP_IOIPSL_NO_OUTPUT 
 
@@ -725,7 +707,5 @@
     USE print_control_mod, ONLY: prt_level,lunout
     USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
-#ifdef CPP_XIOS
-    USE wxios, ONLY: wxios_add_field_to_file
-#endif
+    USE wxios, ONLY: wxios_add_field_to_file, using_xios
     USE print_control_mod, ONLY: prt_level,lunout
     IMPLICIT NONE
@@ -766,16 +746,17 @@
     IF(.NOT.clef_stations(iff)) THEN
 
-#ifdef CPP_XIOS
-       IF (.not. ok_all_xml) THEN
-         IF ( var%flag(iff)<=lev_files(iff) ) THEN
-         CALL wxios_add_field_to_file(var%name, 3, iff, phys_out_filenames(iff), &
-         var%description, var%unit, var%flag(iff), typeecrit)
-           IF (prt_level >= 10) THEN
-             WRITE(lunout,*) 'histdef3d: call wxios_add_field_to_file var%name iff: ', &
-                             trim(var%name),iff
-           ENDIF
-         ENDIF
-       ENDIF
-#endif
+      IF (using_xios) THEN  
+
+        IF (.not. ok_all_xml) THEN
+          IF ( var%flag(iff)<=lev_files(iff) ) THEN
+          CALL wxios_add_field_to_file(var%name, 3, iff, phys_out_filenames(iff), &
+          var%description, var%unit, var%flag(iff), typeecrit)
+            IF (prt_level >= 10) THEN
+              WRITE(lunout,*) 'histdef3d: call wxios_add_field_to_file var%name iff: ', &
+                              trim(var%name),iff
+            ENDIF
+          ENDIF
+        ENDIF
+      ENDIF
 #ifndef CPP_IOIPSL_NO_OUTPUT 
 
@@ -974,7 +955,5 @@
   USE print_control_mod, ONLY: prt_level,lunout
   USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat, grid_type, unstructured, regular_lonlat
-#ifdef CPP_XIOS
-  USE xios, ONLY: xios_send_field, xios_field_is_active
-#endif
+  USE lmdz_xios, ONLY: xios_send_field, xios_field_is_active, using_xios
   USE print_control_mod, ONLY: lunout, prt_level
 
@@ -1036,14 +1015,14 @@
 
   ELSE
-#ifdef CPP_XIOS
-    IF (ok_all_xml) THEN
-      !$omp barrier
-      !$omp master
-      is_active = xios_field_is_active(var%name, at_current_timestep_arg=.false.)
-      !$omp end master
-      !$omp barrier
-      IF(.not. is_active) RETURN
-    ENDIF
-#endif
+    IF (using_xios) THEN
+      IF (ok_all_xml) THEN
+        !$omp barrier
+        !$omp master
+        is_active = xios_field_is_active(var%name, at_current_timestep_arg=.false.)
+        !$omp end master
+        !$omp barrier
+        IF(.not. is_active) RETURN
+      ENDIF
+    ENDIF
 
     !Et sinon on.... écrit
@@ -1068,5 +1047,5 @@
 
       IF (ok_all_xml) THEN
-#ifdef CPP_XIOS
+        IF (using_xios) THEN  
           IF (prt_level >= 10) THEN
              write(lunout,*)'Dans iophy histwrite2D,var%name ', trim(var%name)                       
@@ -1091,35 +1070,35 @@
                              trim(var%name)                       
           ENDIF
-#else
-        CALL abort_physic ('iophy','cannot have ok_all_xml = .T. without CPP_XIOS defined' ,1)
-#endif
+        ELSE
+          CALL abort_physic ('iophy','cannot have ok_all_xml = .T. without CPP_XIOS defined' ,1)
+        ENDIF
       ELSE  
         DO iff=iff_beg, iff_end
             IF (var%flag(iff) <= lev_files(iff) .AND. clef_files(iff)) THEN 
 
-#ifdef CPP_XIOS
-               IF (firstx) THEN
-                  IF (prt_level >= 10) THEN
-                     write(lunout,*)'Dans iophy histwrite2D,iff,var%name ',&
-                                    iff,trim(var%name)                       
-                     write(lunout,*)"histwrite2d_phy:.NOT.clef_stations(iff)and iff==iff_beg, call xios_send_field"
-                  ENDIF
-                  IF (grid_type==regular_lonlat) THEN
-                    IF (SIZE(field) == klon) then
-                       CALL xios_send_field(var%name, Field2d)
-                    ELSE
+              IF (using_xios) THEN
+                IF (firstx) THEN
+                   IF (prt_level >= 10) THEN
+                      write(lunout,*)'Dans iophy histwrite2D,iff,var%name ',&
+                                     iff,trim(var%name)                       
+                      write(lunout,*)"histwrite2d_phy:.NOT.clef_stations(iff)and iff==iff_beg, call xios_send_field"
+                   ENDIF
+                   IF (grid_type==regular_lonlat) THEN
+                     IF (SIZE(field) == klon) then
+                        CALL xios_send_field(var%name, Field2d)
+                     ELSE
+                        CALL xios_send_field(var%name, field)
+                     ENDIF
+                   ELSE IF (grid_type==unstructured) THEN
+                     IF (SIZE(field) == klon) then
+                       CALL xios_send_field(var%name, buffer_omp)
+                     ELSE
                        CALL xios_send_field(var%name, field)
-                    ENDIF
-                  ELSE IF (grid_type==unstructured) THEN
-                    IF (SIZE(field) == klon) then
-                      CALL xios_send_field(var%name, buffer_omp)
-                    ELSE
-                      CALL xios_send_field(var%name, field)
-                    ENDIF
-                  ENDIF
-
-                  firstx=.false.
-               ENDIF
-#endif
+                     ENDIF
+                   ENDIF
+
+                   firstx=.false.
+                ENDIF
+              ENDIF
 
                   IF (.NOT.clef_stations(iff)) THEN
@@ -1129,5 +1108,5 @@
                         CALL histwrite(nid_files(iff),var%name,itau_iophy,Field2d,nbp_lon*jj_nb,index2d)
 #endif
-!#ifdef CPP_XIOS
+!    IF (using_xios) THEN  
 !                        IF (iff == iff_beg) THEN
 !                          IF (prt_level >= 10) THEN
@@ -1136,5 +1115,5 @@
 !                          CALL xios_send_field(var%name, Field2d)
 !                        ENDIF
-!#endif
+!    ENDIF
                   ELSE 
                         ALLOCATE(fieldok(npstn))
@@ -1188,7 +1167,5 @@
                                  nid_files, swaerofree_diag
   USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat, grid_type, regular_lonlat, unstructured
-#ifdef CPP_XIOS
-  USE xios, ONLY: xios_send_field, xios_field_is_active
-#endif
+  USE lmdz_xios, ONLY: xios_send_field, xios_field_is_active, using_xios
   USE print_control_mod, ONLY: prt_level,lunout
 
@@ -1236,14 +1213,14 @@
       CALL bcast_omp(swaerofree_diag)
   ELSE
-#ifdef CPP_XIOS
-    IF (ok_all_xml) THEN
-      !$omp barrier
-      !$omp master
-      is_active = xios_field_is_active(var%name, at_current_timestep_arg=.false.)
-      !$omp end master
-      !$omp barrier
-      IF(.not. is_active) RETURN
-    ENDIF
-#endif
+    IF (using_xios) THEN  
+      IF (ok_all_xml) THEN
+        !$omp barrier
+        !$omp master
+        is_active = xios_field_is_active(var%name, at_current_timestep_arg=.false.)
+        !$omp end master
+        !$omp barrier
+        IF(.not. is_active) RETURN
+      ENDIF
+    ENDIF
 
     !Et sinon on.... écrit
@@ -1273,5 +1250,5 @@
 
     IF (ok_all_xml) THEN
-#ifdef CPP_XIOS
+      IF (using_xios) THEN  
           IF (prt_level >= 10) THEN
              write(lunout,*)'Dans iophy histwrite3D,var%name ',&
@@ -1292,12 +1269,12 @@
         ENDIF
 
-#else
+      ELSE
         CALL abort_physic ('iophy','cannot have ok_all_xml = .T. without CPP_XIOS defined' ,1)
-#endif
+      ENDIF
     ELSE  
 
       DO iff=iff_beg, iff_end
           IF (var%flag(iff) <= lev_files(iff) .AND. clef_files(iff)) THEN
-#ifdef CPP_XIOS
+            IF (using_xios) THEN  
               IF (firstx) THEN
                 IF (prt_level >= 10) THEN
@@ -1324,8 +1301,9 @@
                 firstx=.false.
               ENDIF
-#endif
-              IF (.NOT.clef_stations(iff)) THEN
-                        ALLOCATE(index3d(nbp_lon*jj_nb*nlev))
-                        ALLOCATE(fieldok(nbp_lon*jj_nb,nlev))
+            ENDIF
+            
+            IF (.NOT.clef_stations(iff)) THEN
+                      ALLOCATE(index3d(nbp_lon*jj_nb*nlev))
+                      ALLOCATE(fieldok(nbp_lon*jj_nb,nlev))
 
 #ifndef CPP_IOIPSL_NO_OUTPUT 
@@ -1333,9 +1311,9 @@
 #endif
 
-!#ifdef CPP_XIOS
+!    IF (using_xios) THEN  
 !                        IF (iff == 1) THEN
 !                              CALL xios_send_field(var%name, Field3d(:,:,1:klev))
 !                        ENDIF
-!#endif
+!    ENDIF
 !                        
               ELSE 
@@ -1378,5 +1356,4 @@
 
 ! VERSION DES HISTWRITE DEDIEES AU TOUT-XIOS-XML DEJA UTILISEE DANS PHYDEV
-#ifdef CPP_XIOS
   SUBROUTINE histwrite2d_xios(field_name,field)
 
@@ -1386,5 +1363,5 @@
                                 jj_nb, klon_mpi, is_master
   USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat, grid_type, unstructured
-  USE xios, ONLY: xios_send_field
+  USE lmdz_xios, ONLY: xios_send_field
   USE print_control_mod, ONLY: prt_level,lunout
 
@@ -1468,5 +1445,5 @@
                                 is_sequential, klon_mpi_begin, klon_mpi_end, &
                                 jj_nb, klon_mpi, is_master
-  USE xios, ONLY: xios_send_field
+  USE lmdz_xios, ONLY: xios_send_field
   USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat, grid_type, unstructured
   USE print_control_mod, ONLY: prt_level,lunout
@@ -1551,7 +1528,6 @@
   END SUBROUTINE histwrite3d_xios
 
-#ifdef CPP_XIOS
   SUBROUTINE histwrite0d_xios(field_name, field)
-  USE xios, ONLY: xios_send_field
+  USE lmdz_xios, ONLY: xios_send_field
   USE mod_phys_lmdz_para, ONLY: is_master
   USE print_control_mod, ONLY: prt_level,lunout
@@ -1568,6 +1544,4 @@
 
   END SUBROUTINE histwrite0d_xios
-#endif
-
-#endif
+
 END MODULE iophy
Index: LMDZ6/trunk/libf/phylmd/limit_read_mod.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/limit_read_mod.F90	(revision 4618)
+++ LMDZ6/trunk/libf/phylmd/limit_read_mod.F90	(revision 4619)
@@ -36,7 +36,6 @@
   USE surface_data
   USE mod_phys_lmdz_para
-#ifdef CPP_XIOS
-  USE XIOS
-#endif
+  USE lmdz_xios
+
   IMPLICIT NONE
     INTEGER, INTENT(IN) :: first_day
@@ -45,7 +44,5 @@
     IF ( type_ocean /= 'couple') THEN
       IF (grid_type==unstructured) THEN
-#ifdef CPP_XIOS
         IF (is_omp_master) CALL xios_set_file_attr("limit_read",enabled=.TRUE.,record_offset=first_day)
-#endif
       ENDIF  
     ENDIF
@@ -172,7 +169,5 @@
     USE phys_cal_mod, ONLY : calend, year_len
     USE print_control_mod, ONLY: lunout, prt_level
-#ifdef CPP_XIOS
-    USE XIOS, ONLY: xios_recv_field
-#endif
+    USE lmdz_xios, ONLY: xios_recv_field, using_xios
     
     IMPLICIT NONE
@@ -297,5 +292,4 @@
       IF (grid_type==unstructured) THEN
 
-#ifdef CPP_XIOS
         IF ( type_ocean /= 'couple') THEN
 
@@ -331,6 +325,4 @@
           CALL Scatter_omp(rug_mpi, rugos)
        END IF
-#endif
-
  
      ELSE      ! grid_type==regular
Index: LMDZ6/trunk/libf/phylmd/moy_undefSTD.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/moy_undefSTD.F90	(revision 4618)
+++ LMDZ6/trunk/libf/phylmd/moy_undefSTD.F90	(revision 4619)
@@ -8,14 +8,10 @@
   USE phys_state_var_mod
 #endif
-#ifdef CPP_XIOS
-  USE wxios, ONLY: missing_val
-#endif
+  USE wxios, ONLY: missing_val_xios => missing_val, using_xios
  
   USE phys_cal_mod, ONLY: mth_len
   IMPLICIT NONE
   include "clesphys.h"
-#ifndef CPP_XIOS 
   REAL :: missing_val
-#endif
 
   ! ====================================================================
@@ -59,7 +55,9 @@
 
 ! missing_val = nf90_fill_real
-#ifndef CPP_XIOS
-      missing_val=missing_val_nf90
-#endif
+  IF (using_xios) THEN
+    missing_val = missing_val_xios
+  ELSE
+    missing_val=missing_val_nf90
+  ENDIF
 
   DO n = 1, nout
Index: LMDZ6/trunk/libf/phylmd/oasis.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/oasis.F90	(revision 4618)
+++ LMDZ6/trunk/libf/phylmd/oasis.F90	(revision 4619)
@@ -117,8 +117,6 @@
     USE surface_data, ONLY : version_ocean
     USE carbon_cycle_mod, ONLY : carbon_cycle_cpl
-#ifdef CPP_XIOS
     USE wxios, ONLY : wxios_context_init 
-    USE xios  
-#endif
+    USE lmdz_xios  
     USE print_control_mod, ONLY: lunout
     USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat, grid_type, unstructured, regular_lonlat
@@ -393,7 +391,7 @@
 ! End definition
 !************************************************************************************
-#ifdef CPP_XIOS
-    CALL xios_oasis_enddef()
-#endif
+
+    IF (using_xios) CALL xios_oasis_enddef()
+
     CALL prism_enddef_proto(ierror)
     IF (ierror .NE. PRISM_Ok) THEN
@@ -404,9 +402,5 @@
     ENDIF
 
-#ifdef CPP_XIOS
-!    CALL wxios_context_init()
-#endif
-
-!$OMP END MASTER
+S!$OMP END MASTER
     
   END SUBROUTINE inicma
Index: LMDZ6/trunk/libf/phylmd/pbl_surface_mod.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/pbl_surface_mod.F90	(revision 4618)
+++ LMDZ6/trunk/libf/phylmd/pbl_surface_mod.F90	(revision 4619)
@@ -319,9 +319,6 @@
     use phys_output_var_mod, only: tkt, tks, taur, sss
     use blowing_snow_ini_mod, only : zeta_bs
-#ifdef CPP_XIOS
-    USE wxios, ONLY: missing_val
-#else
-    use netcdf, only: missing_val => nf90_fill_real
-#endif
+    USE wxios, ONLY: missing_val_xios => missing_val, using_xios
+    USE netcdf, only: missing_val_netcdf => nf90_fill_real
 
      
@@ -899,8 +896,13 @@
     ! compression of delta_sst, delta_sal, ds_ns, dt_ns, dter, dser,
     ! dt_ds, tkt, tks, taur, sss on ocean points
-
+    REAL :: missing_val
 !****************************************************************************************
 ! End of declarations
 !****************************************************************************************
+      IF (using_xios) THEN
+        missing_val=missing_val_xios
+      ELSE
+        missing_val=missing_val_netcdf
+      ENDIF
 
       IF (prt_level >=10) print *,' -> pbl_surface, itap ',itap
Index: LMDZ6/trunk/libf/phylmd/phyaqua_mod.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/phyaqua_mod.F90	(revision 4618)
+++ LMDZ6/trunk/libf/phylmd/phyaqua_mod.F90	(revision 4619)
@@ -514,7 +514,5 @@
     USE mod_phys_lmdz_para, ONLY: is_omp_master, klon_mpi
     USE mod_phys_lmdz_transfert_para, ONLY: gather_omp
-#ifdef CPP_XIOS
-    USE xios
-#endif
+    USE lmdz_xios
     IMPLICIT NONE
 
@@ -536,31 +534,31 @@
       ! on the whole physics grid
  
-#ifdef CPP_XIOS
-    PRINT *, 'writelim: Ecriture du fichier limit'
-
-    CALL gather_omp(phy_foce, phy_mpi)
-    IF (is_omp_master) CALL xios_send_field('foce_limout',phy_mpi)
-
-    CALL gather_omp(phy_fsic, phy_mpi)
-    IF (is_omp_master) CALL xios_send_field('fsic_limout',phy_mpi)
+    IF (using_xios) THEN
+      PRINT *, 'writelim: Ecriture du fichier limit'
+
+      CALL gather_omp(phy_foce, phy_mpi)
+      IF (is_omp_master) CALL xios_send_field('foce_limout',phy_mpi)
+
+      CALL gather_omp(phy_fsic, phy_mpi)
+      IF (is_omp_master) CALL xios_send_field('fsic_limout',phy_mpi)
       
-    CALL gather_omp(phy_fter, phy_mpi)
-    IF (is_omp_master) CALL xios_send_field('fter_limout',phy_mpi)
+      CALL gather_omp(phy_fter, phy_mpi)
+      IF (is_omp_master) CALL xios_send_field('fter_limout',phy_mpi)
       
-    CALL gather_omp(phy_flic, phy_mpi)
-    IF (is_omp_master) CALL xios_send_field('flic_limout',phy_mpi)
-
-    CALL gather_omp(phy_sst, phy_mpi)
-    IF (is_omp_master) CALL xios_send_field('sst_limout',phy_mpi)
-
-    CALL gather_omp(phy_bil, phy_mpi)
-    IF (is_omp_master) CALL xios_send_field('bils_limout',phy_mpi)
-
-    CALL gather_omp(phy_alb, phy_mpi)
-    IF (is_omp_master) CALL xios_send_field('alb_limout',phy_mpi)
-
-    CALL gather_omp(phy_rug, phy_mpi)
-    IF (is_omp_master) CALL xios_send_field('rug_limout',phy_mpi)
-#endif
+      CALL gather_omp(phy_flic, phy_mpi)
+      IF (is_omp_master) CALL xios_send_field('flic_limout',phy_mpi)
+
+      CALL gather_omp(phy_sst, phy_mpi)
+      IF (is_omp_master) CALL xios_send_field('sst_limout',phy_mpi)
+
+      CALL gather_omp(phy_bil, phy_mpi)
+      IF (is_omp_master) CALL xios_send_field('bils_limout',phy_mpi)
+
+      CALL gather_omp(phy_alb, phy_mpi)
+      IF (is_omp_master) CALL xios_send_field('alb_limout',phy_mpi)
+
+      CALL gather_omp(phy_rug, phy_mpi)
+      IF (is_omp_master) CALL xios_send_field('rug_limout',phy_mpi)
+    ENDIF
   END SUBROUTINE writelim_unstruct
 
Index: LMDZ6/trunk/libf/phylmd/phyetat0_mod.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/phyetat0_mod.F90	(revision 4618)
+++ LMDZ6/trunk/libf/phylmd/phyetat0_mod.F90	(revision 4619)
@@ -39,9 +39,6 @@
   USE ocean_slab_mod,   ONLY: nslay, tslab, seaice, tice, ocean_slab_init
   USE time_phylmdz_mod, ONLY: init_iteration, pdtphys, itau_phy
-#ifdef CPP_XIOS
-  USE wxios, ONLY: missing_val
-#else
-  use netcdf, only: missing_val => nf90_fill_real
-#endif
+  USE wxios, ONLY: missing_val_xios => missing_val, using_xios
+  use netcdf, only: missing_val_netcdf => nf90_fill_real
   use config_ocean_skin_m, only: activate_ocean_skin
 
@@ -92,5 +89,12 @@
   REAL :: lon_startphy(klon), lat_startphy(klon)
   CHARACTER(LEN=maxlen) :: tname, t(2)
-
+  REAL :: missing_val
+
+  IF (using_xios) THEN
+    missing_val=missing_val_xios
+  ELSE
+    missing_val=missing_val_netcdf
+  ENDIF
+  
   ! FH1D
   !     real iolat(jjm+1)
Index: LMDZ6/trunk/libf/phylmd/phys_output_ctrlout_mod.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/phys_output_ctrlout_mod.F90	(revision 4618)
+++ LMDZ6/trunk/libf/phylmd/phys_output_ctrlout_mod.F90	(revision 4619)
@@ -2065,5 +2065,5 @@
 
 #ifdef CPP_Dust
-      INCLUDE "Dust/spla_output_dat.h"
+      INCLUDE 'spla_output_dat.h'
 #endif
 
Index: LMDZ6/trunk/libf/phylmd/phys_output_mod.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/phys_output_mod.F90	(revision 4618)
+++ LMDZ6/trunk/libf/phylmd/phys_output_mod.F90	(revision 4619)
@@ -47,8 +47,6 @@
     USE vertical_layers_mod, ONLY: ap,bp,preff,presnivs, aps, bps, pseudoalt, presinter
     USE time_phylmdz_mod, ONLY: day_ini, itau_phy, start_time, annee_ref, day_ref
-#ifdef CPP_XIOS
     ! ug Pour les sorties XIOS
     USE wxios
-#endif
 
     IMPLICIT NONE
@@ -129,5 +127,4 @@
     REAL, DIMENSION(klev+1)   :: lev_index
                 
-#ifdef CPP_XIOS
     ! ug Variables utilis\'ees pour r\'ecup\'erer le calendrier pour xios
     INTEGER :: x_an, x_mois, x_jour
@@ -135,5 +132,5 @@
     INTEGER :: ini_an, ini_mois, ini_jour
     REAL :: ini_heure
-#endif
+
     INTEGER                         :: ISW
     REAL, DIMENSION(NSW)            :: wl1_sun, wl2_sun !wavelength bounds (in um) for SW
@@ -290,12 +287,12 @@
      ENDIF
 
-#ifdef CPP_XIOS
-    ! ug R\'eglage du calendrier xios
-    !Temps julian => an, mois, jour, heure
-    CALL ju2ymds(zjulian, x_an, x_mois, x_jour, x_heure)
-    CALL ju2ymds(zjulian_start, ini_an, ini_mois, ini_jour, ini_heure)
-    CALL wxios_set_cal(dtime, calend, x_an, x_mois, x_jour, x_heure, ini_an, &
-                       ini_mois, ini_jour, ini_heure )
-#endif
+    IF (using_xios) THEN
+      ! ug R\'eglage du calendrier xios
+      !Temps julian => an, mois, jour, heure
+      CALL ju2ymds(zjulian, x_an, x_mois, x_jour, x_heure)
+      CALL ju2ymds(zjulian_start, ini_an, ini_mois, ini_jour, ini_heure)
+      CALL wxios_set_cal(dtime, calend, x_an, x_mois, x_jour, x_heure, ini_an, &
+                         ini_mois, ini_jour, ini_heure )
+    ENDIF
 
 !!!!!!!!!!!!!!!!!!!!!!! Boucle sur les fichiers !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -330,64 +327,64 @@
 
 
-#ifdef CPP_XIOS
-!!! Ouverture de chaque fichier XIOS !!!!!!!!!!!
-    IF (.not. ok_all_xml) THEN
+    IF (using_xios) THEN 
+      !!! Ouverture de chaque fichier XIOS !!!!!!!!!!!
+      IF (.not. ok_all_xml) THEN
+        IF (prt_level >= 10) THEN
+         print*,'phys_output_open: call wxios_add_file with phys_out_filenames(iff)=',trim(phys_out_filenames(iff))    
+        ENDIF
+        CALL wxios_add_file(phys_out_filenames(iff),chtimestep(iff),lev_files(iff))  
+      ENDIF
+
+      !!! Declaration des axes verticaux de chaque fichier:
       IF (prt_level >= 10) THEN
-        print*,'phys_output_open: call wxios_add_file with phys_out_filenames(iff)=',trim(phys_out_filenames(iff))    
+        print*,'phys_output_open: Declare vertical axes for each file'
       ENDIF
-      CALL wxios_add_file(phys_out_filenames(iff),chtimestep(iff),lev_files(iff))  
-    ENDIF
-
-!!! Declaration des axes verticaux de chaque fichier:
-    IF (prt_level >= 10) THEN
-      print*,'phys_output_open: Declare vertical axes for each file'
-    ENDIF
-
-   IF (iff.LE.6.OR.iff.EQ.10) THEN
-    CALL wxios_add_vaxis("presnivs", &
-            levmax(iff) - levmin(iff) + 1, presnivs(levmin(iff):levmax(iff)))
-    CALL wxios_add_vaxis("presinter", &
-            klev + 1, presinter(1:klev+1))
-    CALL wxios_add_vaxis("Ahyb", &
-            levmax(iff) - levmin(iff) + 1, aps(levmin(iff):levmax(iff)), positif='down', &
-            bnds=Ahyb_bounds(levmin(iff):levmax(iff),:))
-    CALL wxios_add_vaxis("Bhyb", &
-            levmax(iff) - levmin(iff) + 1, bps(levmin(iff):levmax(iff)), positif='down', &
-            bnds=Bhyb_bounds(levmin(iff):levmax(iff),:))
-    CALL wxios_add_vaxis("klev", levmax(iff) - levmin(iff) + 1, &
-                          lev_index(levmin(iff):levmax(iff)))
-    CALL wxios_add_vaxis("klevp1", klev+1, &
-                          lev_index(1:klev+1))
-    CALL wxios_add_vaxis("bnds", 2, (/1.,2./))
-
-    CALL wxios_add_vaxis("Alt", &
-            levmax(iff) - levmin(iff) + 1, pseudoalt)
-
-    ! wl1_sun/wl2_sun: minimum/maximum bound of wavelength (in um)
-    SELECT CASE(NSW)
-      CASE(6)
-        wl1_sun(1:6) = [0.180, 0.250, 0.440, 0.690, 1.190, 2.380]
-        wl2_sun(1:6) = [0.250, 0.440, 0.690, 1.190, 2.380, 4.000]
-      CASE(2)
-        wl1_sun(1:2) = [0.250, 0.690]
-        wl2_sun(1:2) = [0.690, 4.000]
-    END SELECT
-
-    DO ISW=1, NSW
-     wn1_sun(ISW)=1.e+6/wl1_sun(ISW) 
-     wn2_sun(ISW)=1.e+6/wl2_sun(ISW) 
-     spbnds_sun(ISW,1)=wn2_sun(ISW)
-     spbnds_sun(ISW,2)=wn1_sun(ISW)
-     spectband(ISW)=(wn1_sun(ISW)+wn2_sun(ISW))/2
-    ENDDO
+
+      IF (iff.LE.6.OR.iff.EQ.10) THEN
+        CALL wxios_add_vaxis("presnivs", &
+              levmax(iff) - levmin(iff) + 1, presnivs(levmin(iff):levmax(iff)))
+        CALL wxios_add_vaxis("presinter", &
+              klev + 1, presinter(1:klev+1))
+        CALL wxios_add_vaxis("Ahyb", &
+              levmax(iff) - levmin(iff) + 1, aps(levmin(iff):levmax(iff)), positif='down', &
+              bnds=Ahyb_bounds(levmin(iff):levmax(iff),:))
+        CALL wxios_add_vaxis("Bhyb", &
+              levmax(iff) - levmin(iff) + 1, bps(levmin(iff):levmax(iff)), positif='down', &
+              bnds=Bhyb_bounds(levmin(iff):levmax(iff),:))
+        CALL wxios_add_vaxis("klev", levmax(iff) - levmin(iff) + 1, &
+                              lev_index(levmin(iff):levmax(iff)))
+        CALL wxios_add_vaxis("klevp1", klev+1, &
+                              lev_index(1:klev+1))
+        CALL wxios_add_vaxis("bnds", 2, (/1.,2./))
+  
+        CALL wxios_add_vaxis("Alt", &
+                levmax(iff) - levmin(iff) + 1, pseudoalt)
+
+        ! wl1_sun/wl2_sun: minimum/maximum bound of wavelength (in um)
+        SELECT CASE(NSW)
+          CASE(6)
+            wl1_sun(1:6) = [0.180, 0.250, 0.440, 0.690, 1.190, 2.380]
+            wl2_sun(1:6) = [0.250, 0.440, 0.690, 1.190, 2.380, 4.000]
+          CASE(2)
+            wl1_sun(1:2) = [0.250, 0.690]
+            wl2_sun(1:2) = [0.690, 4.000]
+        END SELECT
+
+        DO ISW=1, NSW
+          wn1_sun(ISW)=1.e+6/wl1_sun(ISW) 
+          wn2_sun(ISW)=1.e+6/wl2_sun(ISW) 
+          spbnds_sun(ISW,1)=wn2_sun(ISW)
+          spbnds_sun(ISW,2)=wn1_sun(ISW)
+          spectband(ISW)=(wn1_sun(ISW)+wn2_sun(ISW))/2
+        ENDDO
 !
 !!! ajout axe vertical spectband : solar band number
-    CALL wxios_add_vaxis("spectband", NSW, spectband, positif='down')
-   ELSE
-    ! NMC files
-    CALL wxios_add_vaxis("plev", &
-            levmax(iff) - levmin(iff) + 1, rlevSTD(levmin(iff):levmax(iff)))
-   ENDIF
-#endif 
+        CALL wxios_add_vaxis("spectband", NSW, spectband, positif='down')
+      ELSE
+        ! NMC files
+        CALL wxios_add_vaxis("plev", &
+                levmax(iff) - levmin(iff) + 1, rlevSTD(levmin(iff):levmax(iff)))
+      ENDIF
+    ENDIF !using_xios 
 
         IF (clef_files(iff)) THEN
Index: LMDZ6/trunk/libf/phylmd/phys_output_write_mod.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/phys_output_write_mod.F90	(revision 4618)
+++ LMDZ6/trunk/libf/phylmd/phys_output_write_mod.F90	(revision 4619)
@@ -420,11 +420,7 @@
     USE netcdf, ONLY: nf90_fill_real
     USE print_control_mod, ONLY: prt_level,lunout
-
-
-#ifdef CPP_XIOS
     ! ug Pour les sorties XIOS
-    USE xios
-    USE wxios, ONLY: wxios_closedef, missing_val, wxios_set_context
-#endif
+    USE lmdz_xios
+    USE wxios, ONLY: wxios_closedef, missing_val_xios=>missing_val, wxios_set_context
     USE phys_cal_mod, ONLY : mth_len
 
@@ -484,7 +480,5 @@
 !$OMP THREADPRIVATE(kmax_100m)
     REAL :: x
-#ifndef CPP_XIOS
     REAL :: missing_val
-#endif
     REAL, PARAMETER :: un_jour=86400.
     CHARACTER(len=12) :: nvar    
@@ -513,11 +507,11 @@
  !   ENDIF
 
-#ifdef CPP_XIOS
-    CALL wxios_set_context
-#endif
-
-#ifndef CPP_XIOS
-    missing_val=missing_val_nf90
-#endif
+    IF (using_xios) CALL wxios_set_context
+
+    IF (using_xios) THEN
+      missing_val=missing_val_xios
+    ELSE
+      missing_val=missing_val_nf90
+    ENDIF
 
     IF (.NOT.vars_defined) THEN
@@ -554,16 +548,17 @@
     DO iinit=1, iinitend
 !      print *,'IFF iinit=', iinit, iinitend 
-#ifdef CPP_XIOS
-       !$OMP MASTER
-       IF (vars_defined) THEN
-          IF (prt_level >= 10) then
-             write(lunout,*)"phys_output_write: call xios_update_calendar, itau_w=",itau_w
-          ENDIF
-!          CALL xios_update_calendar(itau_w)
-          CALL xios_update_calendar(itap)
-       ENDIF
-       !$OMP END MASTER
-       !$OMP BARRIER
-#endif
+       IF (using_xios) THEN
+         !$OMP MASTER
+         IF (vars_defined) THEN
+            IF (prt_level >= 10) then
+               write(lunout,*)"phys_output_write: call xios_update_calendar, itau_w=",itau_w
+            ENDIF
+!            CALL xios_update_calendar(itau_w)
+            CALL xios_update_calendar(itap)
+         ENDIF
+         !$OMP END MASTER
+         !$OMP BARRIER
+       ENDIF
+
        ! On procède à l'écriture ou à la définition des nombreuses variables:
 !!! Champs 1D !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -588,38 +583,39 @@
        CALL histwrite_phy(o_contfracOR, pctsrf(:,is_ter))
 !
-#ifdef CPP_XIOS
-       CALL histwrite_phy("R_ecc",R_ecc)
-       CALL histwrite_phy("R_peri",R_peri)
-       CALL histwrite_phy("R_incl",R_incl)
-       CALL histwrite_phy("solaire",solaire)
-       CALL histwrite_phy(o_Ahyb, ap)
-       CALL histwrite_phy(o_Bhyb, bp)
-       CALL histwrite_phy(o_Ahyb_bounds, Ahyb_bounds)
-       CALL histwrite_phy(o_Bhyb_bounds, Bhyb_bounds)
-       CALL histwrite_phy(o_Ahyb_mid, aps)
-       CALL histwrite_phy(o_Bhyb_mid, bps)
-       CALL histwrite_phy(o_Ahyb_mid_bounds, Ahyb_mid_bounds)
-       CALL histwrite_phy(o_Bhyb_mid_bounds, Bhyb_mid_bounds)
-       CALL histwrite_phy(o_longitude, longitude_deg)
-       CALL histwrite_phy(o_latitude, latitude_deg)
+       IF (using_xios) THEN
+
+         CALL histwrite_phy("R_ecc",R_ecc)
+         CALL histwrite_phy("R_peri",R_peri)
+         CALL histwrite_phy("R_incl",R_incl)
+         CALL histwrite_phy("solaire",solaire)
+         CALL histwrite_phy(o_Ahyb, ap)
+         CALL histwrite_phy(o_Bhyb, bp)
+         CALL histwrite_phy(o_Ahyb_bounds, Ahyb_bounds)
+         CALL histwrite_phy(o_Bhyb_bounds, Bhyb_bounds)
+         CALL histwrite_phy(o_Ahyb_mid, aps)
+         CALL histwrite_phy(o_Bhyb_mid, bps)
+         CALL histwrite_phy(o_Ahyb_mid_bounds, Ahyb_mid_bounds)
+         CALL histwrite_phy(o_Bhyb_mid_bounds, Bhyb_mid_bounds)
+         CALL histwrite_phy(o_longitude, longitude_deg)
+         CALL histwrite_phy(o_latitude, latitude_deg)
 !
 #ifdef CPP_RRTM
-      IF (iflag_rrtm.EQ.1) THEN
-        DO ISW=1, NSW
-          WRITE(ch1,'(i1)') ISW
-!         zx_tmp_0d=RSUN(ISW)
-!         CALL histwrite_phy("rsun"//ch1,zx_tmp_0d)
-          CALL histwrite_phy("rsun"//ch1,RSUN(ISW))
-        ENDDO
-      ENDIF
+        IF (iflag_rrtm.EQ.1) THEN
+          DO ISW=1, NSW
+            WRITE(ch1,'(i1)') ISW
+  !         zx_tmp_0d=RSUN(ISW)
+  !         CALL histwrite_phy("rsun"//ch1,zx_tmp_0d)
+            CALL histwrite_phy("rsun"//ch1,RSUN(ISW))
+          ENDDO
+        ENDIF
 #endif
 !
-       CALL histwrite_phy("co2_ppm",co2_ppm)
-       CALL histwrite_phy("CH4_ppb",CH4_ppb)
-       CALL histwrite_phy("N2O_ppb",N2O_ppb)
-       CALL histwrite_phy("CFC11_ppt",CFC11_ppt)
-       CALL histwrite_phy("CFC12_ppt",CFC12_ppt)
+        CALL histwrite_phy("co2_ppm",co2_ppm)
+        CALL histwrite_phy("CH4_ppb",CH4_ppb)
+        CALL histwrite_phy("N2O_ppb",N2O_ppb)
+        CALL histwrite_phy("CFC11_ppt",CFC11_ppt)
+        CALL histwrite_phy("CFC12_ppt",CFC12_ppt)
 !
-#endif
+      ENDIF !using_xios
 
 !!! Champs 2D !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -884,36 +880,36 @@
 
 ! offline 
-#ifdef CPP_XIOS
-       IF (offline) THEN
-
-          coefh_stok(:,1)      = cdragh(:)
-          coefh_stok(:,2:klev) = coefh(:,2:klev, is_ave)
+       IF (using_xios) THEN
+         IF (offline) THEN
+
+            coefh_stok(:,1)      = cdragh(:)
+            coefh_stok(:,2:klev) = coefh(:,2:klev, is_ave)
           
-          CALL histwrite_phy('upwd_stok', upwd)
-          CALL histwrite_phy('t_stok', t)
-          CALL histwrite_phy('fm_th_stok', fm_therm(:,1:klev))
-          CALL histwrite_phy('en_th_stok', entr_therm)
-          CALL histwrite_phy('da_stok',da )
-          CALL histwrite_phy('mp_stok',mp )
-          CALL histwrite_phy('dnwd_stok', dnwd)
-          CALL histwrite_phy('wght_stok', wght_cvfd)
-          CALL histwrite_phy('coefh_stok', coefh_stok)
-          CALL histwrite_phy('yu1_stok', u1) 
-          CALL histwrite_phy('yv1_stok', v1)
-
-          DO k=1,klev
-             IF (k<10) THEN
-                WRITE(nvar,'(i1)') k
-             ELSE IF (k<100) THEN
-                WRITE(nvar,'(i2)') k
-             ELSE
-                WRITE(nvar,'(i3)') k
-             END IF
-             nvar='phi_lev'//trim(nvar)
-             CALL histwrite_phy(nvar,phi(:,:,k))
-          END DO
+            CALL histwrite_phy('upwd_stok', upwd)
+            CALL histwrite_phy('t_stok', t)
+            CALL histwrite_phy('fm_th_stok', fm_therm(:,1:klev))
+            CALL histwrite_phy('en_th_stok', entr_therm)
+            CALL histwrite_phy('da_stok',da )
+            CALL histwrite_phy('mp_stok',mp )
+            CALL histwrite_phy('dnwd_stok', dnwd)
+            CALL histwrite_phy('wght_stok', wght_cvfd)
+            CALL histwrite_phy('coefh_stok', coefh_stok)
+            CALL histwrite_phy('yu1_stok', u1) 
+            CALL histwrite_phy('yv1_stok', v1)
+
+            DO k=1,klev
+               IF (k<10) THEN
+                  WRITE(nvar,'(i1)') k
+               ELSE IF (k<100) THEN
+                  WRITE(nvar,'(i2)') k
+               ELSE
+                  WRITE(nvar,'(i3)') k
+               END IF
+               nvar='phi_lev'//trim(nvar)
+               CALL histwrite_phy(nvar,phi(:,:,k))
+            END DO
           
-       ENDIF
-#endif
+         ENDIF
+       ENDIF
 
 
@@ -1291,54 +1287,56 @@
 
 #ifdef CPP_IOIPSL
-#ifndef CPP_XIOS
-  IF (.NOT.ok_all_xml) THEN
-       ! ATTENTION, LES ANCIENS HISTWRITE ONT ETES CONSERVES EN ATTENDANT MIEUX:
-       ! Champs interpolles sur des niveaux de pression
-       DO iff=1, nfiles
-          ll=0
-          DO k=1, nlevSTD
-             bb2=clevSTD(k) 
-             IF (bb2.EQ."850".OR.bb2.EQ."700".OR. &
+       IF (.NOT. using_xios) THEN
+         IF (.NOT.ok_all_xml) THEN
+           ! ATTENTION, LES ANCIENS HISTWRITE ONT ETES CONSERVES EN ATTENDANT MIEUX:
+           ! Champs interpolles sur des niveaux de pression
+            DO iff=1, nfiles
+              ll=0
+              DO k=1, nlevSTD
+                bb2=clevSTD(k) 
+                  IF (bb2.EQ."850".OR.bb2.EQ."700".OR. &
+                       bb2.EQ."500".OR.bb2.EQ."200".OR. &
+                       bb2.EQ."100".OR. &
+                       bb2.EQ."50".OR.bb2.EQ."10") THEN
+
+                      ! a refaire correctement !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+                      ll=ll+1
+                      CALL histwrite_phy(o_uSTDlevs(ll),uwriteSTD(:,k,iff), iff)
+                      CALL histwrite_phy(o_vSTDlevs(ll),vwriteSTD(:,k,iff), iff)
+                      CALL histwrite_phy(o_wSTDlevs(ll),wwriteSTD(:,k,iff), iff)
+                      CALL histwrite_phy(o_zSTDlevs(ll),phiwriteSTD(:,k,iff), iff)
+                      CALL histwrite_phy(o_qSTDlevs(ll),qwriteSTD(:,k,iff), iff)
+                      CALL histwrite_phy(o_tSTDlevs(ll),twriteSTD(:,k,iff), iff)
+
+                  ENDIF !(bb2.EQ."850".OR.bb2.EQ."700".OR.
+              ENDDO
+            ENDDO
+         ENDIF
+       ENDIF
+#endif
+
+       IF (using_xios) THEN
+         IF (ok_all_xml) THEN
+           !XIOS  CALL xios_get_field_attr("u850",default_value=missing_val)
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+            ll=0
+            DO k=1, nlevSTD
+              bb2=clevSTD(k) 
+              IF (bb2.EQ."850".OR.bb2.EQ."700".OR. &
                   bb2.EQ."500".OR.bb2.EQ."200".OR. &
                   bb2.EQ."100".OR. &
                   bb2.EQ."50".OR.bb2.EQ."10") THEN
-
-                ! a refaire correctement !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-                ll=ll+1
-                CALL histwrite_phy(o_uSTDlevs(ll),uwriteSTD(:,k,iff), iff)
-                CALL histwrite_phy(o_vSTDlevs(ll),vwriteSTD(:,k,iff), iff)
-                CALL histwrite_phy(o_wSTDlevs(ll),wwriteSTD(:,k,iff), iff)
-                CALL histwrite_phy(o_zSTDlevs(ll),phiwriteSTD(:,k,iff), iff)
-                CALL histwrite_phy(o_qSTDlevs(ll),qwriteSTD(:,k,iff), iff)
-                CALL histwrite_phy(o_tSTDlevs(ll),twriteSTD(:,k,iff), iff)
-
-             ENDIF !(bb2.EQ."850".OR.bb2.EQ."700".OR.
-          ENDDO
-       ENDDO
-  ENDIF
-#endif
-#endif
-#ifdef CPP_XIOS
-  IF (ok_all_xml) THEN
-!XIOS  CALL xios_get_field_attr("u850",default_value=missing_val)
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-          ll=0
-          DO k=1, nlevSTD
-             bb2=clevSTD(k) 
-             IF (bb2.EQ."850".OR.bb2.EQ."700".OR. &
-                bb2.EQ."500".OR.bb2.EQ."200".OR. &
-                bb2.EQ."100".OR. &
-                bb2.EQ."50".OR.bb2.EQ."10") THEN
-                ll=ll+1
-                CALL histwrite_phy(o_uSTDlevs(ll),ulevSTD(:,k))
-                CALL histwrite_phy(o_vSTDlevs(ll),vlevSTD(:,k))
-                CALL histwrite_phy(o_wSTDlevs(ll),wlevSTD(:,k))
-                CALL histwrite_phy(o_zSTDlevs(ll),philevSTD(:,k))
-                CALL histwrite_phy(o_qSTDlevs(ll),qlevSTD(:,k))
-                CALL histwrite_phy(o_tSTDlevs(ll),tlevSTD(:,k))
-             ENDIF !(bb2.EQ."850".OR.bb2.EQ."700".OR.
-          ENDDO
-  ENDIF
-#endif
+                  ll=ll+1
+                  CALL histwrite_phy(o_uSTDlevs(ll),ulevSTD(:,k))
+                  CALL histwrite_phy(o_vSTDlevs(ll),vlevSTD(:,k))
+                  CALL histwrite_phy(o_wSTDlevs(ll),wlevSTD(:,k))
+                  CALL histwrite_phy(o_zSTDlevs(ll),philevSTD(:,k))
+                  CALL histwrite_phy(o_qSTDlevs(ll),qlevSTD(:,k))
+                  CALL histwrite_phy(o_tSTDlevs(ll),tlevSTD(:,k))
+              ENDIF !(bb2.EQ."850".OR.bb2.EQ."700".OR.
+            ENDDO
+         ENDIF
+       ENDIF
+
        IF (vars_defined) THEN
           DO i=1, klon
@@ -1789,18 +1787,18 @@
        ENDIF
 
-#ifdef CPP_XIOS
+       IF (using_xios) THEN
 !solbnd begin
 #ifdef CPP_RRTM
-      IF (iflag_rrtm.EQ.1) THEN
-       IF (vars_defined) THEN
-        DO ISW=1, NSW
-          zx_tmp_fi3dsp(:,ISW) = swdn(:,klevp1)*swradcorr(:)*RSUN(ISW)
-        ENDDO
-        CALL histwrite_phy(o_solbnd, zx_tmp_fi3dsp)
-       ENDIF
-      ENDIF
+         IF (iflag_rrtm.EQ.1) THEN
+           IF (vars_defined) THEN
+             DO ISW=1, NSW
+               zx_tmp_fi3dsp(:,ISW) = swdn(:,klevp1)*swradcorr(:)*RSUN(ISW)
+             ENDDO
+             CALL histwrite_phy(o_solbnd, zx_tmp_fi3dsp)
+           ENDIF
+         ENDIF
 #endif
 !solbnd end
-#endif
+       ENDIF
 #endif
 
@@ -2379,50 +2377,50 @@
 !!!!!!!!!!!! Sorties niveaux de pression NMC !!!!!!!!!!!!!!!!!!!!
 #ifdef CPP_IOIPSL
-#ifndef CPP_XIOS
-  IF (.NOT.ok_all_xml) THEN 
-       ! ATTENTION, LES ANCIENS HISTWRITE ONT ETES CONSERVES EN ATTENDANT MIEUX:
-       ! Champs interpolles sur des niveaux de pression
-       DO iff=7, nfiles-1 !--OB: here we deal with files 7,8,9
-
-          CALL histwrite_phy(o_tnondef,tnondef(:,:,iff-6),iff)
-          CALL histwrite_phy(o_ta,twriteSTD(:,:,iff-6),iff)
-          CALL histwrite_phy(o_zg,phiwriteSTD(:,:,iff-6),iff)
-          CALL histwrite_phy(o_hus,qwriteSTD(:,:,iff-6),iff)
-          CALL histwrite_phy(o_hur,rhwriteSTD(:,:,iff-6),iff)
-          CALL histwrite_phy(o_ua,uwriteSTD(:,:,iff-6),iff)
-          CALL histwrite_phy(o_va,vwriteSTD(:,:,iff-6),iff)
-          CALL histwrite_phy(o_wap,wwriteSTD(:,:,iff-6),iff)
-          IF (vars_defined) THEN
-             DO k=1, nlevSTD
-                DO i=1, klon
-                   IF (tnondef(i,k,iff-6).NE.missing_val) THEN
-                      IF (freq_outNMC(iff-6).LT.0) THEN
-                         freq_moyNMC(iff-6)=(mth_len*un_jour)/freq_calNMC(iff-6)
-                      ELSE
-                         freq_moyNMC(iff-6)=freq_outNMC(iff-6)/freq_calNMC(iff-6)
-                      ENDIF
-                      zx_tmp_fi3d_STD(i,k) = (100.*tnondef(i,k,iff-6))/freq_moyNMC(iff-6)
-                   ELSE
-                      zx_tmp_fi3d_STD(i,k) = missing_val
-                   ENDIF
-                ENDDO
-             ENDDO
-          ENDIF
-          CALL histwrite_phy(o_psbg,zx_tmp_fi3d_STD,iff)
-          IF (vars_defined) THEN
-             DO k=1, nlevSTD
-                DO i=1, klon
-                   IF (O3sumSTD(i,k,iff-6).NE.missing_val) THEN
-                      zx_tmp_fi3d_STD(i,k) = O3sumSTD(i,k,iff-6) * 1.e+9
-                   ELSE
-                      zx_tmp_fi3d_STD(i,k) = missing_val
-                   ENDIF
-                ENDDO
-             ENDDO !k=1, nlevSTD
-          ENDIF
-          CALL histwrite_phy(o_tro3,zx_tmp_fi3d_STD,iff)
-          IF (read_climoz == 2) THEN
+       IF (.NOT. using_xios) THEN
+         IF (.NOT.ok_all_xml) THEN 
+           ! ATTENTION, LES ANCIENS HISTWRITE ONT ETES CONSERVES EN ATTENDANT MIEUX:
+           ! Champs interpolles sur des niveaux de pression
+           DO iff=7, nfiles-1 !--OB: here we deal with files 7,8,9
+
+             CALL histwrite_phy(o_tnondef,tnondef(:,:,iff-6),iff)
+             CALL histwrite_phy(o_ta,twriteSTD(:,:,iff-6),iff)
+             CALL histwrite_phy(o_zg,phiwriteSTD(:,:,iff-6),iff)
+             CALL histwrite_phy(o_hus,qwriteSTD(:,:,iff-6),iff)
+             CALL histwrite_phy(o_hur,rhwriteSTD(:,:,iff-6),iff)
+             CALL histwrite_phy(o_ua,uwriteSTD(:,:,iff-6),iff)
+             CALL histwrite_phy(o_va,vwriteSTD(:,:,iff-6),iff)
+             CALL histwrite_phy(o_wap,wwriteSTD(:,:,iff-6),iff)
              IF (vars_defined) THEN
-                DO k=1, nlevSTD
+               DO k=1, nlevSTD
+                  DO i=1, klon
+                     IF (tnondef(i,k,iff-6).NE.missing_val) THEN
+                       IF (freq_outNMC(iff-6).LT.0) THEN
+                          freq_moyNMC(iff-6)=(mth_len*un_jour)/freq_calNMC(iff-6)
+                       ELSE
+                          freq_moyNMC(iff-6)=freq_outNMC(iff-6)/freq_calNMC(iff-6)
+                       ENDIF
+                       zx_tmp_fi3d_STD(i,k) = (100.*tnondef(i,k,iff-6))/freq_moyNMC(iff-6)
+                     ELSE
+                       zx_tmp_fi3d_STD(i,k) = missing_val
+                     ENDIF
+                  ENDDO
+               ENDDO
+             ENDIF
+             CALL histwrite_phy(o_psbg,zx_tmp_fi3d_STD,iff)
+             IF (vars_defined) THEN
+               DO k=1, nlevSTD
+                  DO i=1, klon
+                    IF (O3sumSTD(i,k,iff-6).NE.missing_val) THEN
+                       zx_tmp_fi3d_STD(i,k) = O3sumSTD(i,k,iff-6) * 1.e+9
+                    ELSE
+                       zx_tmp_fi3d_STD(i,k) = missing_val
+                    ENDIF
+                  ENDDO
+               ENDDO !k=1, nlevSTD
+             ENDIF
+             CALL histwrite_phy(o_tro3,zx_tmp_fi3d_STD,iff)
+             IF (read_climoz == 2) THEN
+               IF (vars_defined) THEN
+                 DO k=1, nlevSTD
                    DO i=1, klon
                       IF (O3daysumSTD(i,k,iff-6).NE.missing_val) THEN
@@ -2432,24 +2430,25 @@
                       ENDIF
                    ENDDO
-                ENDDO !k=1, nlevSTD
+                 ENDDO !k=1, nlevSTD
+               ENDIF
+               CALL histwrite_phy(o_tro3_daylight,zx_tmp_fi3d_STD,iff)
              ENDIF
-             CALL histwrite_phy(o_tro3_daylight,zx_tmp_fi3d_STD,iff)
-          endif
-          CALL histwrite_phy(o_uxv,uvsumSTD(:,:,iff-6),iff)
-          CALL histwrite_phy(o_vxq,vqsumSTD(:,:,iff-6),iff)
-          CALL histwrite_phy(o_vxT,vTsumSTD(:,:,iff-6),iff)
-          CALL histwrite_phy(o_wxq,wqsumSTD(:,:,iff-6),iff)
-          CALL histwrite_phy(o_vxphi,vphisumSTD(:,:,iff-6),iff)
-          CALL histwrite_phy(o_wxT,wTsumSTD(:,:,iff-6),iff)
-          CALL histwrite_phy(o_uxu,u2sumSTD(:,:,iff-6),iff)
-          CALL histwrite_phy(o_vxv,v2sumSTD(:,:,iff-6),iff)
-          CALL histwrite_phy(o_TxT,T2sumSTD(:,:,iff-6),iff)
-       ENDDO !nfiles
-  ENDIF
+             CALL histwrite_phy(o_uxv,uvsumSTD(:,:,iff-6),iff)
+             CALL histwrite_phy(o_vxq,vqsumSTD(:,:,iff-6),iff)
+             CALL histwrite_phy(o_vxT,vTsumSTD(:,:,iff-6),iff)
+             CALL histwrite_phy(o_wxq,wqsumSTD(:,:,iff-6),iff)
+             CALL histwrite_phy(o_vxphi,vphisumSTD(:,:,iff-6),iff)
+             CALL histwrite_phy(o_wxT,wTsumSTD(:,:,iff-6),iff)
+             CALL histwrite_phy(o_uxu,u2sumSTD(:,:,iff-6),iff)
+             CALL histwrite_phy(o_vxv,v2sumSTD(:,:,iff-6),iff)
+             CALL histwrite_phy(o_TxT,T2sumSTD(:,:,iff-6),iff)
+           ENDDO !nfiles
+         ENDIF
+       ENDIF !.NOT. using_xios
 #endif
-#endif
-#ifdef CPP_XIOS
-  IF (ok_all_xml) THEN 
-!      DO iff=7, nfiles
+
+       IF (using_xios) THEN
+         IF (ok_all_xml) THEN 
+    !      DO iff=7, nfiles
 
 !         CALL histwrite_phy(o_tnondef,tnondef(:,:,3))
@@ -2514,6 +2513,6 @@
           CALL histwrite_phy(o_TxT,T2STD(:,:))
 !      ENDDO !nfiles
-  ENDIF
-#endif
+    ENDIF
+  ENDIF !using_xios
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        IF (iflag_phytrac == 1 ) then
@@ -2698,8 +2697,7 @@
           ENDDO !  iff
 #endif
-#ifdef CPP_XIOS
           !On finalise l'initialisation:
-          CALL wxios_closedef()
-#endif
+          IF (using_xios) CALL wxios_closedef()
+
           !$OMP END MASTER
           !$OMP BARRIER
Index: LMDZ6/trunk/libf/phylmd/physiq_mod.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/physiq_mod.F90	(revision 4618)
+++ LMDZ6/trunk/libf/phylmd/physiq_mod.F90	(revision 4619)
@@ -76,7 +76,5 @@
     USE vampir
     USE write_field_phy
-#ifdef CPP_XIOS
     USE wxios, ONLY: g_ctx, wxios_set_context
-#endif
     USE lscp_mod, ONLY : lscp
     USE lmdz_wake_ini, ONLY : wake_ini
@@ -134,11 +132,9 @@
 #endif
 
-
-#ifdef CPP_XIOS
-    USE xios, ONLY: xios_update_calendar, xios_context_finalize
-    USE xios, ONLY: xios_get_field_attr, xios_field_is_active, xios_context
-    USE xios, ONLY: xios_set_current_context
-    USE wxios, ONLY: missing_val, missing_val_omp
-#endif
+    USE lmdz_xios, ONLY: xios_update_calendar, xios_context_finalize
+    USE lmdz_xios, ONLY: xios_get_field_attr, xios_field_is_active, xios_context
+    USE lmdz_xios, ONLY: xios_set_current_context
+    USE wxios, ONLY: missing_val, using_xios
+
 #ifndef CPP_XIOS
     USE paramLMDZ_phy_mod
@@ -520,7 +516,4 @@
     REAL dtadd(klon,klev)
 
-#ifndef CPP_XIOS
-    REAL, SAVE :: missing_val=nf90_fill_real
-#endif
 !!   Variables moved to phys_local_var_mod
 !!    ! Variables pour le transport convectif
@@ -1276,11 +1269,13 @@
     CALL update_time(pdtphys)
     phys_tstep=NINT(pdtphys)
-#ifdef CPP_XIOS
-! switch to XIOS LMDZ physics context 
-    IF (.NOT. debut .AND. is_omp_master) THEN
-       CALL wxios_set_context()
-       CALL xios_update_calendar(itap+1)
-    ENDIF
-#endif
+    IF (.NOT. using_xios) missing_val=nf90_fill_real
+
+    IF (using_xios) THEN
+      ! switch to XIOS LMDZ physics context 
+      IF (.NOT. debut .AND. is_omp_master) THEN
+        CALL wxios_set_context()
+        CALL xios_update_calendar(itap+1)
+      ENDIF
+    ENDIF
 
     !======================================================================
@@ -1841,7 +1836,8 @@
 
 
-#ifdef CPP_XIOS
-       IF (is_omp_master) CALL xios_update_calendar(1)
-#endif
+       IF (using_xios) THEN
+         IF (is_omp_master) CALL xios_update_calendar(1)
+       ENDIF
+       
        IF(read_climoz>=1 .AND. create_etat0_limit) CALL regr_horiz_time_climoz(read_climoz,ok_daily_climoz)
        CALL create_etat0_limit_unstruct
@@ -2022,63 +2018,57 @@
        !=============================================================
 
-#ifdef CPP_XIOS
-       ! Get "missing_val" value from XML files (from temperature variable)
-       !$OMP MASTER
-       CALL xios_get_field_attr("temp",default_value=missing_val_omp)
-       !$OMP END MASTER
-       !$OMP BARRIER
-       missing_val=missing_val_omp
-#endif
-
-#ifdef CPP_XIOS 
-! Need to put this initialisation after phyetat0 as in the coupled model the XIOS context is only
-! initialised at that moment
-       ! Get "missing_val" value from XML files (from temperature variable)
-       !$OMP MASTER
-       CALL xios_get_field_attr("temp",default_value=missing_val_omp)
-       !$OMP END MASTER
-       !$OMP BARRIER
-       missing_val=missing_val_omp
+       IF (using_xios) THEN    
+         ! Get "missing_val" value from XML files (from temperature variable)
+         IF (is_omp_master) CALL xios_get_field_attr("temp",default_value=missing_val)
+         CALL bcast_omp(missing_val)
+       ENDIF
+
+       IF (using_xios) THEN    
+         ! Need to put this initialisation after phyetat0 as in the coupled model the XIOS context is only
+         ! initialised at that moment
+         ! Get "missing_val" value from XML files (from temperature variable)
+         IF (is_omp_master) CALL xios_get_field_attr("temp",default_value=missing_val)
+         CALL bcast_omp(missing_val)
        ! 
        ! Now we activate some double radiation call flags only if some
        ! diagnostics are requested, otherwise there is no point in doing this
-       IF (is_master) THEN
-         !--setting up swaero_diag to TRUE in XIOS case 
-         IF (xios_field_is_active("topswad").OR.xios_field_is_active("topswad0").OR. & 
-            xios_field_is_active("solswad").OR.xios_field_is_active("solswad0").OR. & 
-            xios_field_is_active("topswai").OR.xios_field_is_active("solswai").OR.  & 
-              (iflag_rrtm==1.AND.(xios_field_is_active("toplwad").OR.xios_field_is_active("toplwad0").OR. & 
-                                  xios_field_is_active("sollwad").OR.xios_field_is_active("sollwad0"))))  & 
-            !!!--for now these fields are not in the XML files so they are omitted 
-            !!!  xios_field_is_active("toplwai").OR.xios_field_is_active("sollwai") !))) & 
-            swaero_diag=.TRUE. 
+         IF (is_master) THEN
+           !--setting up swaero_diag to TRUE in XIOS case 
+           IF (xios_field_is_active("topswad").OR.xios_field_is_active("topswad0").OR. & 
+              xios_field_is_active("solswad").OR.xios_field_is_active("solswad0").OR. & 
+              xios_field_is_active("topswai").OR.xios_field_is_active("solswai").OR.  & 
+                (iflag_rrtm==1.AND.(xios_field_is_active("toplwad").OR.xios_field_is_active("toplwad0").OR. & 
+                                    xios_field_is_active("sollwad").OR.xios_field_is_active("sollwad0"))))  & 
+              !!!--for now these fields are not in the XML files so they are omitted 
+              !!!  xios_field_is_active("toplwai").OR.xios_field_is_active("sollwai") !))) & 
+              swaero_diag=.TRUE. 
  
-         !--setting up swaerofree_diag to TRUE in XIOS case 
-         IF (xios_field_is_active("SWdnSFCcleanclr").OR.xios_field_is_active("SWupSFCcleanclr").OR. &
-            xios_field_is_active("SWupTOAcleanclr").OR.xios_field_is_active("rsucsaf").OR.   &
-            xios_field_is_active("rsdcsaf") .OR. xios_field_is_active("LWdnSFCcleanclr").OR. &
-            xios_field_is_active("LWupTOAcleanclr")) &
-            swaerofree_diag=.TRUE. 
+           !--setting up swaerofree_diag to TRUE in XIOS case 
+           IF (xios_field_is_active("SWdnSFCcleanclr").OR.xios_field_is_active("SWupSFCcleanclr").OR. &
+              xios_field_is_active("SWupTOAcleanclr").OR.xios_field_is_active("rsucsaf").OR.   &
+              xios_field_is_active("rsdcsaf") .OR. xios_field_is_active("LWdnSFCcleanclr").OR. &
+              xios_field_is_active("LWupTOAcleanclr")) &
+              swaerofree_diag=.TRUE. 
  
-         !--setting up dryaod_diag to TRUE in XIOS case 
-         DO naero = 1, naero_tot-1
-          IF (xios_field_is_active("dryod550_"//name_aero_tau(naero))) dryaod_diag=.TRUE. 
-         ENDDO
-         !
-         !--setting up ok_4xCO2atm to TRUE in XIOS case 
-         IF (xios_field_is_active("rsut4co2").OR.xios_field_is_active("rlut4co2").OR. & 
-            xios_field_is_active("rsutcs4co2").OR.xios_field_is_active("rlutcs4co2").OR. &
-            xios_field_is_active("rsu4co2").OR.xios_field_is_active("rsucs4co2").OR. &
-            xios_field_is_active("rsd4co2").OR.xios_field_is_active("rsdcs4co2").OR. &
-            xios_field_is_active("rlu4co2").OR.xios_field_is_active("rlucs4co2").OR. &
-            xios_field_is_active("rld4co2").OR.xios_field_is_active("rldcs4co2")) &
-            ok_4xCO2atm=.TRUE. 
-       ENDIF
-       !$OMP BARRIER
-       CALL bcast(swaero_diag)
-       CALL bcast(swaerofree_diag)
-       CALL bcast(dryaod_diag)
-       CALL bcast(ok_4xCO2atm)
-#endif 
+           !--setting up dryaod_diag to TRUE in XIOS case 
+           DO naero = 1, naero_tot-1
+             IF (xios_field_is_active("dryod550_"//name_aero_tau(naero))) dryaod_diag=.TRUE. 
+           ENDDO
+           !
+          !--setting up ok_4xCO2atm to TRUE in XIOS case 
+           IF (xios_field_is_active("rsut4co2").OR.xios_field_is_active("rlut4co2").OR. & 
+              xios_field_is_active("rsutcs4co2").OR.xios_field_is_active("rlutcs4co2").OR. &
+              xios_field_is_active("rsu4co2").OR.xios_field_is_active("rsucs4co2").OR. &
+              xios_field_is_active("rsd4co2").OR.xios_field_is_active("rsdcs4co2").OR. &
+              xios_field_is_active("rlu4co2").OR.xios_field_is_active("rlucs4co2").OR. &
+              xios_field_is_active("rld4co2").OR.xios_field_is_active("rldcs4co2")) &
+              ok_4xCO2atm=.TRUE. 
+           ENDIF
+           !$OMP BARRIER
+           CALL bcast(swaero_diag)
+           CALL bcast(swaerofree_diag)
+           CALL bcast(dryaod_diag)
+           CALL bcast(ok_4xCO2atm)
+         ENDIF !using_xios
        !
        CALL printflag( tabcntr0,radpas,ok_journe, &
@@ -4509,16 +4499,16 @@
           cool = cool + betalwoff * (cool0 - cool)
  
-#ifndef CPP_XIOS
-          !
-          !IM 2eme calcul radiatif pour le cas perturbe ou au moins un
-          !IM des taux doit etre different du taux actuel
-          !IM Par defaut on a les taux perturbes egaux aux taux actuels
-          !
-          IF (RCO2_per.NE.RCO2_act.OR. &
-              RCH4_per.NE.RCH4_act.OR. &
-              RN2O_per.NE.RN2O_act.OR. &
-              RCFC11_per.NE.RCFC11_act.OR. &
-              RCFC12_per.NE.RCFC12_act) ok_4xCO2atm =.TRUE. 
-#endif
+          IF (.NOT. using_xios) THEN
+            !
+            !IM 2eme calcul radiatif pour le cas perturbe ou au moins un
+            !IM des taux doit etre different du taux actuel
+            !IM Par defaut on a les taux perturbes egaux aux taux actuels
+            !
+            IF (RCO2_per.NE.RCO2_act.OR. &
+                RCH4_per.NE.RCH4_act.OR. &
+                RN2O_per.NE.RN2O_act.OR. &
+                RCFC11_per.NE.RCFC11_act.OR. &
+                RCFC12_per.NE.RCFC12_act) ok_4xCO2atm =.TRUE. 
+          ENDIF
    ! 
           IF (ok_4xCO2atm) THEN
@@ -5558,5 +5548,5 @@
 
 #ifndef CPP_XIOS
-    CALL write_paramLMDZ_phy(itap,nid_ctesGCM,ok_sync)
+      CALL write_paramLMDZ_phy(itap,nid_ctesGCM,ok_sync)
 #endif
 
@@ -5604,16 +5594,16 @@
        
        ENDIF
-#ifdef CPP_XIOS
-       IF (is_omp_master) CALL xios_context_finalize
+
+       IF (using_xios) THEN
+         IF (is_omp_master) CALL xios_context_finalize
 
 #ifdef INCA
-       if (type_trac == 'inca') then 
-          IF (is_omp_master .and. grid_type==unstructured) THEN 
-             CALL finalize_inca
-          ENDIF
-       endif
+         if (type_trac == 'inca') then 
+            IF (is_omp_master .and. grid_type==unstructured) THEN 
+               CALL finalize_inca
+            ENDIF
+         endif
 #endif
-
-#endif
+       ENDIF 
        WRITE(lunout,*) ' physiq fin, nombre de steps ou cvpas = 1 : ', Ncvpaseq1
     ENDIF
Index: LMDZ6/trunk/libf/phylmd/plevel.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/plevel.F90	(revision 4618)
+++ LMDZ6/trunk/libf/phylmd/plevel.F90	(revision 4619)
@@ -12,7 +12,5 @@
   USE phys_state_var_mod, ONLY: missing_val_nf90 
 #endif
-#ifdef CPP_XIOS
-  USE wxios, ONLY: missing_val
-#endif
+  USE wxios, ONLY: missing_val_xios => missing_val, using_xios
   IMPLICIT NONE
 
@@ -60,13 +58,12 @@
 
 ! REAL missing_val
-#ifndef CPP_XIOS
   REAL :: missing_val
-#endif
 
 ! missing_val = nf90_fill_real
-
-#ifndef CPP_XIOS
-      missing_val=missing_val_nf90
-#endif
+  IF (using_xios) THEN
+    missing_val = missing_val_xios
+  ELSE
+    missing_val=missing_val_nf90
+  ENDIF
 
   IF (first) THEN
Index: LMDZ6/trunk/libf/phylmd/plevel_new.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/plevel_new.F90	(revision 4618)
+++ LMDZ6/trunk/libf/phylmd/plevel_new.F90	(revision 4619)
@@ -13,7 +13,5 @@
   USE phys_state_var_mod, ONLY: missing_val_nf90
 #endif
-#ifdef CPP_XIOS
-  USE wxios, ONLY: missing_val
-#endif
+  USE wxios, ONLY: missing_val_xios=>missing_val, using_xios
 
   IMPLICIT NONE
@@ -62,14 +60,11 @@
   INTEGER i, k
 
-! REAL missing_val
-#ifndef CPP_XIOS
   REAL :: missing_val
-#endif
 
-! missing_val = nf90_fill_real
-
-#ifndef CPP_XIOS
-      missing_val=missing_val_nf90
-#endif
+  IF (using_xios) THEN
+    missing_val=missing_val_xios
+  ELSE
+    missing_val=missing_val_nf90
+  ENDIF
 
   IF (first) THEN
Index: LMDZ6/trunk/libf/phylmd/readaerosol_mod.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/readaerosol_mod.F90	(revision 4618)
+++ LMDZ6/trunk/libf/phylmd/readaerosol_mod.F90	(revision 4619)
@@ -173,14 +173,11 @@
 
 
-  SUBROUTINE init_aero_fromfile(flag_aerosol)
+SUBROUTINE init_aero_fromfile(flag_aerosol)
   USE netcdf
   USE mod_phys_lmdz_para
   USE mod_grid_phy_lmdz, ONLY: grid_type, unstructured
-#ifdef CPP_XIOS
-  USE xios
-#endif
+  USE lmdz_xios
   IMPLICIT NONE
   INTEGER, INTENT(IN) :: flag_aerosol
-#ifdef CPP_XIOS
   REAL,ALLOCATABLE :: lat_src(:)
   REAL,ALLOCATABLE :: lon_src(:)
@@ -191,55 +188,56 @@
   REAL :: null_array(0)
 
-  IF (flag_aerosol>0 .AND. grid_type==unstructured) THEN
+  IF (using_xios) THEN
+    IF (flag_aerosol>0 .AND. grid_type==unstructured) THEN
   
-    IF (is_omp_root) THEN
+      IF (is_omp_root) THEN
   
-      IF (is_mpi_root) THEN
+        IF (is_mpi_root) THEN
     
-        IF (nf90_open(TRIM(file_aerosol), NF90_NOWRITE, ncid) /= NF90_NOERR) THEN
-          CALL check_err( nf90_open(TRIM(file_so4), NF90_NOWRITE, ncid), "pb open "//trim(file_so4) )
+          IF (nf90_open(TRIM(file_aerosol), NF90_NOWRITE, ncid) /= NF90_NOERR) THEN
+            CALL check_err( nf90_open(TRIM(file_so4), NF90_NOWRITE, ncid), "pb open "//trim(file_so4) )
+          ENDIF
+
+          ! Read and test longitudes
+          CALL check_err( nf90_inq_dimid(ncid, "lon", dimID),"pb inq dim lon") 
+          CALL check_err( nf90_inquire_dimension(ncid, dimID, len = nbp_lon_src),"pb inq dim lon")
+          CALL check_err( nf90_inq_varid(ncid, 'lon', varid),"pb inq lon" )
+          ALLOCATE(lon_src(nbp_lon_src))
+          CALL check_err( nf90_get_var(ncid, varid, lon_src(:)),"pb get lon" )
+
+          ! Read and test latitudes
+          CALL check_err( nf90_inq_dimid(ncid, "lat", dimID),"pb inq dim lat") 
+          CALL check_err( nf90_inquire_dimension(ncid, dimID, len = nbp_lat_src),"pb inq dim lat")
+          CALL check_err( nf90_inq_varid(ncid, 'lat', varid),"pb inq lat" )
+          ALLOCATE(lat_src(nbp_lat_src))
+          CALL check_err( nf90_get_var(ncid, varid, lat_src(:)),"pb get lat" )
+          IF (nf90_inq_dimid(ncid, 'lev', dimid) /= NF90_NOERR) THEN
+            IF (nf90_inq_dimid(ncid, 'presnivs', dimid)/= NF90_NOERR) THEN
+               CALL check_err(nf90_inq_dimid(ncid, 'PRESNIVS', dimid),'dimension lev,PRESNIVS or presnivs not in file')
+            ENDIF
+          ENDIF
+          CALL check_err( nf90_inquire_dimension(ncid, dimid, len = klev_src),"pb inq dim for PRESNIVS or lev" )
+          CALL check_err( nf90_close(ncid),"pb in close" )   
         ENDIF
 
-        ! Read and test longitudes
-        CALL check_err( nf90_inq_dimid(ncid, "lon", dimID),"pb inq dim lon") 
-        CALL check_err( nf90_inquire_dimension(ncid, dimID, len = nbp_lon_src),"pb inq dim lon")
-        CALL check_err( nf90_inq_varid(ncid, 'lon', varid),"pb inq lon" )
-        ALLOCATE(lon_src(nbp_lon_src))
-        CALL check_err( nf90_get_var(ncid, varid, lon_src(:)),"pb get lon" )
-
-        ! Read and test latitudes
-        CALL check_err( nf90_inq_dimid(ncid, "lat", dimID),"pb inq dim lat") 
-        CALL check_err( nf90_inquire_dimension(ncid, dimID, len = nbp_lat_src),"pb inq dim lat")
-        CALL check_err( nf90_inq_varid(ncid, 'lat', varid),"pb inq lat" )
-        ALLOCATE(lat_src(nbp_lat_src))
-        CALL check_err( nf90_get_var(ncid, varid, lat_src(:)),"pb get lat" )
-        IF (nf90_inq_dimid(ncid, 'lev', dimid) /= NF90_NOERR) THEN
-          IF (nf90_inq_dimid(ncid, 'presnivs', dimid)/= NF90_NOERR) THEN
-             CALL check_err(nf90_inq_dimid(ncid, 'PRESNIVS', dimid),'dimension lev,PRESNIVS or presnivs not in file')
-          ENDIF
+        CALL bcast_mpi(nbp_lat_src)
+        CALL bcast_mpi(nbp_lon_src)
+        CALL bcast_mpi(klev_src)
+
+        IF (is_mpi_root ) THEN
+          CALL xios_set_domain_attr("domain_aerosol",nj_glo=nbp_lat_src, nj=nbp_lat_src, jbegin=0, latvalue_1d=lat_src)
+          CALL xios_set_domain_attr("domain_aerosol",ni_glo=nbp_lon_src, ni=nbp_lon_src, ibegin=0, lonvalue_1d=lon_src)
+        ELSE
+          CALL xios_set_domain_attr("domain_aerosol",nj_glo=nbp_lat_src, nj=0, jbegin=0, latvalue_1d=null_array )
+          CALL xios_set_domain_attr("domain_aerosol",ni_glo=nbp_lon_src, ni=0, ibegin=0, lonvalue_1d=null_array)
         ENDIF
-        CALL check_err( nf90_inquire_dimension(ncid, dimid, len = klev_src),"pb inq dim for PRESNIVS or lev" )
-        CALL check_err( nf90_close(ncid),"pb in close" )   
+        CALL xios_set_axis_attr("axis_aerosol",n_glo=klev_src)
+        CALL xios_set_fieldgroup_attr("aerosols", enabled=.TRUE.)
+  
       ENDIF
-
-      CALL bcast_mpi(nbp_lat_src)
-      CALL bcast_mpi(nbp_lon_src)
-      CALL bcast_mpi(klev_src)
-
-      IF (is_mpi_root ) THEN
-        CALL xios_set_domain_attr("domain_aerosol",nj_glo=nbp_lat_src, nj=nbp_lat_src, jbegin=0, latvalue_1d=lat_src)
-        CALL xios_set_domain_attr("domain_aerosol",ni_glo=nbp_lon_src, ni=nbp_lon_src, ibegin=0, lonvalue_1d=lon_src)
-      ELSE
-        CALL xios_set_domain_attr("domain_aerosol",nj_glo=nbp_lat_src, nj=0, jbegin=0, latvalue_1d=null_array )
-        CALL xios_set_domain_attr("domain_aerosol",ni_glo=nbp_lon_src, ni=0, ibegin=0, lonvalue_1d=null_array)
-      ENDIF
-      CALL xios_set_axis_attr("axis_aerosol",n_glo=klev_src)
-      CALL xios_set_fieldgroup_attr("aerosols", enabled=.TRUE.)
-  
-    ENDIF
     
-  ENDIF    
-#endif 
-  END SUBROUTINE init_aero_fromfile
+    ENDIF    
+  ENDIF !using_xios 
+END SUBROUTINE init_aero_fromfile
 
 
@@ -271,7 +269,5 @@
     USE iophy, ONLY : io_lon, io_lat
     USE print_control_mod, ONLY: lunout
-#ifdef CPP_XIOS
-    USE xios
-#endif
+    USE lmdz_xios
     IMPLICIT NONE
       
@@ -685,5 +681,4 @@
 
     IF (grid_type==unstructured) THEN
-#ifdef CPP_XIOS
       IF (is_omp_master) THEN
         CALL xios_send_field(TRIM(varname)//"_in",varyear)
@@ -702,5 +697,4 @@
       CALL scatter_omp(psurf_interp,psurf_out)
       first=.FALSE.
-#endif
     ELSE
       ! Scatter global field to local domain at local process
Index: LMDZ6/trunk/libf/phylmd/readaerosolstrato.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/readaerosolstrato.F90	(revision 4618)
+++ LMDZ6/trunk/libf/phylmd/readaerosolstrato.F90	(revision 4619)
@@ -16,7 +16,5 @@
     USE dimphy
     USE print_control_mod, ONLY: prt_level,lunout
-#ifdef CPP_XIOS
-    USE xios
-#endif
+    USE lmdz_xios
     implicit none
 
@@ -148,5 +146,4 @@
 
     IF (grid_type==unstructured) THEN
-#ifdef CPP_XIOS
       IF (is_omp_master) THEN
         CALL xios_send_field("taustrat_in",tauaerstrat_mois)
@@ -157,5 +154,4 @@
       ENDIF
       CALL scatter_omp(tau_aer_strat_mpi,tau_aer_strat)
-#endif
     ELSE  
 !--scatter on all proc
Index: LMDZ6/trunk/libf/phylmd/readaerosolstrato_m.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/readaerosolstrato_m.F90	(revision 4618)
+++ LMDZ6/trunk/libf/phylmd/readaerosolstrato_m.F90	(revision 4619)
@@ -23,11 +23,10 @@
 
 
-  SUBROUTINE init_readaerosolstrato1
-#ifdef CPP_XIOS
+SUBROUTINE init_readaerosolstrato1
   USE netcdf
   USE netcdf95, ONLY: nf95_close, nf95_gw_var, nf95_inq_dimid, & 
                       nf95_inq_varid, nf95_open
   USE mod_phys_lmdz_para
-  USE xios
+  USE lmdz_xios
 !  USE YOERAD, ONLY : NLW
   IMPLICIT NONE
@@ -38,4 +37,5 @@
   INTEGER :: ncid_in, varid
   
+  IF (using_xios) THEN
     IF (is_omp_master) THEN  
       IF (is_mpi_root) THEN
@@ -63,14 +63,13 @@
     ENDIF
     
-#endif
-  END SUBROUTINE init_readaerosolstrato1
+  ENDIF
+END SUBROUTINE init_readaerosolstrato1
   
-  SUBROUTINE init_readaerosolstrato2
-#ifdef CPP_XIOS
+SUBROUTINE init_readaerosolstrato2
   USE netcdf
   USE netcdf95, ONLY: nf95_close, nf95_gw_var, nf95_inq_dimid, & 
                       nf95_inq_varid, nf95_open
   USE mod_phys_lmdz_para
-  USE xios
+  USE lmdz_xios
 !  USE YOERAD, ONLY : NLW
   IMPLICIT NONE
@@ -80,5 +79,6 @@
   REAL    :: null_array(0)
   INTEGER :: ncid_in, varid
-
+  
+  IF (using_xios) THEN
     IF (is_omp_master) THEN    
       IF (is_mpi_root) THEN
@@ -131,6 +131,6 @@
 
     ENDIF
-#endif    
-  END SUBROUTINE init_readaerosolstrato2
+  ENDIF    
+END SUBROUTINE init_readaerosolstrato2
   
 
Index: LMDZ6/trunk/libf/phylmd/regr_horiz_time_climoz_m.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/regr_horiz_time_climoz_m.F90	(revision 4618)
+++ LMDZ6/trunk/libf/phylmd/regr_horiz_time_climoz_m.F90	(revision 4619)
@@ -66,7 +66,5 @@
   USE regular_lonlat_mod, ONLY: boundslon_reg, boundslat_reg, south, west, east
   USE slopes_m,           ONLY: slopes
-#ifdef CPP_XIOS
-  USE xios
-#endif
+  USE lmdz_xios
   USE mod_phys_lmdz_para, ONLY: is_mpi_root, is_master, is_omp_master, gather, gather_mpi, bcast_mpi, klon_mpi
   USE geometry_mod, ONLY : latitude_deg, ind_cell_glo
@@ -240,5 +238,4 @@
       CALL bcast_mpi(ntim_ou)
 
-#ifdef CPP_XIOS    
       IF (is_mpi_root) THEN
         CALL xios_set_domain_attr("domain_climoz",nj_glo=nlat_in, nj=nlat_in, jbegin=0, latvalue_1d=lat_in/deg2rad)
@@ -262,5 +259,4 @@
       CALL  xios_set_field_attr("tro3_out", enabled=.TRUE.)
       CALL  xios_set_field_attr("tro3_out", enabled=.TRUE.)
-#endif
       
       IF (first) THEN
@@ -415,5 +411,4 @@
     !=============================================================================
      IF (grid_type==unstructured) THEN
-#ifdef CPP_XIOS
        nlat_ou=klon_mpi
        
@@ -428,5 +423,4 @@
        CALL xios_send_field("tro3_in",o3_in3bis(:,:,:,:,:))
        CALL xios_recv_field("tro3_out",o3_regr_lonlat(1,:,:,:,:))
-#endif
      ELSE
           
@@ -462,10 +456,8 @@
      nlat_ou=nbp_lat
      IF (grid_type==unstructured) THEN
-#ifdef CPP_XIOS
        CALL xios_send_field('o3_out',o3_out3)
        ndims=3 
        ALLOCATE(o3_out3_glo(nlat_ou, nlev_in, ntim_ou, read_climoz))
        CALL gather_mpi(o3_out3(1,:,:,:,:), o3_out3_glo)
-#endif
      ENDIF
 
@@ -508,5 +500,4 @@
    
      IF (grid_type==unstructured) THEN
-#ifdef CPP_XIOS
        nlat_ou=klon_mpi
 
@@ -522,5 +513,4 @@
        IF(.NOT.lprev) o3_regr_lat(:,:, 0, :) = o3_regr_lat(:,:,12,:)
        IF(.NOT.lnext) o3_regr_lat(:,:,13, :) = o3_regr_lat(:,:, 1,:)
-#endif       
      
      ELSE 
Index: LMDZ6/trunk/libf/phylmd/rrtm/readaerosolstrato1_rrtm.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/rrtm/readaerosolstrato1_rrtm.F90	(revision 4618)
+++ LMDZ6/trunk/libf/phylmd/rrtm/readaerosolstrato1_rrtm.F90	(revision 4619)
@@ -18,7 +18,5 @@
     USE YOERAD, ONLY : NLW
     USE YOMCST
-#ifdef CPP_XIOS
-    USE xios
-#endif
+    USE lmdz_xios
 
     IMPLICIT NONE
@@ -167,5 +165,4 @@
     
     IF (grid_type==unstructured) THEN
-#ifdef CPP_XIOS
       IF (is_omp_master) THEN
         ALLOCATE(tauaerstrat_mpi(klon_mpi,klev))
@@ -176,5 +173,4 @@
       ENDIF
       CALL scatter_omp(tauaerstrat_mpi,tau_aer_strat)
-#endif
     ELSE  
       CALL scatter(tauaerstrat_mois_glo,tau_aer_strat)
Index: LMDZ6/trunk/libf/phylmd/rrtm/readaerosolstrato2_rrtm.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/rrtm/readaerosolstrato2_rrtm.F90	(revision 4618)
+++ LMDZ6/trunk/libf/phylmd/rrtm/readaerosolstrato2_rrtm.F90	(revision 4619)
@@ -19,7 +19,5 @@
     USE YOERAD, ONLY : NLW
     USE YOMCST
-#ifdef CPP_XIOS
-    USE xios
-#endif
+    USE lmdz_xios
 
     IMPLICIT NONE
@@ -282,6 +280,4 @@
 
       IF (grid_type==unstructured) THEN
-
-#ifdef CPP_XIOS
 
         IF (is_omp_master) THEN
@@ -310,5 +306,4 @@
         CALL scatter_omp(cgaerstrat_mpi,cg_aer_strat)
         CALL scatter_omp(taulwaerstrat_mpi,taulw_aer_strat)
-#endif
       ELSE  
         
Index: LMDZ6/trunk/libf/phylmd/undefSTD.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/undefSTD.F90	(revision 4618)
+++ LMDZ6/trunk/libf/phylmd/undefSTD.F90	(revision 4619)
@@ -8,13 +8,9 @@
   USE phys_state_var_mod
 #endif
-#ifdef CPP_XIOS
-  USE wxios, ONLY: missing_val
-#endif
+  USE wxios, ONLY: missing_val_xios => missing_val, using_xios
 
   IMPLICIT NONE
   include "clesphys.h"
-#ifndef CPP_XIOS 
   REAL :: missing_val
-#endif
 
   ! ====================================================================
@@ -59,7 +55,9 @@
 
 ! missing_val = nf90_fill_real
-#ifndef CPP_XIOS
+  IF (using_xios) THEN
+    missing_val=missing_val_xios
+  ELSE
       missing_val=missing_val_nf90
-#endif
+  ENDIF
 
   DO n = 1, nout
Index: LMDZ6/trunk/libf/phylmdiso/limit_read_mod.F90
===================================================================
--- LMDZ6/trunk/libf/phylmdiso/limit_read_mod.F90	(revision 4618)
+++ LMDZ6/trunk/libf/phylmdiso/limit_read_mod.F90	(revision 4619)
@@ -40,7 +40,5 @@
   USE surface_data
   USE mod_phys_lmdz_para
-#ifdef CPP_XIOS
-  USE XIOS
-#endif
+  USE lmdz_xios
   IMPLICIT NONE
     INTEGER, INTENT(IN) :: first_day
@@ -49,7 +47,5 @@
     IF ( type_ocean /= 'couple') THEN
       IF (grid_type==unstructured) THEN
-#ifdef CPP_XIOS
-        IF (is_omp_master) CALL xios_set_file_attr("limit_read",enabled=.TRUE.,record_offset=first_day)
-#endif
+          IF (is_omp_master) CALL xios_set_file_attr("limit_read",enabled=.TRUE.,record_offset=first_day)
       ENDIF  
     ENDIF
@@ -288,7 +284,5 @@
     USE phys_cal_mod, ONLY : calend, year_len
     USE print_control_mod, ONLY: lunout, prt_level
-#ifdef CPP_XIOS
-    USE XIOS, ONLY: xios_recv_field
-#endif
+    USE lmdz_XIOS, ONLY: xios_recv_field
     
     IMPLICIT NONE
@@ -416,5 +410,4 @@
       IF (grid_type==unstructured) THEN
 
-#ifdef CPP_XIOS
         IF ( type_ocean /= 'couple') THEN
 
@@ -450,7 +443,5 @@
           CALL Scatter_omp(rug_mpi, rugos)
        END IF
-#endif
-
- 
+
      ELSE      ! grid_type==regular
 
Index: LMDZ6/trunk/libf/phylmdiso/pbl_surface_mod.F90
===================================================================
--- LMDZ6/trunk/libf/phylmdiso/pbl_surface_mod.F90	(revision 4618)
+++ LMDZ6/trunk/libf/phylmdiso/pbl_surface_mod.F90	(revision 4619)
@@ -412,12 +412,6 @@
     use phys_output_var_mod, only: tkt, tks, taur, sss
     use blowing_snow_ini_mod, only : zeta_bs
-#ifdef CPP_XIOS
-    USE wxios, ONLY: missing_val
-#else
-    use netcdf, only: missing_val => nf90_fill_real
-#endif
-
-     
-
+    USE wxios, ONLY: missing_val_xios => missing_val, using_xios
+    use netcdf, only: nf90_fill_real
 
     IMPLICIT NONE
@@ -944,5 +938,5 @@
     REAL, DIMENSION(klon)       :: uzon_w, vmer_w, speed_w, zri1_w, pref_w !speed_w, zri1_w, pref_w, added by Fuxing WANG, 04/03/2015
     REAL, DIMENSION(klon)       :: zgeo1_w, tair1_w, qair1_w, tairsol_w
-
+    
 !!! jyg le 25/03/2013
 !!    Variables intermediaires pour le raccord des deux colonnes \`a la surface
@@ -1051,5 +1045,5 @@
     ! compression of delta_sst, delta_sal, ds_ns, dt_ns, dter, dser,
     ! dt_ds, tkt, tks, taur, sss on ocean points
-
+    REAL :: missing_val
 #ifdef ISO
     REAL, DIMENSION(klon)       :: h1
@@ -1063,6 +1057,12 @@
 ! End of declarations
 !****************************************************************************************
-
+    
       IF (prt_level >=10) print *,' -> pbl_surface, itap ',itap
+      
+      IF (using_xios) THEN
+        missing_val = missing_val_xios
+      ELSE
+        missing_val = nf90_fill_real
+      ENDIF
 !
 !!jyg      iflag_split = mod(iflag_pbl_split,2)
Index: LMDZ6/trunk/libf/phylmdiso/phyaqua_mod.F90
===================================================================
--- LMDZ6/trunk/libf/phylmdiso/phyaqua_mod.F90	(revision 4618)
+++ LMDZ6/trunk/libf/phylmdiso/phyaqua_mod.F90	(revision 4619)
@@ -536,7 +536,5 @@
     USE mod_phys_lmdz_para, ONLY: is_omp_master, klon_mpi
     USE mod_phys_lmdz_transfert_para, ONLY: gather_omp
-#ifdef CPP_XIOS
-    USE xios
-#endif
+    USE lmdz_xios
     IMPLICIT NONE
 
@@ -558,5 +556,4 @@
       ! on the whole physics grid
  
-#ifdef CPP_XIOS
     PRINT *, 'writelim: Ecriture du fichier limit'
 
@@ -584,5 +581,5 @@
     CALL gather_omp(phy_rug, phy_mpi)
     IF (is_omp_master) CALL xios_send_field('rug_limout',phy_mpi)
-#endif
+
   END SUBROUTINE writelim_unstruct
 
Index: LMDZ6/trunk/libf/phylmdiso/phyetat0_mod.F90
===================================================================
--- LMDZ6/trunk/libf/phylmdiso/phyetat0_mod.F90	(revision 4618)
+++ LMDZ6/trunk/libf/phylmdiso/phyetat0_mod.F90	(revision 4619)
@@ -47,9 +47,6 @@
   USE ocean_slab_mod,   ONLY: nslay, tslab, seaice, tice, ocean_slab_init
   USE time_phylmdz_mod, ONLY: init_iteration, pdtphys, itau_phy
-#ifdef CPP_XIOS
-  USE wxios, ONLY: missing_val
-#else
-  use netcdf, only: missing_val => nf90_fill_real
-#endif
+  USE wxios, ONLY: missing_val_xios => missing_val, using_xios
+  use netcdf, only:  nf90_fill_real
   use config_ocean_skin_m, only: activate_ocean_skin
 #ifdef ISO
@@ -108,5 +105,5 @@
   REAL :: lon_startphy(klon), lat_startphy(klon)
   CHARACTER(LEN=maxlen) :: tname, t(2)
-
+  REAL :: missing_val
 #ifdef ISO
   REAL xtsnow(niso,klon, nbsrf)
@@ -119,4 +116,9 @@
 
   ! Ouvrir le fichier contenant l'etat initial:
+  IF (using_xios) THEN
+    missing_val = missing_val_xios
+  ELSE
+    missing_val =  nf90_fill_real
+  ENDIF
 
   CALL open_startphy(fichnom)
Index: LMDZ6/trunk/libf/phylmdiso/phys_output_mod.F90
===================================================================
--- LMDZ6/trunk/libf/phylmdiso/phys_output_mod.F90	(revision 4618)
+++ LMDZ6/trunk/libf/phylmdiso/phys_output_mod.F90	(revision 4619)
@@ -47,8 +47,6 @@
     USE vertical_layers_mod, ONLY: ap,bp,preff,presnivs, aps, bps, pseudoalt
     USE time_phylmdz_mod, ONLY: day_ini, itau_phy, start_time, annee_ref, day_ref
-#ifdef CPP_XIOS
     ! ug Pour les sorties XIOS
     USE wxios
-#endif
 #ifdef ISO
     USE isotopes_mod, ONLY: isoName,iso_HTO
@@ -140,5 +138,4 @@
     REAL, DIMENSION(klev+1)   :: lev_index
                 
-#ifdef CPP_XIOS
     ! ug Variables utilis\'ees pour r\'ecup\'erer le calendrier pour xios
     INTEGER :: x_an, x_mois, x_jour
@@ -146,5 +143,4 @@
     INTEGER :: ini_an, ini_mois, ini_jour
     REAL :: ini_heure
-#endif
     INTEGER                         :: ISW
     REAL, DIMENSION(NSW)            :: wl1_sun, wl2_sun !wavelength bounds (in um) for SW
@@ -326,12 +322,12 @@
      ENDIF
 
-#ifdef CPP_XIOS
-    ! ug R\'eglage du calendrier xios
-    !Temps julian => an, mois, jour, heure
-    CALL ju2ymds(zjulian, x_an, x_mois, x_jour, x_heure)
-    CALL ju2ymds(zjulian_start, ini_an, ini_mois, ini_jour, ini_heure)
-    CALL wxios_set_cal(dtime, calend, x_an, x_mois, x_jour, x_heure, ini_an, &
-                       ini_mois, ini_jour, ini_heure )
-#endif
+    IF (using_xios) THEN
+      ! ug R\'eglage du calendrier xios
+      !Temps julian => an, mois, jour, heure
+      CALL ju2ymds(zjulian, x_an, x_mois, x_jour, x_heure)
+      CALL ju2ymds(zjulian_start, ini_an, ini_mois, ini_jour, ini_heure)
+      CALL wxios_set_cal(dtime, calend, x_an, x_mois, x_jour, x_heure, ini_an, &
+                         ini_mois, ini_jour, ini_heure )
+    ENDIF
 
 !!!!!!!!!!!!!!!!!!!!!!! Boucle sur les fichiers !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -366,62 +362,62 @@
 
 
-#ifdef CPP_XIOS
+    IF (using_xios) THEN
 !!! Ouverture de chaque fichier XIOS !!!!!!!!!!!
-    IF (.not. ok_all_xml) THEN
+      IF (.not. ok_all_xml) THEN
+        IF (prt_level >= 10) THEN
+         print*,'phys_output_open: call wxios_add_file with phys_out_filenames(iff)=',trim(phys_out_filenames(iff))    
+        ENDIF
+        CALL wxios_add_file(phys_out_filenames(iff),chtimestep(iff),lev_files(iff))  
+      ENDIF
+
+!!! Declaration des axes verticaux de chaque fichier:
       IF (prt_level >= 10) THEN
-        print*,'phys_output_open: call wxios_add_file with phys_out_filenames(iff)=',trim(phys_out_filenames(iff))    
+        print*,'phys_output_open: Declare vertical axes for each file'
       ENDIF
-      CALL wxios_add_file(phys_out_filenames(iff),chtimestep(iff),lev_files(iff))  
-    ENDIF
-
-!!! Declaration des axes verticaux de chaque fichier:
-    IF (prt_level >= 10) THEN
-      print*,'phys_output_open: Declare vertical axes for each file'
-    ENDIF
-
-   IF (iff.LE.6.OR.iff.EQ.10) THEN
-    CALL wxios_add_vaxis("presnivs", &
-            levmax(iff) - levmin(iff) + 1, presnivs(levmin(iff):levmax(iff)))
-    CALL wxios_add_vaxis("Ahyb", &
+
+      IF (iff.LE.6.OR.iff.EQ.10) THEN
+        CALL wxios_add_vaxis("presnivs", &
+             levmax(iff) - levmin(iff) + 1, presnivs(levmin(iff):levmax(iff)))
+        CALL wxios_add_vaxis("Ahyb", &
             levmax(iff) - levmin(iff) + 1, aps(levmin(iff):levmax(iff)), positif='down', &
             bnds=Ahyb_bounds(levmin(iff):levmax(iff),:))
-    CALL wxios_add_vaxis("Bhyb", &
+        CALL wxios_add_vaxis("Bhyb", &
             levmax(iff) - levmin(iff) + 1, bps(levmin(iff):levmax(iff)), positif='down', &
             bnds=Bhyb_bounds(levmin(iff):levmax(iff),:))
-    CALL wxios_add_vaxis("klev", levmax(iff) - levmin(iff) + 1, &
+        CALL wxios_add_vaxis("klev", levmax(iff) - levmin(iff) + 1, &
                           lev_index(levmin(iff):levmax(iff)))
-    CALL wxios_add_vaxis("klevp1", klev+1, &
+        CALL wxios_add_vaxis("klevp1", klev+1, &
                           lev_index(1:klev+1))
-    CALL wxios_add_vaxis("bnds", 2, (/1.,2./))
-
-    CALL wxios_add_vaxis("Alt", &
+        CALL wxios_add_vaxis("bnds", 2, (/1.,2./))
+
+        CALL wxios_add_vaxis("Alt", &
             levmax(iff) - levmin(iff) + 1, pseudoalt)
-
-    ! wl1_sun/wl2_sun: minimum/maximum bound of wavelength (in um)
-    SELECT CASE(NSW)
-      CASE(6)
-        wl1_sun(1:6) = [0.180, 0.250, 0.440, 0.690, 1.190, 2.380]
-        wl2_sun(1:6) = [0.250, 0.440, 0.690, 1.190, 2.380, 4.000]
-      CASE(2)
-        wl1_sun(1:2) = [0.250, 0.690]
-        wl2_sun(1:2) = [0.690, 4.000]
-    END SELECT
-
-    DO ISW=1, NSW
-     wn1_sun(ISW)=1.e+6/wl1_sun(ISW) 
-     wn2_sun(ISW)=1.e+6/wl2_sun(ISW) 
-     spbnds_sun(ISW,1)=wn2_sun(ISW)
-     spbnds_sun(ISW,2)=wn1_sun(ISW)
-     spectband(ISW)=(wn1_sun(ISW)+wn2_sun(ISW))/2
-    ENDDO
+  
+        ! wl1_sun/wl2_sun: minimum/maximum bound of wavelength (in um)
+        SELECT CASE(NSW)
+          CASE(6)
+          wl1_sun(1:6) = [0.180, 0.250, 0.440, 0.690, 1.190, 2.380]
+          wl2_sun(1:6) = [0.250, 0.440, 0.690, 1.190, 2.380, 4.000]
+        CASE(2)
+          wl1_sun(1:2) = [0.250, 0.690]
+          wl2_sun(1:2) = [0.690, 4.000]
+        END SELECT
+
+        DO ISW=1, NSW
+          wn1_sun(ISW)=1.e+6/wl1_sun(ISW) 
+          wn2_sun(ISW)=1.e+6/wl2_sun(ISW) 
+          spbnds_sun(ISW,1)=wn2_sun(ISW)
+          spbnds_sun(ISW,2)=wn1_sun(ISW)
+          spectband(ISW)=(wn1_sun(ISW)+wn2_sun(ISW))/2
+        ENDDO
 !
 !!! ajout axe vertical spectband : solar band number
-    CALL wxios_add_vaxis("spectband", NSW, spectband, positif='down')
-   ELSE
+        CALL wxios_add_vaxis("spectband", NSW, spectband, positif='down')
+      ELSE
     ! NMC files
-    CALL wxios_add_vaxis("plev", &
+        CALL wxios_add_vaxis("plev", &
             levmax(iff) - levmin(iff) + 1, rlevSTD(levmin(iff):levmax(iff)))
-   ENDIF
-#endif 
+      ENDIF
+    ENDIF 
 
         IF (clef_files(iff)) THEN
Index: LMDZ6/trunk/libf/phylmdiso/physiq_mod.F90
===================================================================
--- LMDZ6/trunk/libf/phylmdiso/physiq_mod.F90	(revision 4618)
+++ LMDZ6/trunk/libf/phylmdiso/physiq_mod.F90	(revision 4619)
@@ -76,7 +76,5 @@
     USE vampir
     USE write_field_phy
-#ifdef CPP_XIOS
-    USE wxios, ONLY: g_ctx, wxios_set_context
-#endif
+    USE wxios, ONLY: g_ctx, wxios_set_context, using_xios
     USE lscp_mod, ONLY : lscp
     USE lmdz_wake_ini, ONLY : wake_ini
@@ -134,10 +132,9 @@
 
 
-#ifdef CPP_XIOS
-    USE xios, ONLY: xios_update_calendar, xios_context_finalize
-    USE xios, ONLY: xios_get_field_attr, xios_field_is_active, xios_context
-    USE xios, ONLY: xios_set_current_context
-    USE wxios, ONLY: missing_val, missing_val_omp
-#endif
+    USE lmdz_xios, ONLY: xios_update_calendar, xios_context_finalize
+    USE lmdz_xios, ONLY: xios_get_field_attr, xios_field_is_active, xios_context
+    USE lmdz_xios, ONLY: xios_set_current_context
+    USE wxios, ONLY: missing_val_xios => missing_val
+
 #ifndef CPP_XIOS
     USE paramLMDZ_phy_mod
@@ -1326,5 +1323,5 @@
     real xtql1(ntraciso,klon),xtql2(ntraciso,klon),corrxtql(ntraciso)
 #endif
-
+    
     REAL pi
 
@@ -1343,4 +1340,5 @@
     CALL update_time(pdtphys)
     phys_tstep=NINT(pdtphys)
+    IF (.NOT. using_xios) missing_val=nf90_fill_real
 #ifdef CPP_XIOS
 ! switch to XIOS LMDZ physics context 
@@ -2150,22 +2148,17 @@
        !=============================================================
 
-#ifdef CPP_XIOS
-       ! Get "missing_val" value from XML files (from temperature variable)
-       !$OMP MASTER
-       CALL xios_get_field_attr("temp",default_value=missing_val_omp)
-       !$OMP END MASTER
-       !$OMP BARRIER
-       missing_val=missing_val_omp
-#endif
-
-#ifdef CPP_XIOS 
+       IF (using_xios) THEN    
+         ! Get "missing_val" value from XML files (from temperature variable)
+         IF (is_omp_master) CALL xios_get_field_attr("temp",default_value=missing_val)
+         CALL bcast_omp(missing_val)
+       ENDIF
+
+      IF (using_xios) THEN 
 ! Need to put this initialisation after phyetat0 as in the coupled model the XIOS context is only
 ! initialised at that moment
        ! Get "missing_val" value from XML files (from temperature variable)
-       !$OMP MASTER
-       CALL xios_get_field_attr("temp",default_value=missing_val_omp)
-       !$OMP END MASTER
-       !$OMP BARRIER
-       missing_val=missing_val_omp
+        IF (is_omp_master) CALL xios_get_field_attr("temp",default_value=missing_val)
+        CALL bcast_omp(missing_val)
+       
        ! 
        ! Now we activate some double radiation call flags only if some
@@ -2208,5 +2201,7 @@
        CALL bcast(dryaod_diag)
        CALL bcast(ok_4xCO2atm)
-#endif 
+
+     ENDIF !using_xios 
+
        !
        CALL printflag( tabcntr0,radpas,ok_journe, &
@@ -5773,16 +5768,16 @@
           cool = cool + betalwoff * (cool0 - cool)
  
-#ifndef CPP_XIOS
-          !
-          !IM 2eme calcul radiatif pour le cas perturbe ou au moins un
-          !IM des taux doit etre different du taux actuel
-          !IM Par defaut on a les taux perturbes egaux aux taux actuels
-          !
-          IF (RCO2_per.NE.RCO2_act.OR. &
-              RCH4_per.NE.RCH4_act.OR. &
-              RN2O_per.NE.RN2O_act.OR. &
-              RCFC11_per.NE.RCFC11_act.OR. &
-              RCFC12_per.NE.RCFC12_act) ok_4xCO2atm =.TRUE. 
-#endif
+          IF (.NOT. using_xios) THEN
+            !
+            !IM 2eme calcul radiatif pour le cas perturbe ou au moins un
+            !IM des taux doit etre different du taux actuel
+            !IM Par defaut on a les taux perturbes egaux aux taux actuels
+            !
+            IF (RCO2_per.NE.RCO2_act.OR. &
+                RCH4_per.NE.RCH4_act.OR. &
+                RN2O_per.NE.RN2O_act.OR. &
+                RCFC11_per.NE.RCFC11_act.OR. &
+                RCFC12_per.NE.RCFC12_act) ok_4xCO2atm =.TRUE. 
+          ENDIF
    ! 
           IF (ok_4xCO2atm) THEN
@@ -7005,50 +7000,51 @@
 ! Pour XIOS : On remet des variables a .false. apres un premier appel
     IF (debut) THEN
-#ifdef CPP_XIOS
-      swaero_diag=.FALSE.
-      swaerofree_diag=.FALSE.
-      dryaod_diag=.FALSE.
-      ok_4xCO2atm= .FALSE.
-!      write (lunout,*)'ok_4xCO2atm= ',swaero_diag, swaerofree_diag, dryaod_diag, ok_4xCO2atm
-
-      IF (is_master) THEN
-        !--setting up swaero_diag to TRUE in XIOS case 
-        IF (xios_field_is_active("topswad").OR.xios_field_is_active("topswad0").OR. & 
-           xios_field_is_active("solswad").OR.xios_field_is_active("solswad0").OR. & 
-           xios_field_is_active("topswai").OR.xios_field_is_active("solswai").OR.  & 
-             (iflag_rrtm==1.AND.(xios_field_is_active("toplwad").OR.xios_field_is_active("toplwad0").OR. & 
-                                 xios_field_is_active("sollwad").OR.xios_field_is_active("sollwad0"))))  & 
-           !!!--for now these fields are not in the XML files so they are omitted 
-           !!!  xios_field_is_active("toplwai").OR.xios_field_is_active("sollwai") !))) & 
-           swaero_diag=.TRUE. 
-
-        !--setting up swaerofree_diag to TRUE in XIOS case 
-        IF (xios_field_is_active("SWdnSFCcleanclr").OR.xios_field_is_active("SWupSFCcleanclr").OR. &
-           xios_field_is_active("SWupTOAcleanclr").OR.xios_field_is_active("rsucsaf").OR.   &
-           xios_field_is_active("rsdcsaf") .OR. xios_field_is_active("LWdnSFCcleanclr").OR. &
-           xios_field_is_active("LWupTOAcleanclr")) &
-           swaerofree_diag=.TRUE. 
-
-        !--setting up dryaod_diag to TRUE in XIOS case 
-        DO naero = 1, naero_tot-1
-         IF (xios_field_is_active("dryod550_"//name_aero_tau(naero))) dryaod_diag=.TRUE. 
-        ENDDO
-        !
-        !--setting up ok_4xCO2atm to TRUE in XIOS case 
-        IF (xios_field_is_active("rsut4co2").OR.xios_field_is_active("rlut4co2").OR. & 
-           xios_field_is_active("rsutcs4co2").OR.xios_field_is_active("rlutcs4co2").OR. &
-           xios_field_is_active("rsu4co2").OR.xios_field_is_active("rsucs4co2").OR. &
-           xios_field_is_active("rsd4co2").OR.xios_field_is_active("rsdcs4co2").OR. &
-           xios_field_is_active("rlu4co2").OR.xios_field_is_active("rlucs4co2").OR. &
-           xios_field_is_active("rld4co2").OR.xios_field_is_active("rldcs4co2")) &
-           ok_4xCO2atm=.TRUE. 
-      ENDIF
-      !$OMP BARRIER
-      CALL bcast(swaero_diag)
-      CALL bcast(swaerofree_diag)
-      CALL bcast(dryaod_diag)
-      CALL bcast(ok_4xCO2atm)
-!      write (lunout,*)'ok_4xCO2atm= ',swaero_diag, swaerofree_diag, dryaod_diag, ok_4xCO2atm
-#endif
+
+      IF (using_xios) THEN
+        swaero_diag=.FALSE.
+        swaerofree_diag=.FALSE.
+        dryaod_diag=.FALSE.
+        ok_4xCO2atm= .FALSE.
+!       write (lunout,*)'ok_4xCO2atm= ',swaero_diag, swaerofree_diag, dryaod_diag, ok_4xCO2atm
+
+        IF (is_master) THEN
+          !--setting up swaero_diag to TRUE in XIOS case 
+          IF (xios_field_is_active("topswad").OR.xios_field_is_active("topswad0").OR. & 
+             xios_field_is_active("solswad").OR.xios_field_is_active("solswad0").OR. & 
+             xios_field_is_active("topswai").OR.xios_field_is_active("solswai").OR.  & 
+               (iflag_rrtm==1.AND.(xios_field_is_active("toplwad").OR.xios_field_is_active("toplwad0").OR. & 
+                                   xios_field_is_active("sollwad").OR.xios_field_is_active("sollwad0"))))  & 
+             !!!--for now these fields are not in the XML files so they are omitted 
+             !!!  xios_field_is_active("toplwai").OR.xios_field_is_active("sollwai") !))) & 
+             swaero_diag=.TRUE. 
+
+          !--setting up swaerofree_diag to TRUE in XIOS case 
+          IF (xios_field_is_active("SWdnSFCcleanclr").OR.xios_field_is_active("SWupSFCcleanclr").OR. &
+             xios_field_is_active("SWupTOAcleanclr").OR.xios_field_is_active("rsucsaf").OR.   &
+             xios_field_is_active("rsdcsaf") .OR. xios_field_is_active("LWdnSFCcleanclr").OR. &
+             xios_field_is_active("LWupTOAcleanclr")) &
+             swaerofree_diag=.TRUE. 
+
+          !--setting up dryaod_diag to TRUE in XIOS case 
+          DO naero = 1, naero_tot-1
+           IF (xios_field_is_active("dryod550_"//name_aero_tau(naero))) dryaod_diag=.TRUE. 
+          ENDDO
+          !
+          !--setting up ok_4xCO2atm to TRUE in XIOS case 
+          IF (xios_field_is_active("rsut4co2").OR.xios_field_is_active("rlut4co2").OR. & 
+             xios_field_is_active("rsutcs4co2").OR.xios_field_is_active("rlutcs4co2").OR. &
+             xios_field_is_active("rsu4co2").OR.xios_field_is_active("rsucs4co2").OR. &
+             xios_field_is_active("rsd4co2").OR.xios_field_is_active("rsdcs4co2").OR. &
+             xios_field_is_active("rlu4co2").OR.xios_field_is_active("rlucs4co2").OR. &
+             xios_field_is_active("rld4co2").OR.xios_field_is_active("rldcs4co2")) &
+             ok_4xCO2atm=.TRUE. 
+        ENDIF
+        !$OMP BARRIER
+        CALL bcast(swaero_diag)
+        CALL bcast(swaerofree_diag)
+        CALL bcast(dryaod_diag)
+        CALL bcast(ok_4xCO2atm)
+!        write (lunout,*)'ok_4xCO2atm= ',swaero_diag, swaerofree_diag, dryaod_diag, ok_4xCO2atm
+      ENDIF !using_xios
     ENDIF
 
@@ -7112,16 +7108,16 @@
        
        ENDIF
-#ifdef CPP_XIOS
-       IF (is_omp_master) CALL xios_context_finalize
+       
+       IF (using_xios) THEN
+         IF (is_omp_master) CALL xios_context_finalize
 
 #ifdef INCA
-       if (type_trac == 'inca') then 
-          IF (is_omp_master .and. grid_type==unstructured) THEN 
-             CALL finalize_inca
-          ENDIF
-       endif
-#endif
-
-#endif
+         if (type_trac == 'inca') then 
+            IF (is_omp_master .and. grid_type==unstructured) THEN 
+               CALL finalize_inca
+            ENDIF
+         endif
+#endif
+       ENDIF !using_xios
        WRITE(lunout,*) ' physiq fin, nombre de steps ou cvpas = 1 : ', Ncvpaseq1
     ENDIF
