Index: LMDZ6/trunk/libf/phylmdiso/limit_read_mod.F90
===================================================================
--- LMDZ6/trunk/libf/phylmdiso/limit_read_mod.F90	(revision 4613)
+++ 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 4613)
+++ 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 4613)
+++ 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 4613)
+++ 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 4613)
+++ 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 4613)
+++ 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
