Index: LMDZ6/trunk/libf/phylmd/clesphys.h
===================================================================
--- LMDZ6/trunk/libf/phylmd/clesphys.h	(revision 4536)
+++ LMDZ6/trunk/libf/phylmd/clesphys.h	(revision 4537)
@@ -18,4 +18,5 @@
        REAL co2_ppm, co2_ppm0, solaire
        INTEGER iflag_thermals,nsplit_thermals
+       INTEGER iflag_physiq
        REAL tau_thermals
 
@@ -152,5 +153,6 @@
      &     , ok_daily_climoz, ok_all_xml, ok_lwoff                      &
      &     , iflag_phytrac, ok_new_lscp, ok_bs, ok_rad_bs               &
-     &     ,  iflag_thermals,nsplit_thermals, tau_thermals    
+     &     ,  iflag_thermals,nsplit_thermals, tau_thermals              &
+     &     , iflag_physiq
        save /clesphys/
 !$OMP THREADPRIVATE(/clesphys/)
Index: LMDZ6/trunk/libf/phylmd/conf_phys_m.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/conf_phys_m.F90	(revision 4536)
+++ LMDZ6/trunk/libf/phylmd/conf_phys_m.F90	(revision 4537)
@@ -189,5 +189,5 @@
     REAL, SAVE ::  fmagic_omp, pmagic_omp
     INTEGER,SAVE :: iflag_pbl_omp,lev_histhf_omp,lev_histday_omp,lev_histmth_omp
-    INTEGER,SAVE :: iflag_pbl_split_omp
+    INTEGER,SAVE :: iflag_pbl_split_omp,iflag_physiq_omp
 !FC
     INTEGER,SAVE :: ifl_pbltree_omp
@@ -1484,4 +1484,7 @@
     CALL getin('iflag_pbl',iflag_pbl_omp)
 
+    iflag_physiq_omp = 1 ! 1: std, 0 for physiqex
+    CALL getin('iflag_physiq',iflag_physiq_omp)
+
 !FC
     !Config Key  = ifl_pbltree
@@ -1533,10 +1536,9 @@
     nsplit_thermals_omp = 1
     CALL getin('nsplit_thermals',nsplit_thermals_omp)
-
-    !Config Key  = alp_bl_k
-    !Config Desc =
-    !Config Def  = 0.
-    !Config Help =
-    !
+    !
+    !Config Key  = nsplit_thermals
+    !Config Desc =
+    !Config Def  = 0
+    !Config Help =
     alp_bl_k_omp = 1.
     CALL getin('alp_bl_k',alp_bl_k_omp)
@@ -2321,4 +2323,5 @@
     pmagic = pmagic_omp
     iflag_pbl = iflag_pbl_omp
+    iflag_physiq = iflag_physiq_omp
     iflag_pbl_split = iflag_pbl_split_omp
 !FC
@@ -2756,4 +2759,5 @@
     WRITE(lunout,*) ' freq_calNMC = ',freq_calNMC
     WRITE(lunout,*) ' iflag_pbl = ', iflag_pbl
+    WRITE(lunout,*) ' iflag_physiq = ', iflag_physiq
 !FC
     WRITE(lunout,*) ' ifl_pbltree = ', ifl_pbltree
Index: LMDZ6/trunk/libf/phylmd/dyn1d/old_lmdz1d.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/dyn1d/old_lmdz1d.F90	(revision 4536)
+++ LMDZ6/trunk/libf/phylmd/dyn1d/old_lmdz1d.F90	(revision 4537)
@@ -946,4 +946,7 @@
 !------------------------------------------------------------------------
 !Al1 =============== restart option ==========================
+        iflag_physiq=1
+        call getin('iflag_physiq',iflag_physiq)
+
         if (.not.restart) then
           iflag_pbl = 5
Index: LMDZ6/trunk/libf/phylmd/dyn1d/scm.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/dyn1d/scm.F90	(revision 4536)
+++ LMDZ6/trunk/libf/phylmd/dyn1d/scm.F90	(revision 4537)
@@ -704,4 +704,7 @@
 !------------------------------------------------------------------------
 !Al1 =============== restart option ======================================
+        iflag_physiq=1
+        call getin('iflag_physiq',iflag_physiq)
+
         if (.not.restart) then
           iflag_pbl = 5
Index: LMDZ6/trunk/libf/phylmd/phyetat0_mod.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/phyetat0_mod.F90	(revision 4536)
+++ LMDZ6/trunk/libf/phylmd/phyetat0_mod.F90	(revision 4537)
@@ -300,4 +300,9 @@
 
 !===================================================================
+! Lecture dans le cas iflag_pbl_surface =1
+!===================================================================
+
+   if ( iflag_physiq == 1 ) then
+!===================================================================
   ! Lecture des temperatures du sol profond:
 !===================================================================
@@ -373,4 +378,6 @@
     treedrg(:,:,:) = 0.0 
   ENDIF
+
+  endif ! iflag_physiq == 1
 
   ! Lecture de l'age de la neige:
@@ -591,5 +598,7 @@
   ! Initialize module pbl_surface_mod 
 
+  if ( iflag_physiq == 1 ) then
   CALL pbl_surface_init(fder, snow, qsurf, tsoil)
+  endif
 
   ! Initialize module ocean_cpl_mod for the case of coupled ocean
Index: LMDZ6/trunk/libf/phylmd/phyredem.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/phyredem.F90	(revision 4536)
+++ LMDZ6/trunk/libf/phylmd/phyredem.F90	(revision 4537)
@@ -76,5 +76,7 @@
   ! Get variables which will be written to restart file from module 
   ! pbl_surface_mod
-  CALL pbl_surface_final(fder, snow, qsurf,  tsoil)
+  if ( iflag_physiq == 1 ) then
+     CALL pbl_surface_final(fder, snow, qsurf,  tsoil)
+  endif
 
   ! Get a variable calculated in module fonte_neige_mod
Index: LMDZ6/trunk/libf/phylmd/physiq_mod.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/physiq_mod.F90	(revision 4536)
+++ LMDZ6/trunk/libf/phylmd/physiq_mod.F90	(revision 4537)
@@ -142,4 +142,5 @@
 !!!!!!!!!!!!!!!!!!  END "USE" for CPP keys !!!!!!!!!!!!!!!!!!!!!!
 
+USE physiqex_mod, ONLY : physiqex
 USE phys_local_var_mod, ONLY: phys_local_var_init, phys_local_var_end, &
        ! [Variables internes non sauvegardees de la physique]
@@ -1229,4 +1230,26 @@
     REAL pi
 
+
+    !======================================================================!
+    ! Bifurcation vers un nouveau moniteur physique pour experimenter      !
+    ! des solutions et préparer le couplage avec la physique de MesoNH     !
+    ! 14 mai 2023                                                          !
+    !======================================================================!
+    if (debut) then                                                        !
+       iflag_physiq=1                                                      !
+       call getin_p('iflag_physiq', iflag_physiq)                          !
+    endif                                                                  !
+    if ( iflag_physiq == 2 ) then                                          !
+       call physiqex (nlon,nlev, &                                         !
+       debut,lafin,pdtphys_, &                                             !
+       paprs,pplay,pphi,pphis,presnivs, &                                  !
+       u,v,rot,t,qx, &                                                     !
+       flxmass_w, &                                                        !
+       d_u, d_v, d_t, d_qx, d_ps)                                          !
+       return                                                              !
+    endif                                                                  !
+    !======================================================================!
+
+
     pi = 4. * ATAN(1.)
 
@@ -1255,5 +1278,5 @@
     ! Utilise notamment en 1D mais peut etre active egalement en 3D
     ! en imposant la valeur de igout.
-    !======================================================================d
+    !======================================================================
     IF (prt_level.ge.1) THEN
        igout=klon/2+1/klon
Index: LMDZ6/trunk/libf/phylmd/physiqex_mod.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/physiqex_mod.F90	(revision 4537)
+++ LMDZ6/trunk/libf/phylmd/physiqex_mod.F90	(revision 4537)
@@ -0,0 +1,244 @@
+! $Id: physiq.F 1565 2011-08-31 12:53:29Z jghattas $
+MODULE physiqex_mod
+
+IMPLICIT NONE
+
+CONTAINS
+
+      SUBROUTINE physiqex (nlon,nlev, &
+     &            debut,lafin,pdtphys, &
+     &            paprs,pplay,pphi,pphis,presnivs, &
+     &            u,v,rot,t,qx, &
+     &            flxmass_w, &
+     &            d_u, d_v, d_t, d_qx, d_ps)
+
+      USE dimphy, only : klon,klev
+      USE infotrac_phy, only : nqtot
+      USE geometry_mod, only : latitude
+!      USE comcstphy, only : rg
+      USE iophy, only : histbeg_phy,histwrite_phy
+      USE ioipsl, only : getin,histvert,histdef,histend,ymds2ju
+      USE mod_phys_lmdz_para, only : jj_nb
+      USE phys_state_var_mod, only : phys_state_var_init
+      USE mod_grid_phy_lmdz, ONLY: nbp_lon,nbp_lat
+      USE phyetat0_mod, only: phyetat0
+      USE iophy, ONLY : init_iophy_new
+      USE geometry_mod, ONLY: cell_area, latitude_deg, longitude_deg
+
+
+#ifdef CPP_XIOS
+      USE xios, ONLY: xios_update_calendar
+      USE wxios, only: wxios_add_vaxis, wxios_set_cal, wxios_closedef
+      USE iophy, ONLY: histwrite_phy
+#endif
+
+      IMPLICIT none
+!
+! Routine argument:
+!
+
+      integer,intent(in) :: nlon ! number of atmospheric colums
+      integer,intent(in) :: nlev ! number of vertical levels (should be =klev)
+      logical,intent(in) :: debut ! signals first call to physics
+      logical,intent(in) :: lafin ! signals last call to physics
+      real,intent(in) :: pdtphys ! physics time step (s)
+      real,intent(in) :: paprs(klon,klev+1) ! interlayer pressure (Pa)
+      real,intent(in) :: pplay(klon,klev) ! mid-layer pressure (Pa)
+      real,intent(in) :: pphi(klon,klev) ! geopotential at mid-layer
+      real,intent(in) :: pphis(klon) ! surface geopotential
+      real,intent(in) :: presnivs(klev) ! pseudo-pressure (Pa) of mid-layers
+      real,intent(in) :: u(klon,klev) ! eastward zonal wind (m/s)
+      real,intent(in) :: v(klon,klev) ! northward meridional wind (m/s)
+      real,intent(in) :: rot(klon,klev) ! northward meridional wind (m/s)
+      real,intent(in) :: t(klon,klev) ! temperature (K)
+      real,intent(in) :: qx(klon,klev,nqtot) ! tracers (.../kg_air)
+      real,intent(in) :: flxmass_w(klon,klev) ! vertical mass flux
+      real,intent(out) :: d_u(klon,klev) ! physics tendency on u (m/s/s)
+      real,intent(out) :: d_v(klon,klev) ! physics tendency on v (m/s/s)
+      real,intent(out) :: d_t(klon,klev) ! physics tendency on t (K/s)
+      real,intent(out) :: d_qx(klon,klev,nqtot) ! physics tendency on tracers
+      real,intent(out) :: d_ps(klon) ! physics tendency on surface pressure
+
+!    include "clesphys.h"
+    INTEGER        length
+    PARAMETER    ( length = 100 )
+    REAL tabcntr0( length       )
+    INTEGER, PARAMETER :: longcles=20
+    REAL, SAVE :: clesphy0(longcles)
+    !$OMP THREADPRIVATE(clesphy0)
+
+
+integer,save :: itau=0 ! counter to count number of calls to physics
+!$OMP THREADPRIVATE(itau)
+real :: temp_newton(klon,klev)
+integer :: k
+logical, save :: first=.true.
+!$OMP THREADPRIVATE(first)
+
+real,save :: rg=9.81
+!$OMP THREADPRIVATE(rg)
+
+! For I/Os
+integer :: itau0
+real :: zjulian
+real :: dtime
+integer :: nhori ! horizontal coordinate ID
+integer,save :: nid_hist ! output file ID
+!$OMP THREADPRIVATE(nid_hist)
+integer :: zvertid ! vertical coordinate ID
+integer,save :: iwrite_phys ! output every iwrite_phys physics step
+!$OMP THREADPRIVATE(iwrite_phys)
+integer,save :: iwrite_phys_omp ! intermediate variable to read iwrite_phys
+                                ! (must be shared by all threads)
+real :: t_ops ! frequency of the IOIPSL operations (eg average over...)
+real :: t_wrt ! frequency of the IOIPSL outputs
+
+
+
+!------------------------------------------------------------
+! Initialisations de la physique au premier pas de temps
+!------------------------------------------------------------
+
+print*,'Debut physiqex',debut
+! initializations
+if (debut) then ! Things to do only for the first call to physics 
+print*,'Debut physiqex IN'
+
+! load initial conditions for physics (including the grid)
+  call phys_state_var_init(1) ! some initializations, required before calling phyetat0
+  call phyetat0("startphy.nc", clesphy0, tabcntr0)
+  CALL init_iophy_new(latitude_deg,longitude_deg)
+
+! Initialize outputs:
+  itau0=0
+!$OMP MASTER
+  iwrite_phys_omp=1 !default: output every physics timestep
+  ! NB: getin() is not threadsafe; only one thread should call it.
+  call getin("iwrite_phys",iwrite_phys_omp)
+!$OMP END MASTER
+!$OMP BARRIER
+  iwrite_phys=iwrite_phys_omp
+  t_ops=pdtphys*iwrite_phys ! frequency of the IOIPSL operation
+  t_wrt=pdtphys*iwrite_phys ! frequency of the outputs in the file
+  ! compute zjulian for annee0=1979 and month=1 dayref=1 and hour=0.0
+  !CALL ymds2ju(annee0, month, dayref, hour, zjulian)
+  call ymds2ju(1979, 1, 1, 0.0, zjulian)
+  dtime=pdtphys
+
+#ifndef CPP_IOIPSL_NO_OUTPUT
+  ! Initialize IOIPSL output file
+  call histbeg_phy("histins.nc",itau0,zjulian,dtime,nhori,nid_hist)
+#endif
+
+endif ! of if (debut)
+
+!------------------------------------------------------------
+! Initialisations a chaque pas de temps
+!------------------------------------------------------------
+
+! increment local time counter itau
+itau=itau+1
+
+! set all tendencies to zero
+d_u(1:klon,1:klev)=0.
+d_v(1:klon,1:klev)=0.
+d_t(1:klon,1:klev)=0.
+d_qx(1:klon,1:klev,1:nqtot)=0.
+d_ps(1:klon)=0.
+
+!------------------------------------------------------------
+! Calculs
+!------------------------------------------------------------
+
+! compute tendencies to return to the dynamics:
+! "friction" on the first layer
+d_u(1:klon,1)=-u(1:klon,1)/86400.
+d_v(1:klon,1)=-v(1:klon,1)/86400.
+! newtonian relaxation towards temp_newton()
+do k=1,klev
+  temp_newton(1:klon,k)=280.+cos(latitude(1:klon))*40.-pphi(1:klon,k)/rg*6.e-3
+  d_t(1:klon,k)=(temp_newton(1:klon,k)-t(1:klon,k))/1.e5
+enddo
+
+
+!------------------------------------------------------------
+! Entrees sorties
+!------------------------------------------------------------
+
+print*,'PHYDEV: itau=',itau
+
+
+if(debut)then
+!$OMP MASTER
+#ifndef CPP_IOIPSL_NO_OUTPUT 
+! IOIPSL
+  ! define vertical coordinate
+  call histvert(nid_hist,"presnivs","Vertical levels","Pa",klev, &
+                presnivs,zvertid,'down')
+  ! define variables which will be written in "histins.nc" file
+  call histdef(nid_hist,'temperature','Atmospheric temperature','K', &
+               nbp_lon,jj_nb,nhori,klev,1,klev,zvertid,32, &
+               'inst(X)',t_ops,t_wrt)
+  call histdef(nid_hist,'u','Eastward Zonal Wind','m/s', &
+               nbp_lon,jj_nb,nhori,klev,1,klev,zvertid,32, &
+               'inst(X)',t_ops,t_wrt)
+  call histdef(nid_hist,'v','Northward Meridional Wind','m/s', &
+               nbp_lon,jj_nb,nhori,klev,1,klev,zvertid,32, &
+               'inst(X)',t_ops,t_wrt)
+  call histdef(nid_hist,'ps','Surface Pressure','Pa', &
+               nbp_lon,jj_nb,nhori,1,1,1,zvertid,32, &
+               'inst(X)',t_ops,t_wrt)
+  ! end definition sequence
+  call histend(nid_hist)
+#endif
+
+#ifdef CPP_XIOS
+!XIOS
+    ! 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)
+    
+    !Finalize the context:
+    CALL wxios_closedef()
+#endif
+!$OMP END MASTER
+!$OMP BARRIER
+endif
+! write some outputs:
+! IOIPSL
+#ifndef CPP_IOIPSL_NO_OUTPUT 
+if (modulo(itau,iwrite_phys)==0) then
+  call histwrite_phy(nid_hist,.false.,"temperature",itau,t)
+  call histwrite_phy(nid_hist,.false.,"u",itau,u)
+  call histwrite_phy(nid_hist,.false.,"v",itau,v)
+  call histwrite_phy(nid_hist,.false.,"ps",itau,paprs(:,1))
+endif
+#endif
+
+!XIOS
+#ifdef CPP_XIOS
+!$OMP MASTER
+    !Increment XIOS time
+    CALL xios_update_calendar(itau)
+!$OMP END MASTER
+!$OMP BARRIER
+
+    !Send fields to XIOS: (NB these fields must also be defined as
+    ! <field id="..." /> in iodef.xml to be correctly used
+    CALL histwrite_phy("temperature",t)
+    CALL histwrite_phy("temp_newton",temp_newton)
+    CALL histwrite_phy("u",u)
+    CALL histwrite_phy("v",v)
+    CALL histwrite_phy("ps",paprs(:,1))
+#endif
+
+! if lastcall, then it is time to write "restartphy.nc" file
+if (lafin) then
+  call phyredem("restartphy.nc")
+endif
+
+end subroutine physiqex
+
+END MODULE physiqex_mod
