Index: trunk/LMDZ.MARS/README
===================================================================
--- trunk/LMDZ.MARS/README	(revision 2646)
+++ trunk/LMDZ.MARS/README	(revision 2651)
@@ -3676,2 +3676,6 @@
 dedicated flag to avoid calls to mod() with a zero argument which causes
 recent gfortran (9+) to complain about a division by zero when in debug mode.
+
+== 28/03/2022 == JL+EM
+- turn sugwd.F to sugwd.F90 with extra comments
+- turn yoegwd.h into a module
Index: trunk/LMDZ.MARS/libf/phymars/gwprofil_mod.F90
===================================================================
--- trunk/LMDZ.MARS/libf/phymars/gwprofil_mod.F90	(revision 2646)
+++ trunk/LMDZ.MARS/libf/phymars/gwprofil_mod.F90	(revision 2651)
@@ -29,6 +29,7 @@
 	
       use dimradmars_mod, only: ndomainsz  
+      use yoegwd_h, only: gkdrag, grcrit, gssec, gtsec
+      
       implicit none
-#include "yoegwd.h"   ! why begin with #, needs ask Ehouarn Millour
   
       ! 0. DECLARATIONS:
Index: trunk/LMDZ.MARS/libf/phymars/gwstress_mod.F90
===================================================================
--- trunk/LMDZ.MARS/libf/phymars/gwstress_mod.F90	(revision 2646)
+++ trunk/LMDZ.MARS/libf/phymars/gwstress_mod.F90	(revision 2651)
@@ -25,6 +25,7 @@
 
       use dimradmars_mod, only: ndomainsz   
+      use yoegwd_h, only: gkdrag, gtsec, gvcrit
+
       implicit none
-      include "yoegwd.h"
       
       ! 0. DECLARATIONS:
Index: trunk/LMDZ.MARS/libf/phymars/nonoro_gwd_ran_mod.F90
===================================================================
--- trunk/LMDZ.MARS/libf/phymars/nonoro_gwd_ran_mod.F90	(revision 2646)
+++ trunk/LMDZ.MARS/libf/phymars/nonoro_gwd_ran_mod.F90	(revision 2651)
@@ -50,6 +50,6 @@
      use xios_output_mod, only: send_xios_field
 #endif      
+      
       implicit none
-      include "yoegwd.h" 
       include "callkeys.h"
 
Index: trunk/LMDZ.MARS/libf/phymars/orodrag_mod.F90
===================================================================
--- trunk/LMDZ.MARS/libf/phymars/orodrag_mod.F90	(revision 2646)
+++ trunk/LMDZ.MARS/libf/phymars/orodrag_mod.F90	(revision 2651)
@@ -38,7 +38,7 @@
       USE gwprofil_mod, ONLY: gwprofil
       USE comcstfi_h, ONLY: g, cpp
+      USE yoegwd_h, ONLY: gkwake
       
       implicit none
-      include "yoegwd.h"
       
       ! 0. DECLARATIONS:
Index: trunk/LMDZ.MARS/libf/phymars/orosetup.F90
===================================================================
--- trunk/LMDZ.MARS/libf/phymars/orosetup.F90	(revision 2646)
+++ trunk/LMDZ.MARS/libf/phymars/orosetup.F90	(revision 2651)
@@ -21,7 +21,9 @@
       !-----------------------------------------------------------------------
       use dimradmars_mod, only: ndomainsz
-      USE comcstfi_h
+      use comcstfi_h, only: cpp, g, r, pi
+      use yoegwd_h, only: gfrcrit, grcrit, gsigcr, gssec, gtsec, gvsec
+      use yoegwd_h, only: nktopg
+      
       implicit none
-      include "yoegwd.h"
       
       ! 0. DECLARATIONS:
Index: trunk/LMDZ.MARS/libf/phymars/sugwd.F
===================================================================
--- trunk/LMDZ.MARS/libf/phymars/sugwd.F	(revision 2646)
+++ 	(revision )
@@ -1,109 +1,0 @@
-      SUBROUTINE SUGWD(NLEV,PSIG)
-C     
-C**** *SUGWD* INITIALIZE COMMON YOEGWD CONTROLLING GRAVITY WAVE DRAG
-C     
-C     PURPOSE.
-C     --------
-C     INITIALIZE YOEGWD, THE COMMON THAT CONTROLS THE
-C     GRAVITY WAVE DRAG PARAMETRIZATION.
-C     
-C     EXPLICIT ARGUMENTS :
-C     --------------------
-C     
-C     INPUT :
-C     
-C     PSIG        : VERTICAL COORDINATE TABLE
-C     NLEV        : NUMBER OF MODEL LEVELS
-C     
-C     OUTPUT :
-C     
-C     NONE
-C     
-C     IMPLICIT ARGUMENTS :
-C     --------------------
-C     COMMON YOEGWD
-C     
-C     METHOD.
-C     -------
-C     SEE DOCUMENTATION
-C     
-C     EXTERNALS.
-C     ----------
-C     NONE
-C     
-C     REFERENCE.
-C     ----------
-C     ECMWF Research Department documentation of the IFS
-C     
-C     AUTHOR.
-C     -------
-C     MARTIN MILLER             *ECMWF*
-C     
-C     MODIFICATIONS.
-C     --------------
-C     ORIGINAL : 90-01-01
-C     ------------------------------------------------------------------
-      implicit none
-C     
-C     -----------------------------------------------------------------
-c     !-*-      include 'yoegwd.h'
-#include "yoegwd.h"
-c     !-*-
-C     ----------------------------------------------------------------
-C     
-      integer nlev
-      REAL PSIG(NLEV+1)
-
-      real zsigt,zpr,zpm1r
-      integer jk
-C     
-C     *       1.    SET THE VALUES OF THE PARAMETERS
-C     --------------------------------
-C     
- 100  CONTINUE
-C     
-c     PRINT *,' Dans sugwd nlev=',NLEV,' SIG=',PSIG
-      GHMAX=10000.
-C     
-c     old  ZSIGT=0.94
-c     old  ZPR=80000.
-      ZSIGT=0.85
-      ZPR=100000.
-C     
-      DO 110 JK=1,NLEV-1
-         ZPM1R=0.5*ZPR*(PSIG(JK)+PSIG(JK+1))
-         IF((ZPM1R/ZPR).GE.ZSIGT)THEN
-            NKTOPG=JK
-         ENDIF
- 110  CONTINUE
-      WRITE(*,*) 'In sugwd NKTOPG=',NKTOPG
-C     
-      GSIGCR=0.80
-C     
-      GKDRAG= 0.1  ! used to be 0.1 for mcd Version 1 and 2 (before 10/2000)
-      GRCRIT=0.25
-      GFRCRIT=1.0
-      GKWAKE=1.0
-
-C     
-      GKDRAGL=4.*GKDRAG
-      GRAHILO=1.
-      GVCRIT =0.0
-C     
-C     
-C     ----------------------------------------------------------------
-C     
-C     *       2.    SET VALUES OF SECURITY PARAMETERS
-C     ---------------------------------
-C     
- 200  CONTINUE
-C     
-      GVSEC=0.10
-      GSSEC=1.E-12
-C     
-      GTSEC=1.E-07
-C     
-C     ----------------------------------------------------------------
-C     
-      RETURN
-      END
Index: trunk/LMDZ.MARS/libf/phymars/sugwd.F90
===================================================================
--- trunk/LMDZ.MARS/libf/phymars/sugwd.F90	(revision 2651)
+++ trunk/LMDZ.MARS/libf/phymars/sugwd.F90	(revision 2651)
@@ -0,0 +1,73 @@
+      SUBROUTINE SUGWD(nlayer,sigtest)
+! ==============================================================================    
+!     Initialize common variables in yoegwd.h to control the orographic 
+!     graivty wave drag parameterization. That means, all the tunable parameters 
+!     for oro-GW scheme are in this subroutine.
+!     MARTIN MILLER             *ECMWF*               ORIGINAL : 90-01-01  
+!     Update:    Jiandong Liu     2022/03/15          Rewirite into .F90 and
+!                                                     comment.   
+!     REFERENCE.
+!     ----------
+!     ECMWF Research Department documentation of the IFS
+!===============================================================================
+
+      USE yoegwd_h, ONLY: GFRCRIT, GRCRIT, GVCRIT
+      USE yoegwd_h, ONLY: GKDRAG, GKDRAGL, GHMAX
+      USE yoegwd_h, ONLY: GRAHILO, GSIGCR, GSSEC
+      USE yoegwd_h, ONLY: GTSEC, GVSEC, GKWAKE
+      USE yoegwd_h, ONLY: NKTOPG
+
+      implicit none
+
+      ! 0.1 Inputs:         
+      integer,intent(in):: nlayer                ! Number of model levels
+      REAL,intent(in):: sigtest(nlayer+1)        ! Vertical coordinate table
+
+      ! 0.2 Outputs:
+      ! None.
+
+      ! 0.3 Local variables
+      real zsigt                ! Top of the sigma coordinates?
+      real zpr                  ! Reference pressure ?
+      real zpm1r                ! Pressure at full layer ?
+      integer jk
+
+!-------------------------------------------------------------------------------     
+! 1.   Set the values of the parameters 
+!-------------------------------------------------------------------------------   
+!     PRINT *,' Dans sugwd nlayer=',nlayer,' SIG=',sigtest
+      GHMAX=10000.
+   
+!     old  ZSIGT=0.94
+!     old  ZPR=80000.
+      ZSIGT=0.85      ! Sigmal levels
+      ZPR=100000.     ! Surface (Reference) Pressure?
+      
+      ! ! Condition to find NKTOPG layer, which NKTOPG is a condition to set
+      ! 1*pvar and 2*pvar layers (OROSETUP)
+      DO JK=1,nlayer-1
+         ZPM1R=0.5*ZPR*(sigtest(JK)+sigtest(JK+1))
+         IF((ZPM1R/ZPR).GE.ZSIGT)THEN
+            NKTOPG=JK   
+         ENDIF
+      ENDDO
+      WRITE(*,*) 'In sugwd NKTOPG=',NKTOPG
+    
+      GSIGCR=0.80  ! Sigmal levels to found the top of low level flow height (OROSETUP)  
+      GKDRAG= 0.1  ! used to be 0.1 for mcd Version 1 and 2 (before 10/2000) (OROSETUP)
+                      
+      GFRCRIT=1.0
+      GKWAKE=1.0   ! The G in equation (16)
+      GRCRIT=0.25  ! Critical value for Mean flow richardson number(OROSETUP)      
+      GKDRAGL=4.*GKDRAG
+      GRAHILO=1.
+      GVCRIT =0.0    
+!-------------------------------------------------------------------------------  
+! 2.    Set values of security parameters 
+!-------------------------------------------------------------------------------  
+      GVSEC=0.10      ! Security values for For normal wind (pu^2+pv^2)^0.5(OROSETUP,GWSTRESS)
+      GSSEC=1.E-12    ! Security values for Brunt–Väisälä frequency N^2 (OROSETUP)   
+      GTSEC=1.E-07    ! Security values for Sub-grid scale anisotropy(OROSETUP,GWSTRESS)
+
+      RETURN
+      END
Index: trunk/LMDZ.MARS/libf/phymars/yoegwd.h
===================================================================
--- trunk/LMDZ.MARS/libf/phymars/yoegwd.h	(revision 2646)
+++ 	(revision )
@@ -1,13 +1,0 @@
-!     -----------------------------------------------------------------
-!*    *COMMON* *YOEGWD* - PARAMETERS FOR GRAVITY WAVE DRAG CALCULATIONS
-!     -----------------------------------------------------------------
-!
-      real    ::  GFRCRIT,GRCRIT,GVCRIT,GKDRAG,GKDRAGL,GHMAX
-      real    ::   GRAHILO,GSIGCR,GSSEC, GTSEC,  GVSEC, GKWAKE
-      integer ::  NKTOPG
-      COMMON/YOEGWD/ GFRCRIT,GRCRIT,GVCRIT,GKDRAG,GKDRAGL,GHMAX         &
-     &             ,GRAHILO,GSIGCR,NKTOPG,GSSEC, GTSEC, GVSEC,GKWAKE
-!$OMP THREADPRIVATE(/YOEGWD/)
-
-
-
Index: trunk/LMDZ.MARS/libf/phymars/yoegwd_h.F90
===================================================================
--- trunk/LMDZ.MARS/libf/phymars/yoegwd_h.F90	(revision 2651)
+++ trunk/LMDZ.MARS/libf/phymars/yoegwd_h.F90	(revision 2651)
@@ -0,0 +1,27 @@
+module yoegwd_h
+!     -----------------------------------------------------------------
+!*    *COMMON* *YOEGWD* - PARAMETERS FOR GRAVITY WAVE DRAG CALCULATIONS
+!     -----------------------------------------------------------------
+implicit none
+
+  real,save :: GFRCRIT
+  real,save :: GRCRIT
+  real,save :: GVCRIT
+!$OMP THREADPRIVATE(GFRCRIT,GRCRIT,GVCRIT)
+  real,save :: GKDRAG
+  real,save :: GKDRAGL
+  real,save :: GHMAX
+!$OMP THREADPRIVATE(GKDRAG,GKDRAGL,GHMAX)
+  real,save :: GRAHILO
+  real,save :: GSIGCR
+  real,save :: GSSEC
+!$OMP THREADPRIVATE(GRAHILO,GSIGCR,GSSEC)
+  real,save :: GTSEC
+  real,save :: GVSEC
+  real,save :: GKWAKE
+!$OMP THREADPRIVATE(GTSEC,GVSEC,GKWAKE)
+  integer ::  NKTOPG
+!$OMP THREADPRIVATE(NKTOPG)
+
+end module yoegwd_h
+
