Index: LMDZ6/trunk/libf/phylmd/physiq_mod.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/physiq_mod.F90	(revision 4234)
+++ LMDZ6/trunk/libf/phylmd/physiq_mod.F90	(revision 4236)
@@ -78,4 +78,7 @@
     USE VERTICAL_LAYERS_MOD, ONLY: aps,bps, ap, bp
     USE write_field_phy
+#ifdef CPP_XIOS
+    USE wxios, ONLY: g_ctx, wxios_set_context
+#endif
     USE lscp_mod, ONLY : lscp
     USE wake_ini_mod, ONLY : wake_ini
@@ -117,6 +120,7 @@
 
 #ifdef CPP_XIOS
-    USE xios, ONLY: xios_update_calendar, xios_context_finalize, &
-            xios_get_field_attr, xios_field_is_active
+    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
@@ -301,5 +305,4 @@
        zxsnow,snowhgt,qsnow,to_ice,sissnow,runoff,albsol3_lic
        !
-
 
     IMPLICIT NONE
@@ -488,4 +491,8 @@
     REAL dtadd(klon,klev)
 
+!#ifdef CPP_XIOS
+!    TYPE(xios_context), SAVE :: g_ctx
+!#endif
+
 #ifndef CPP_XIOS
     REAL, SAVE :: missing_val=nf90_fill_real
@@ -1216,5 +1223,13 @@
     phys_tstep=NINT(pdtphys)
 #ifdef CPP_XIOS
-    IF (.NOT. debut .AND. is_omp_master) CALL xios_update_calendar(itap+1)
+! switch to XIOS LMDZ physics context 
+!!!!$OMP MASTER
+!!!!    WRITE(*,*)'PHYSICS XIOS Context :', g_ctx
+!!!!    CALL wxios_set_context()
+!!!!$OMP END MASTER
+    IF (.NOT. debut .AND. is_omp_master) THEN
+       CALL wxios_set_context()
+       CALL xios_update_calendar(itap+1)
+    ENDIF
 #endif
 
@@ -2205,4 +2220,12 @@
       ENDIF
     ENDIF
+! switch to XIOS LMDZ physics context just in case
+!$OMP MASTER
+!!!!#ifdef CPP_XIOS
+!!!!    WRITE(*,*)'PHYSICS XIOS Context :', g_ctx
+!!!!    CALL xios_set_current_context(g_ctx)
+!!!!#endif
+!$OMP END MASTER
+
     !
     !
