/[lmdze]/trunk/phylmd/Interface_surf/hbtm.f90
ViewVC logotype

Diff of /trunk/phylmd/Interface_surf/hbtm.f90

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/libf/phylmd/hbtm.f revision 3 by guez, Wed Feb 27 13:16:39 2008 UTC trunk/phylmd/Interface_surf/hbtm.f90 revision 346 by guez, Mon Dec 9 20:15:29 2019 UTC
# Line 1  Line 1 
1        SUBROUTINE HBTM(knon, paprs, pplay,  module HBTM_m
2       .                t2m,t10m,q2m,q10m,ustar,  
3       .                flux_t,flux_q,u,v,t,q,    IMPLICIT none
4       .                pblh,cape,EauLiq,ctei,pblT,  
5       .                therm,trmb1,trmb2,trmb3,plcl)  contains
6        use dimens_m  
7        use dimphy    SUBROUTINE HBTM(paprs, pplay, t2m, q2m, ustar, flux_t, flux_q, u, v, t, q, &
8        use YOMCST         pblh, cape, EauLiq, ctei, pblT, therm, plcl)
9        use yoethf  
10        use fcttre      ! D'apr\'es Holstag et Boville et Troen et Mahrt
11          IMPLICIT none      ! JAS 47 BLM
12    
13  c***************************************************************      ! Algorithme th\'ese Anne Mathieu. Crit\'ere d'entra\^inement
14  c*                                                             *      ! Peter Duynkerke (JAS 50).  Written by: Anne MATHIEU and Alain
15  c* HBTM2   D'apres Holstag&Boville et Troen&Mahrt              *      ! LAHELLEC, 22nd November 1999.
16  c*                 JAS 47              BLM                     *  
17  c* Algorithme These Anne Mathieu                               *      ! Modifications : d\'ecembre 99 passage th \`a niveau plus bas. Voir fixer
18  c* Critere d'Entrainement Peter Duynkerke (JAS 50)             *      ! la prise du th \`a z/Lambda = -.2 (max Ray)
19  c* written by  : Anne MATHIEU & Alain LAHELLEC, 22/11/99       *      ! Autre algorithme : entra\^inement ~ Theta + v =constante
20  c* features : implem. exces Mathieu                            *      !  mais comment ? The ?
21  c***************************************************************      ! On peut fixer q \`a 0.7 qsat (cf. non adiabatique) d'où T2 et The2.
22  c* mods : decembre 99 passage th a niveau plus bas. voir fixer *      ! Voir aussi KE pblh = niveau The_e ou l = env.
23  c* la prise du th a z/Lambda = -.2 (max Ray)                   *  
24  c* Autre algo : entrainement ~ Theta+v =cste mais comment=>The?*      ! Adaptation \`a LMDZ version coupl\'ee. Pour le moment on fait
25  c* on peut fixer q a .7qsat(cf non adiab)=>T2 et The2          *      ! passer en argument les grandeurs de surface : flux, t, q2m. On
26  c* voir aussi //KE pblh = niveau The_e ou l = env.             *      ! va utiliser syst\'ematiquement les grandeurs \`a 2 m mais on
27  c***************************************************************      ! garde la possibilit\'e de changer si besoin (jusqu'\`a pr\'esent
28  c* fin therm a la HBTM passage a forme Mathieu 12/09/2001      *      ! la forme de HB avec le premier niveau mod\`ele \'etait
29  c***************************************************************      ! conserv\'ee).
30  c*  
31  c      USE dimphy, ONLY: klev, klon
32  c      USE suphec_m, ONLY: rcpd, rd, retv, rg, rkappa, rtt
33  cAM Fev 2003      USE yoethf_m, ONLY: r2es, rvtmp2
34  c Adaptation a LMDZ version couplee      USE fcttre, ONLY: foeew
35  c  
36  c Pour le moment on fait passer en argument les grdeurs de surface :      ! Arguments:
37  c flux, t,q2m, t,q10m, on va utiliser systematiquement les grdeurs a 2m ms  
38  c on garde la possibilite de changer si besoin est (jusqu'a present la      ! pression a inter-couche (Pa)
39  c forme de HB avec le 1er niveau modele etait conservee)      REAL, intent(in):: paprs(klon, klev+1)
40  c      ! pression au milieu de couche (Pa)
41  c      REAL, intent(in):: pplay(klon, klev)
42  c      REAL, intent(in):: t2m(klon) ! temperature a 2 m
43  c      ! q a 2 et 10m
44  c      REAL, intent(in):: q2m(klon)
45        REAL RLvCp, REPS      REAL, intent(in):: ustar(:) ! (knon)
46  c Arguments:      REAL, intent(in):: flux_t(:), flux_q(:) ! (knon) flux à la surface
47  c      REAL, intent(in):: u(:, :) ! (knon, klev) vitesse U (m/s)
48        INTEGER knon ! nombre de points a calculer      REAL, intent(in):: v(:, :) ! (knon, klev) vitesse V (m/s)
49  cAM      REAL, intent(in):: t(:, :) ! (knon, klev) temperature (K)
50        REAL t2m(klon), t10m(klon) ! temperature a 2 et 10m      REAL, intent(in):: q(:, :) ! (knon, klev) vapeur d'eau (kg/kg)
51        REAL q2m(klon), q10m(klon) ! q a 2 et 10m  
52        REAL ustar(klon)      REAL, intent(out):: pblh(:) ! (knon)
53        REAL paprs(klon,klev+1) ! pression a inter-couche (Pa)      ! Cape du thermique
54        REAL pplay(klon,klev)   ! pression au milieu de couche (Pa)      REAL Cape(klon)
55        REAL flux_t(klon,klev), flux_q(klon,klev)     ! Flux      ! Eau liqu integr du thermique
56        REAL u(klon,klev) ! vitesse U (m/s)      REAL EauLiq(klon)
57        REAL v(klon,klev) ! vitesse V (m/s)      ! Critere d'instab d'entrainmt des nuages de
58        REAL t(klon,klev) ! temperature (K)      REAL ctei(klon)
59        REAL q(klon,klev) ! vapeur d'eau (kg/kg)      REAL pblT(klon)
60  cAM      REAL cd_h(klon) ! coefficient de friction au sol pour chaleur      ! thermal virtual temperature excess
61  cAM      REAL cd_m(klon) ! coefficient de friction au sol pour vitesse      REAL therm(klon)
62  c      REAL plcl(klon)
63        INTEGER isommet  
64        PARAMETER (isommet=klev) ! limite max sommet pbl      ! Local:
65        REAL vk      
66        PARAMETER (vk=0.35)     ! Von Karman => passer a .41 ! cf U.Olgstrom      INTEGER knon ! nombre de points a calculer
67        REAL ricr      INTEGER isommet
68        PARAMETER (ricr=0.4)      ! limite max sommet pbl
69        REAL fak      PARAMETER (isommet=klev)
70        PARAMETER (fak=8.5)     ! b calcul du Prandtl et de dTetas      REAL vk
71        REAL fakn      ! Von Karman => passer a .41 ! cf U.Olgstrom
72        PARAMETER (fakn=7.2)    ! a      PARAMETER (vk=0.35)
73        REAL onet      REAL ricr
74        PARAMETER (onet=1.0/3.0)      PARAMETER (ricr=0.4)
75        REAL t_coup      ! a
76        PARAMETER(t_coup=273.15)      REAL onet
77        REAL zkmin      PARAMETER (onet=1.0/3.0)
78        PARAMETER (zkmin=0.01)      REAL zkmin
79        REAL betam      PARAMETER (zkmin=0.01)
80        PARAMETER (betam=15.0)  ! pour Phim / h dans la S.L stable      REAL betam
81        REAL betah      ! pour Phim / h dans la S.L stable
82        PARAMETER (betah=15.0)      PARAMETER (betam=15.0)
83        REAL betas      ! z/OBL<>1
84        PARAMETER (betas=5.0)   ! Phit dans la S.L. stable (mais 2 formes / z/OBL<>1      REAL sffrac
85        REAL sffrac      ! S.L. = z/h < .1
86        PARAMETER (sffrac=0.1)  ! S.L. = z/h < .1      PARAMETER (sffrac=0.1)
87        REAL binm      REAL binm
88        PARAMETER (binm=betam*sffrac)      PARAMETER (binm=betam*sffrac)
89        REAL binh  
90        PARAMETER (binh=betah*sffrac)      REAL q_star, t_star
91        REAL ccon      ! Lambert correlations T' q' avec T* q*
92        PARAMETER (ccon=fak*sffrac*vk)      REAL b1, b2, b212, b2sr
93  c      PARAMETER (b1=70., b2=20.)
94        REAL q_star,t_star  
95        REAL b1,b2,b212,b2sr     ! Lambert correlations T' q' avec T* q*      REAL z(klon, klev)
96        PARAMETER (b1=70.,b2=20.)  
97  c      REAL zref
98        REAL z(klon,klev)      ! Niveau de ref a 2m peut eventuellement
99  cAM      REAL pcfm(klon,klev), pcfh(klon,klev)      PARAMETER (zref=2.)
100  cAM      ! etre choisi a 10m
101        REAL zref  
102        PARAMETER (zref=2.)    ! Niveau de ref a 2m peut eventuellement      INTEGER i, k
103  c                              etre choisi a 10m      REAL zxt
104  cMA      ! surface kinematic heat flux [mK/s]
105  c      REAL khfs(klon)
106        INTEGER i, k, j      ! sfc kinematic constituent flux [m/s]
107        REAL zxt      REAL kqfs(klon)
108  cAM      REAL zxt, zxq, zxu, zxv, zxmod, taux, tauy      ! surface virtual heat flux
109  cAM      REAL zx_alf1, zx_alf2 ! parametres pour extrapolation      REAL heatv(klon)
110        REAL khfs(klon)       ! surface kinematic heat flux [mK/s]      ! bulk Richardon no. mais en Theta_v
111        REAL kqfs(klon)       ! sfc kinematic constituent flux [m/s]      REAL rhino(klon, klev)
112        REAL heatv(klon)      ! surface virtual heat flux      ! pts w/unstbl pbl (positive virtual ht flx)
113        REAL rhino(klon,klev) ! bulk Richardon no. mais en Theta_v      LOGICAL unstbl(klon)
114        LOGICAL unstbl(klon)  ! pts w/unstbl pbl (positive virtual ht flx)      LOGICAL check(klon) ! Richardson number > critical
115        LOGICAL stblev(klon)  ! stable pbl with levels within pbl      ! flag de prolongerment cape pour pt Omega
116        LOGICAL unslev(klon)  ! unstbl pbl with levels within pbl      LOGICAL omegafl(klon)
117        LOGICAL unssrf(klon)  ! unstb pbl w/lvls within srf pbl lyr  
118        LOGICAL unsout(klon)  ! unstb pbl w/lvls in outer pbl lyr      ! Monin-Obukhov lengh
119        LOGICAL check(klon)   ! True=>chk if Richardson no.>critcal      REAL obklen(klon)
120        LOGICAL omegafl(klon) ! flag de prolongerment cape pour pt Omega  
121        REAL pblh(klon)      REAL zdu2
122        REAL pblT(klon)      ! Algorithme thermique
123        REAL plcl(klon)      REAL s(klon, klev) ! [P/Po]^Kappa milieux couches
124  cAM      REAL cgh(klon,2:klev) ! counter-gradient term for heat [K/m]      ! total water of thermal
125  cAM      REAL cgq(klon,2:klev) ! counter-gradient term for constituents      REAL qT_th(klon)
126  cAM      REAL cgs(klon,2:klev) ! counter-gradient star (cg/flux)      ! T thermique niveau precedent
127        REAL obklen(klon)     ! Monin-Obukhov lengh      REAL qsatbef(klon)
128  cAM      REAL ztvd, ztvu,      ! le thermique est sature
129        REAL zdu2      LOGICAL Zsat(klon)
130        REAL therm(klon)      ! thermal virtual temperature excess      REAL zthvd, zthvu, qqsat
131        REAL trmb1(klon),trmb2(klon),trmb3(klon)      REAL t2
132  C  Algorithme thermique  
133        REAL s(klon,klev)     ! [P/Po]^Kappa milieux couches      ! inverse phi function for momentum
134        REAL Th_th(klon)      ! potential temperature of thermal      REAL phiminv(klon)
135        REAL The_th(klon)     ! equivalent potential temperature of thermal      ! turbulent velocity scale for momentum
136        REAL qT_th(klon)      ! total water  of thermal      REAL wm(klon)
137        REAL Tbef(klon)       ! T thermique niveau precedent      ! current level height + one level up
138        REAL qsatbef(klon)      REAL zp(klon)
139        LOGICAL Zsat(klon)    ! le thermique est sature      REAL zcor
140        REAL Cape(klon)       ! Cape du thermique  
141        REAL Kape(klon)       ! Cape locale      REAL pblmin
142        REAL EauLiq(klon)     ! Eau liqu integr du thermique  
143        REAL ctei(klon)       ! Critere d'instab d'entrainmt des nuages de CL      !-----------------------------------------------------------------
144        REAL the1,the2,aa,bb,zthvd,zthvu,xintpos,qqsat  
145  cIM 091204 BEG      knon = size(pblh)
146        REAL a1,a2,a3  
147  cIM 091204 END      ! initialisations
148        REAL xhis,rnum,denom,th1,th2,thv1,thv2,ql2      q_star = 0
149        REAL dqsat_dt,qsat2,qT1,q2,t1,t2,xnull,delt_the      t_star = 0
150        REAL delt_qt,delt_2,quadsat,spblh,reduc  
151  c      b212=sqrt(b1*b2)
152        REAL phiminv(klon)    ! inverse phi function for momentum      b2sr=sqrt(b2)
153        REAL phihinv(klon)    ! inverse phi function for heat  
154        REAL wm(klon)         ! turbulent velocity scale for momentum      ! Calculer les hauteurs de chaque couche
155        REAL fak1(klon)       ! k*ustar*pblh      ! (geopotentielle Int_dp/ro = Int_[Rd.T.dp/p] z = geop/g)
156        REAL fak2(klon)       ! k*wm*pblh      ! pourquoi ne pas utiliser Phi/RG ?
157        REAL fak3(klon)       ! fakn*wstr/wm      DO i = 1, knon
158        REAL pblk(klon)       ! level eddy diffusivity for momentum         z(i, 1) = RD * t(i, 1) / (0.5*(paprs(i, 1)+pplay(i, 1))) &
159        REAL pr(klon)         ! Prandtl number for eddy diffusivities              * (paprs(i, 1)-pplay(i, 1)) / RG
160        REAL zl(klon)         ! zmzp / Obukhov length         s(i, 1) = (pplay(i, 1)/paprs(i, 1))**RKappa
161        REAL zh(klon)         ! zmzp / pblh      ENDDO
162        REAL zzh(klon)        ! (1-(zmzp/pblh))**2      ! s(k) = [pplay(k)/ps]^kappa
163        REAL wstr(klon)       ! w*, convective velocity scale      ! + + + + + + + + + pplay <-> s(k) t dp=pplay(k-1)-pplay(k)
164        REAL zm(klon)         ! current level height      ! ----------------- paprs <-> sig(k)
165        REAL zp(klon)         ! current level height + one level up      ! + + + + + + + + + pplay <-> s(k-1)
166        REAL zcor, zdelta, zcvm5      ! + + + + + + + + + pplay <-> s(1) t dp=paprs-pplay z(1)
167  cAM      REAL zxqs      ! ----------------- paprs <-> sig(1)
168        REAL fac, pblmin, zmzp, term  
169  c      DO k = 2, klev
170           DO i = 1, knon
171              z(i, k) = z(i, k-1) &
172                   + RD * 0.5*(t(i, k-1)+t(i, k)) / paprs(i, k) &
173  ! initialisations (Anne)                 * (pplay(i, k-1)-pplay(i, k)) / RG
174        th_th(:) = 0.            s(i, k) = (pplay(i, k) / paprs(i, 1))**RKappa
175        q_star = 0         ENDDO
176        t_star = 0      ENDDO
177    
178        ! Determination des grandeurs de surface
179        b212=sqrt(b1*b2)      DO i = 1, knon
180        b2sr=sqrt(b2)         ! Niveau de ref choisi a 2m
181  c         zxt = t2m(i)
182  C ============================================================  
183  C     Fonctions thermo implicites         ! convention >0 vers le bas ds lmdz
184  C ============================================================         khfs(i) = - flux_t(i)*zxt*Rd / (RCPD*paprs(i, 1))
185  c +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++         kqfs(i) = - flux_q(i)*zxt*Rd / paprs(i, 1)
186  c Tetens : pression partielle de vap d'eau e_sat(T)         ! verifier que khfs et kqfs sont bien de la forme w'l'
187  c =================================================         heatv(i) = khfs(i) + 0.608*zxt*kqfs(i)
188  C++ e_sat(T) = r2*exp( r3*(T-Tf)/(T-r4) ) id a r2*FOEWE         ! a comparer aussi aux sorties de clqh : flux_T/RoCp et flux_q/RoLv
189  C++ avec :         ! Theta et qT du thermique sans exces (interpolin vers surf)
190  C++ Tf = 273.16 K  (Temp de fusion de la glace)         ! chgt de niveau du thermique (jeudi 30/12/1999)
191  C++ r2 = 611.14 Pa         ! (interpolation lineaire avant integration phi_h)
192  C++ r3 = 17.269 (liquide) 21.875 (solide) adim         qT_th(i) = q2m(i)
193  C++ r4 = 35.86             7.66           Kelvin      ENDDO
194  C++  q_sat = eps*e_sat/(p-(1-eps)*e_sat)  
195  C++ derivée :      DO i = 1, knon
196  C++ =========         ! Global Richardson
197  C++                   r3*(Tf-r4)*q_sat(T,p)         rhino(i, 1) = 0.0
198  C++ d_qsat_dT = --------------------------------         check(i) = .TRUE.
199  C++             (T-r4)^2*( 1-(1-eps)*e_sat(T)/p )         ! on initialise pblh a l'altitude du 1er niv
200  c++ pour zcvm5=Lv, c'est FOEDE         pblh(i) = z(i, 1)
201  c++ Rq :(1.-REPS)*esarg/Parg id a RETV*Qsat         plcl(i) = 6000.
202  C     ------------------------------------------------------------------         ! Lambda = -u*^3 / (alpha.g.kvon.<w'Theta'v>
203  c         obklen(i) = -t(i, 1)*ustar(i)**3/(RG*vk*heatv(i))
204  c Initialisation      ENDDO
205        RLvCp = RLVTT/RCPD  
206        REPS  = RD/RV      ! PBL height calculation: Search for level of pbl. Scan upward
207        ! until the Richardson number between the first level and the
208  c      ! current level exceeds the "critical" value.  (bonne idee Nu de
209  c      DO i = 1, klon      ! separer le Ric et l'exces de temp du thermique)
210  c         pcfh(i,1) = cd_h(i)      DO k = 2, isommet
211  c         pcfm(i,1) = cd_m(i)         DO i = 1, knon
212  c      ENDDO            IF (check(i)) THEN
213  c      DO k = 2, klev               ! pourquoi / niveau 1 (au lieu du sol) et le terme en u*^2 ?
214  c      DO i = 1, klon               zdu2 = u(i, k)**2+v(i, k)**2
215  c         pcfh(i,k) = zkmin               zdu2 = max(zdu2, 1.0e-20)
216  c         pcfm(i,k) = zkmin               ! Theta_v environnement
217  c         cgs(i,k) = 0.0               zthvd=t(i, k)/s(i, k)*(1.+RETV*q(i, k))
218  c         cgh(i,k) = 0.0  
219  c         cgq(i,k) = 0.0               ! therm Theta_v sans exces (avec hypothese fausse de H&B, sinon,
220  c      ENDDO               ! passer par Theta_e et virpot)
221  c      ENDDO               zthvu = T2m(i)*(1.+RETV*qT_th(i))
222  c               ! Le Ri par Theta_v
223  c Calculer les hauteurs de chaque couche               ! On a nveau de ref a 2m ???
224  c (geopotentielle Int_dp/ro = Int_[Rd.T.dp/p] z = geop/g)               rhino(i, k) = (z(i, k)-zref)*RG*(zthvd-zthvu) &
225  c  pourquoi ne pas utiliser Phi/RG ?                    /(zdu2*0.5*(zthvd+zthvu))
226        DO i = 1, knon  
227           z(i,1) = RD * t(i,1) / (0.5*(paprs(i,1)+pplay(i,1)))               IF (rhino(i, k).GE.ricr) THEN
228       .               * (paprs(i,1)-pplay(i,1)) / RG                  pblh(i) = z(i, k-1) + (z(i, k-1)-z(i, k)) * &
229           s(i,1) = (pplay(i,1)/paprs(i,1))**RKappa                       (ricr-rhino(i, k-1))/(rhino(i, k-1)-rhino(i, k))
230        ENDDO                  ! test04
231  c                                 s(k) = [pplay(k)/ps]^kappa                  pblh(i) = pblh(i) + 100.
232  c    + + + + + + + + + pplay  <-> s(k)   t  dp=pplay(k-1)-pplay(k)                  pblT(i) = t(i, k-1) + (t(i, k)-t(i, k-1)) * &
233  c                       (pblh(i)-z(i, k-1))/(z(i, k)-z(i, k-1))
234  c    -----------------  paprs <-> sig(k)                  check(i) = .FALSE.
235  c               ENDIF
 c    + + + + + + + + + pplay  <-> s(k-1)  
 c  
 c  
 c    + + + + + + + + + pplay  <-> s(1)   t  dp=paprs-pplay   z(1)  
 c  
 c    -----------------  paprs <-> sig(1)  
 c  
       DO k = 2, klev  
       DO i = 1, knon  
          z(i,k) = z(i,k-1)  
      .              + RD * 0.5*(t(i,k-1)+t(i,k)) / paprs(i,k)  
      .                   * (pplay(i,k-1)-pplay(i,k)) / RG  
          s(i,k) = (pplay(i,k)/paprs(i,1))**RKappa  
       ENDDO  
       ENDDO  
 c  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++  
 c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++  
 c +++  Determination des grandeurs de surface  +++++++++++++++++++++  
 c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++  
 c  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++  
       DO i = 1, knon  
 cAM         IF (thermcep) THEN  
 cAM           zdelta=MAX(0.,SIGN(1.,RTT-tsol(i)))  
 c           zcvm5 = R5LES*RLVTT*(1.-zdelta) + R5IES*RLSTT*zdelta  
 c           zcvm5 = zcvm5 / RCPD / (1.0+RVTMP2*q(i,1))  
 cAM           zxqs= r2es * FOEEW(tsol(i),zdelta)/paprs(i,1)  
 cAM           zxqs=MIN(0.5,zxqs)  
 cAM           zcor=1./(1.-retv*zxqs)  
 cAM           zxqs=zxqs*zcor  
 cAM         ELSE  
 cAM           IF (tsol(i).LT.t_coup) THEN  
 cAM              zxqs = qsats(tsol(i)) / paprs(i,1)  
 cAM           ELSE  
 cAM              zxqs = qsatl(tsol(i)) / paprs(i,1)  
 cAM           ENDIF  
 cAM         ENDIF  
 c niveau de reference bulk; mais ici, c,a pourrait etre le niveau de ref du thermique  
 cAM        zx_alf1 = 1.0  
 cAM        zx_alf2 = 1.0 - zx_alf1  
 cAM        zxt = (t(i,1)+z(i,1)*RG/RCPD/(1.+RVTMP2*q(i,1)))  
 cAM     .        *(1.+RETV*q(i,1))*zx_alf1  
 cAM     .      + (t(i,2)+z(i,2)*RG/RCPD/(1.+RVTMP2*q(i,2)))  
 cAM     .        *(1.+RETV*q(i,2))*zx_alf2  
 cAM        zxu = u(i,1)*zx_alf1+u(i,2)*zx_alf2  
 cAM        zxv = v(i,1)*zx_alf1+v(i,2)*zx_alf2  
 cAM        zxq = q(i,1)*zx_alf1+q(i,2)*zx_alf2  
 cAM        
 cAMAM           zxu = u10m(i)  
 cAMAM           zxv = v10m(i)  
 cAMAM           zxmod = 1.0+SQRT(zxu**2+zxv**2)  
 cAM Niveau de ref choisi a 2m  
         zxt = t2m(i)  
   
 c ***************************************************  
 c attention, il doit s'agir de <w'theta'>  
 c   ;Calcul de tcls virtuel et de w'theta'virtuel  
 c   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  
 c   tcls=tcls*(1+.608*qcls)  
 c  
 c   ;Pour avoir w'theta',  
 c   ; il faut diviser par ro.Cp  
 c   Cp=Cpd*(1+0.84*qcls)  
 c   fcs=fcs/(ro_surf*Cp)  
 c   ;On transforme w'theta' en w'thetav'  
 c   Lv=(2.501-0.00237*(tcls-273.15))*1.E6  
 c   xle=xle/(ro_surf*Lv)  
 c   fcsv=fcs+.608*xle*tcls  
 c ***************************************************  
 cAM        khfs(i) = (tsol(i)*(1.+RETV*q(i,1))-zxt) *zxmod*cd_h(i)  
 cAM        kqfs(i) = (zxqs-zxq) *zxmod*cd_h(i) * beta(i)  
 cAM  
 cdif khfs est deja w't'_v / heatv(i) = khfs(i) + RETV*zxt*kqfs(i)  
 cAM calcule de Ro = paprs(i,1)/Rd zxt  
 cAM convention >0 vers le bas ds lmdz  
         khfs(i) = - flux_t(i,1)*zxt*Rd / (RCPD*paprs(i,1))  
         kqfs(i) = - flux_q(i,1)*zxt*Rd / (paprs(i,1))  
 cAM   verifier que khfs et kqfs sont bien de la forme w'l'  
         heatv(i) = khfs(i) + 0.608*zxt*kqfs(i)  
 c a comparer aussi aux sorties de clqh : flux_T/RoCp et flux_q/RoLv  
 cAM        heatv(i) = khfs(i)  
 cAM ustar est en entree  
 cAM        taux = zxu *zxmod*cd_m(i)  
 cAM        tauy = zxv *zxmod*cd_m(i)  
 cAM        ustar(i) = SQRT(taux**2+tauy**2)  
 cAM        ustar(i) = MAX(SQRT(ustar(i)),0.01)  
 c Theta et qT du thermique sans exces (interpolin vers surf)  
 c chgt de niveau du thermique (jeudi 30/12/1999)  
 c (interpolation lineaire avant integration phi_h)  
 cAM        qT_th(i) = zxqs*beta(i) + 4./z(i,1)*(q(i,1)-zxqs*beta(i))  
 cAM        qT_th(i) = max(qT_th(i),q(i,1))  
         qT_th(i) = q2m(i)  
 cn The_th restera la Theta du thermique sans exces jusqu'a 2eme calcul  
 cn reste a regler convention P) pour Theta  
 c        The_th(i) = tsol(i) + 4./z(i,1)*(t(i,1)-tsol(i))  
 c     -                      + RLvCp*qT_th(i)  
 cAM        Th_th(i) = tsol(i) + 4./z(i,1)*(t(i,1)-tsol(i))  
         Th_th(i) = t2m(i)  
       ENDDO  
 c  
       DO i = 1, knon  
          rhino(i,1) = 0.0   ! Global Richardson  
          check(i) = .TRUE.  
          pblh(i) = z(i,1)   ! on initialise pblh a l'altitude du 1er niveau  
          plcl(i) = 6000.  
 c Lambda = -u*^3 / (alpha.g.kvon.<w'Theta'v>  
          obklen(i) = -t(i,1)*ustar(i)**3/(RG*vk*heatv(i))  
          trmb1(i)   = 0.  
          trmb2(i)   = 0.  
          trmb3(i) = 0.  
       ENDDO  
   
 C  
 c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++  
 C PBL height calculation:  
 C Search for level of pbl. Scan upward until the Richardson number between  
 C the first level and the current level exceeds the "critical" value.  
 C (bonne idee Nu de separer le Ric et l'exces de temp du thermique)  
 c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++  
       fac = 100.0  
       DO k = 2, isommet  
       DO i = 1, knon  
       IF (check(i)) THEN  
 ! pourquoi / niveau 1 (au lieu du sol) et le terme en u*^2 ?  
 ctest     zdu2 = (u(i,k)-u(i,1))**2+(v(i,k)-v(i,1))**2+fac*ustar(i)**2  
          zdu2 = u(i,k)**2+v(i,k)**2  
          zdu2 = max(zdu2,1.0e-20)  
 c Theta_v environnement  
          zthvd=t(i,k)/s(i,k)*(1.+RETV*q(i,k))  
 c  
 c therm Theta_v sans exces (avec hypothese fausse de H&B, sinon,  
 c passer par Theta_e et virpot)  
 c         zthvu=t(i,1)/s(i,1)*(1.+RETV*q(i,1))  
 cAM         zthvu = Th_th(i)*(1.+RETV*q(i,1))  
          zthvu = Th_th(i)*(1.+RETV*qT_th(i))  
 c  Le Ri par Theta_v  
 cAM         rhino(i,k) = (z(i,k)-z(i,1))*RG*(zthvd-zthvu)  
 cAM     .               /(zdu2*0.5*(zthvd+zthvu))  
 cAM On a nveau de ref a 2m ???  
          rhino(i,k) = (z(i,k)-zref)*RG*(zthvd-zthvu)  
      .               /(zdu2*0.5*(zthvd+zthvu))  
 c  
          IF (rhino(i,k).GE.ricr) THEN  
            pblh(i) = z(i,k-1) + (z(i,k-1)-z(i,k)) *  
      .              (ricr-rhino(i,k-1))/(rhino(i,k-1)-rhino(i,k))  
 c test04  
            pblh(i) = pblh(i) + 100.  
            pblT(i) = t(i,k-1) + (t(i,k)-t(i,k-1)) *  
      .              (pblh(i)-z(i,k-1))/(z(i,k)-z(i,k-1))  
            check(i) = .FALSE.  
          ENDIF  
       ENDIF  
       ENDDO  
       ENDDO  
   
 C  
 C Set pbl height to maximum value where computation exceeds number of  
 C layers allowed  
 C  
       DO i = 1, knon  
         if (check(i)) pblh(i) = z(i,isommet)  
       ENDDO  
 C  
 C Improve estimate of pbl height for the unstable points.  
 C Find unstable points (sensible heat flux is upward):  
 C  
       DO i = 1, knon  
       IF (heatv(i) .GT. 0.) THEN  
         unstbl(i) = .TRUE.  
         check(i) = .TRUE.  
       ELSE  
         unstbl(i) = .FALSE.  
         check(i) = .FALSE.  
       ENDIF  
       ENDDO  
 C  
 C For the unstable case, compute velocity scale and the  
 C convective temperature excess:  
 C  
       DO i = 1, knon  
       IF (check(i)) THEN  
         phiminv(i) = (1.-binm*pblh(i)/obklen(i))**onet  
 c ***************************************************  
 c Wm ? et W* ? c'est la formule pour z/h < .1  
 c   ;Calcul de w* ;;  
 c   ;;;;;;;;;;;;;;;;  
 c   w_star=((g/tcls)*fcsv*z(ind))^(1/3.) [ou prendre la premiere approx de h)  
 c   ;; CALCUL DE wm ;;  
 c   ;;;;;;;;;;;;;;;;;;  
 c   ; Ici on considerera que l'on est dans la couche de surf jusqu'a 100m  
 c   ; On prend svt couche de surface=0.1*h mais on ne connait pas h  
 c   ;;;;;;;;;;;Dans la couche de surface  
 c   if (z(ind) le 20) then begin  
 c   Phim=(1.-15.*(z(ind)/L))^(-1/3.)  
 c   wm=u_star/Phim  
 c   ;;;;;;;;;;;En dehors de la couche de surface  
 c   endif else if (z(ind) gt 20) then begin  
 c   wm=(u_star^3+c1*w_star^3)^(1/3.)  
 c   endif  
 c ***************************************************  
         wm(i)= ustar(i)*phiminv(i)  
 c======================================================================  
 cvaleurs de Dominique Lambert de la campagne SEMAPHORE :  
 c <T'^2> = 100.T*^2; <q'^2> = 20.q*^2 a 10m  
 c <Tv'^2> = (1+1.2q).100.T* + 1.2Tv.sqrt(20*100).T*.q* + (.608*Tv)^2*20.q*^2;  
 c et dTetavS = sqrt(<Tv'^2>) ainsi calculee.  
 c avec : T*=<w'T'>_s/w* et q*=<w'q'>/w*  
 c !!! on peut donc utiliser w* pour les fluctuations <-> Lambert  
 c(leur corellation pourrait dependre de beta par ex)  
 c  if fcsv(i,j) gt 0 then begin  
 c    dTetavs=b1*(1.+2.*.608*q_10(i,j))*(fcs(i,j)/wm(i,j))^2+$  
 c    (.608*Thetav_10(i,j))^2*b2*(xle(i,j)/wm(i,j))^2+$  
 c    2.*.608*thetav_10(i,j)*sqrt(b1*b2)*(xle(i,j)/wm(i,j))*(fcs(i,j)/wm(i,j))  
 c    dqs=b2*(xle(i,j)/wm(i,j))^2  
 c    theta_s(i,j)=thetav_10(i,j)+sqrt(dTetavs)  
 c    q_s(i,j)=q_10(i,j)+sqrt(dqs)  
 c  endif else begin  
 c    Theta_s(i,j)=thetav_10(i,j)  
 c    q_s(i,j)=q_10(i,j)  
 c  endelse  
 c======================================================================  
 c  
 cHBTM        therm(i) = heatv(i)*fak/wm(i)  
 c forme Mathieu :  
         q_star = kqfs(i)/wm(i)  
         t_star = khfs(i)/wm(i)  
 cIM 091204 BEG  
         IF(1.EQ.0) THEN  
         IF(t_star.LT.0..OR.q_star.LT.0.) THEN  
           print*,'i t_star q_star khfs kqfs wm',i,t_star,q_star,  
      $    khfs(i),kqfs(i),wm(i)  
         ENDIF  
         ENDIF  
 cIM 091204 END  
 cAM Nveau cde ref 2m =>  
 cAM        therm(i) = sqrt( b1*(1.+2.*RETV*q(i,1))*t_star**2  
 cAM     +             + (RETV*T(i,1))**2*b2*q_star**2  
 cAM     +             + 2.*RETV*T(i,1)*b212*q_star*t_star  
 cAM     +                 )  
 cIM 091204 BEG  
         a1=b1*(1.+2.*RETV*qT_th(i))*t_star**2  
         a2=(RETV*Th_th(i))**2*b2*q_star**2  
         a3=2.*RETV*Th_th(i)*b212*q_star*t_star  
         aa=a1+a2+a3  
         IF(1.EQ.0) THEN  
         IF (aa.LT.0.) THEN  
          print*,'i a1 a2 a3 aa',i,a1,a2,a3,aa  
          print*,'i qT_th Th_th t_star q_star RETV b1 b2 b212',  
      $   i,qT_th(i),Th_th(i),t_star,q_star,RETV,b1,b2,b212  
         ENDIF  
         ENDIF  
 cIM 091204 END  
         therm(i) = sqrt( b1*(1.+2.*RETV*qT_th(i))*t_star**2  
      +             + (RETV*Th_th(i))**2*b2*q_star**2  
 cIM 101204  +             + 2.*RETV*Th_th(i)*b212*q_star*t_star  
      +             + max(0.,2.*RETV*Th_th(i)*b212*q_star*t_star)  
      +                 )  
 c  
 c Theta et qT du thermique (forme H&B) avec exces  
 c (attention, on ajoute therm(i) qui est virtuelle ...)  
 c pourquoi pas sqrt(b1)*t_star ?  
 c        dqs = b2sr*kqfs(i)/wm(i)  
         qT_th(i) = qT_th(i)  + b2sr*q_star  
 cnew on differre le calcul de Theta_e  
 c        The_th(i) = The_th(i) + therm(i) + RLvCp*qT_th(i)  
 c ou:    The_th(i) = The_th(i) + sqrt(b1)*khfs(i)/wm(i) + RLvCp*qT_th(i)  
         rhino(i,1) = 0.0  
       ENDIF  
       ENDDO  
 C  
 c +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++  
 c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++  
 C ++ Improve pblh estimate for unstable conditions using the +++++++  
 C ++          convective temperature excess :                +++++++  
 c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++  
 c +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++  
 C  
       DO k = 2, isommet  
       DO i = 1, knon  
       IF (check(i)) THEN  
 ctest     zdu2 = (u(i,k)-u(i,1))**2+(v(i,k)-v(i,1))**2+fac*ustar(i)**2  
          zdu2 = u(i,k)**2+v(i,k)**2  
          zdu2 = max(zdu2,1.0e-20)  
 c Theta_v environnement  
          zthvd=t(i,k)/s(i,k)*(1.+RETV*q(i,k))  
 c  
 c et therm Theta_v (avec hypothese de constance de H&B,  
 c         zthvu=(t(i,1)+therm(i))/s(i,1)*(1.+RETV*q(i,1))  
          zthvu = Th_th(i)*(1.+RETV*qT_th(i)) + therm(i)  
   
 c  
 c  Le Ri par Theta_v  
 cAM Niveau de ref 2m  
 cAM         rhino(i,k) = (z(i,k)-z(i,1))*RG*(zthvd-zthvu)  
 cAM     .               /(zdu2*0.5*(zthvd+zthvu))  
          rhino(i,k) = (z(i,k)-zref)*RG*(zthvd-zthvu)  
      .               /(zdu2*0.5*(zthvd+zthvu))  
 c  
 c  
          IF (rhino(i,k).GE.ricr) THEN  
            pblh(i) = z(i,k-1) + (z(i,k-1)-z(i,k)) *  
      .              (ricr-rhino(i,k-1))/(rhino(i,k-1)-rhino(i,k))  
 c test04  
            pblh(i) = pblh(i) + 100.  
            pblT(i) = t(i,k-1) + (t(i,k)-t(i,k-1)) *  
      .              (pblh(i)-z(i,k-1))/(z(i,k)-z(i,k-1))  
            check(i) = .FALSE.  
 cIM 170305 BEG  
       IF(1.EQ.0) THEN  
 c debug print -120;34       -34-        58 et    0;26 wamp  
       if (i.eq.950.or.i.eq.192.or.i.eq.624.or.i.eq.118) then  
             print*,' i,Th_th,Therm,qT :',i,Th_th(i),therm(i),qT_th(i)  
             q_star = kqfs(i)/wm(i)  
             t_star = khfs(i)/wm(i)  
             print*,'q* t*, b1,b2,b212 ',q_star,t_star  
      -            , b1*(1.+2.*RETV*qT_th(i))*t_star**2  
      -            , (RETV*Th_th(i))**2*b2*q_star**2  
      -            , 2.*RETV*Th_th(i)*b212*q_star*t_star  
             print*,'zdu2 ,100.*ustar(i)**2',zdu2 ,fac*ustar(i)**2  
       endif  
       ENDIF !(1.EQ.0) THEN  
 cIM 170305 END  
 c             q_star = kqfs(i)/wm(i)  
 c             t_star = khfs(i)/wm(i)  
 c             trmb1(i) = b1*(1.+2.*RETV*q(i,1))*t_star**2  
 c             trmb2(i) = (RETV*T(i,1))**2*b2*q_star**2  
 c Omega now   trmb3(i) = 2.*RETV*T(i,1)*b212*q_star*t_star  
          ENDIF  
       ENDIF  
       ENDDO  
       ENDDO  
 C  
 C Set pbl height to maximum value where computation exceeds number of  
 C layers allowed  
 C  
       DO i = 1, knon  
         if (check(i)) pblh(i) = z(i,isommet)  
       ENDDO  
 C  
 C PBL height must be greater than some minimum mechanical mixing depth  
 C Several investigators have proposed minimum mechanical mixing depth  
 C relationships as a function of the local friction velocity, u*.  We  
 C make use of a linear relationship of the form h = c u* where c=700.  
 C The scaling arguments that give rise to this relationship most often  
 C represent the coefficient c as some constant over the local coriolis  
 C parameter.  Here we make use of the experimental results of Koracin  
 C and Berkowicz (1988) [BLM, Vol 43] for wich they recommend 0.07/f  
 C where f was evaluated at 39.5 N and 52 N.  Thus we use a typical mid  
 C latitude value for f so that c = 0.07/f = 700.  
 C  
       DO i = 1, knon  
         pblmin  = 700.0*ustar(i)  
         pblh(i) = MAX(pblh(i),pblmin)  
 c par exemple :  
         pblT(i) = t(i,2) + (t(i,3)-t(i,2)) *  
      .              (pblh(i)-z(i,2))/(z(i,3)-z(i,2))  
       ENDDO  
   
 C ********************************************************************  
 C  pblh is now available; do preparation for diffusivity calculation :  
 C ********************************************************************  
       DO i = 1, knon  
         check(i) = .TRUE.  
         Zsat(i)   = .FALSE.  
 c omegafl utilise pour prolongement CAPE  
         omegafl(i) = .FALSE.  
         Cape(i)   = 0.  
         Kape(i)   = 0.  
         EauLiq(i) = 0.  
         CTEI(i)   = 0.  
         pblk(i) = 0.0  
         fak1(i) = ustar(i)*pblh(i)*vk  
 C  
 C Do additional preparation for unstable cases only, set temperature  
 C and moisture perturbations depending on stability.  
 C *** Rq: les formule sont prises dans leur forme CS ***  
         IF (unstbl(i)) THEN  
 cAM Niveau de ref du thermique  
 cAM          zxt=(t(i,1)-z(i,1)*0.5*RG/RCPD/(1.+RVTMP2*q(i,1)))  
 cAM     .         *(1.+RETV*q(i,1))  
           zxt=(Th_th(i)-zref*0.5*RG/RCPD/(1.+RVTMP2*qT_th(i)))  
      .         *(1.+RETV*qT_th(i))  
           phiminv(i) = (1. - binm*pblh(i)/obklen(i))**onet  
           phihinv(i) = sqrt(1. - binh*pblh(i)/obklen(i))  
           wm(i)      = ustar(i)*phiminv(i)  
           fak2(i)    = wm(i)*pblh(i)*vk  
           wstr(i)    = (heatv(i)*RG*pblh(i)/zxt)**onet  
           fak3(i)    = fakn*wstr(i)/wm(i)  
         ENDIF  
 c Computes Theta_e for thermal (all cases : to be modified)  
 c   attention ajout therm(i) = virtuelle  
         The_th(i) = Th_th(i) + therm(i) + RLvCp*qT_th(i)  
 c ou:    The_th(i) = Th_th(i) + sqrt(b1)*khfs(i)/wm(i) + RLvCp*qT_th(i)  
       ENDDO  
   
 C Main level loop to compute the diffusivities and  
 C counter-gradient terms:  
 C  
       DO 1000 k = 2, isommet  
 C  
 C Find levels within boundary layer:  
 C  
         DO i = 1, knon  
           unslev(i) = .FALSE.  
           stblev(i) = .FALSE.  
           zm(i) = z(i,k-1)  
           zp(i) = z(i,k)  
           IF (zkmin.EQ.0.0 .AND. zp(i).GT.pblh(i)) zp(i) = pblh(i)  
           IF (zm(i) .LT. pblh(i)) THEN  
             zmzp = 0.5*(zm(i) + zp(i))  
 C debug  
 c          if (i.EQ.1864) then  
 c             print*,'i,pblh(1864),obklen(1864)',i,pblh(i),obklen(i)  
 c          endif  
   
             zh(i) = zmzp/pblh(i)  
             zl(i) = zmzp/obklen(i)  
             zzh(i) = 0.  
             IF (zh(i).LE.1.0) zzh(i) = (1. - zh(i))**2  
 C  
 C stblev for points zm < plbh and stable and neutral  
 C unslev for points zm < plbh and unstable  
 C  
             IF (unstbl(i)) THEN  
               unslev(i) = .TRUE.  
             ELSE  
               stblev(i) = .TRUE.  
             ENDIF  
           ENDIF  
         ENDDO  
 c        print*,'fin calcul niveaux'  
 C  
 C Stable and neutral points; set diffusivities; counter-gradient  
 C terms zero for stable case:  
 C  
         DO i = 1, knon  
           IF (stblev(i)) THEN  
             IF (zl(i).LE.1.) THEN  
               pblk(i) = fak1(i)*zh(i)*zzh(i)/(1. + betas*zl(i))  
             ELSE  
               pblk(i) = fak1(i)*zh(i)*zzh(i)/(betas + zl(i))  
             ENDIF  
 c            pcfm(i,k) = pblk(i)  
 c            pcfh(i,k) = pcfm(i,k)  
           ENDIF  
         ENDDO  
 C  
 C unssrf, unstable within surface layer of pbl  
 C unsout, unstable within outer   layer of pbl  
 C  
         DO i = 1, knon  
           unssrf(i) = .FALSE.  
           unsout(i) = .FALSE.  
           IF (unslev(i)) THEN  
             IF (zh(i).lt.sffrac) THEN  
               unssrf(i) = .TRUE.  
             ELSE  
               unsout(i) = .TRUE.  
             ENDIF  
           ENDIF  
         ENDDO  
 C  
 C Unstable for surface layer; counter-gradient terms zero  
 C  
         DO i = 1, knon  
           IF (unssrf(i)) THEN  
             term = (1. - betam*zl(i))**onet  
             pblk(i) = fak1(i)*zh(i)*zzh(i)*term  
             pr(i) = term/sqrt(1. - betah*zl(i))  
236            ENDIF            ENDIF
237          ENDDO         ENDDO
238  c        print*,'fin counter-gradient terms zero'      ENDDO
239  C  
240  C Unstable for outer layer; counter-gradient terms non-zero:      ! Set pbl height to maximum value where computation exceeds number of
241  C      ! layers allowed
242          DO i = 1, knon      DO i = 1, knon
243            IF (unsout(i)) THEN         if (check(i)) pblh(i) = z(i, isommet)
244              pblk(i) = fak2(i)*zh(i)*zzh(i)      ENDDO
245  c            cgs(i,k) = fak3(i)/(pblh(i)*wm(i))  
246  c            cgh(i,k) = khfs(i)*cgs(i,k)      ! Improve estimate of pbl height for the unstable points.
247              pr(i) = phiminv(i)/phihinv(i) + ccon*fak3(i)/fak      ! Find unstable points (sensible heat flux is upward):
248  c            cgq(i,k) = kqfs(i)*cgs(i,k)      DO i = 1, knon
249           IF (heatv(i) > 0.) THEN
250              unstbl(i) = .TRUE.
251              check(i) = .TRUE.
252           ELSE
253              unstbl(i) = .FALSE.
254              check(i) = .FALSE.
255           ENDIF
256        ENDDO
257    
258        ! For the unstable case, compute velocity scale and the
259        ! convective temperature excess:
260        DO i = 1, knon
261           IF (check(i)) THEN
262              phiminv(i) = (1.-binm*pblh(i)/obklen(i))**onet
263    
264              ! CALCUL DE wm
265              ! Ici on considerera que l'on est dans la couche de surf jusqu'a 100
266              ! On prend svt couche de surface=0.1*h mais on ne connait pas h
267              ! Dans la couche de surface
268              wm(i)= ustar(i)*phiminv(i)
269    
270              ! forme Mathieu :
271              q_star = kqfs(i)/wm(i)
272              t_star = khfs(i)/wm(i)
273    
274              therm(i) = sqrt( b1*(1.+2.*RETV*qT_th(i))*t_star**2 &
275                   + (RETV*T2m(i))**2*b2*q_star**2 &
276                   + max(0., 2.*RETV*T2m(i)*b212*q_star*t_star))
277    
278              ! Theta et qT du thermique (forme H&B) avec exces
279              ! (attention, on ajoute therm(i) qui est virtuelle ...)
280              ! pourquoi pas sqrt(b1)*t_star ?
281              qT_th(i) = qT_th(i) + b2sr*q_star
282              ! new on diff\`ere le calcul de Theta_e
283              rhino(i, 1) = 0.
284           ENDIF
285        ENDDO
286    
287        ! Improve pblh estimate for unstable conditions using the
288        ! convective temperature excess :
289        DO k = 2, isommet
290           DO i = 1, knon
291              IF (check(i)) THEN
292                 zdu2 = u(i, k)**2 + v(i, k)**2
293                 zdu2 = max(zdu2, 1e-20)
294                 ! Theta_v environnement
295                 zthvd=t(i, k)/s(i, k)*(1.+RETV*q(i, k))
296    
297                 ! et therm Theta_v (avec hypothese de constance de H&B,
298                 zthvu = T2m(i)*(1.+RETV*qT_th(i)) + therm(i)
299    
300                 ! Le Ri par Theta_v
301                 ! Niveau de ref 2m
302                 rhino(i, k) = (z(i, k)-zref)*RG*(zthvd-zthvu) &
303                      /(zdu2*0.5*(zthvd+zthvu))
304    
305                 IF (rhino(i, k).GE.ricr) THEN
306                    pblh(i) = z(i, k-1) + (z(i, k-1)-z(i, k)) * &
307                         (ricr-rhino(i, k-1))/(rhino(i, k-1)-rhino(i, k))
308                    ! test04
309                    pblh(i) = pblh(i) + 100.
310                    pblT(i) = t(i, k-1) + (t(i, k)-t(i, k-1)) * &
311                         (pblh(i)-z(i, k-1))/(z(i, k)-z(i, k-1))
312                    check(i) = .FALSE.
313                 ENDIF
314            ENDIF            ENDIF
315          ENDDO         ENDDO
316  c        print*,'fin counter-gradient terms non zero'      ENDDO
317  C  
318  C For all unstable layers, compute diffusivities and ctrgrad ter m      ! Set pbl height to maximum value where computation exceeds number of
319  C      ! layers allowed
320  c        DO i = 1, knon      DO i = 1, knon
321  c        IF (unslev(i)) THEN         if (check(i)) pblh(i) = z(i, isommet)
322  c            pcfm(i,k) = pblk(i)      ENDDO
323  c            pcfh(i,k) = pblk(i)/pr(i)  
324  c etc cf original      ! PBL height must be greater than some minimum mechanical mixing depth
325  c        ENDIF      ! Several investigators have proposed minimum mechanical mixing depth
326  c        ENDDO      ! relationships as a function of the local friction velocity, u*. We
327  C      ! make use of a linear relationship of the form h = c u* where c=700.
328  C For all layers, compute integral info and CTEI      ! The scaling arguments that give rise to this relationship most often
329  C      ! represent the coefficient c as some constant over the local coriolis
330          DO i = 1, knon      ! parameter. Here we make use of the experimental results of Koracin
331          if (check(i).or.omegafl(i)) then      ! and Berkowicz (1988) [BLM, Vol 43] for wich they recommend 0.07/f
332            if (.not.Zsat(i)) then      ! where f was evaluated at 39.5 N and 52 N. Thus we use a typical mid
333  c            Th2 = The_th(i) - RLvCp*qT_th(i)      ! latitude value for f so that c = 0.07/f = 700.
334              Th2 = Th_th(i)      DO i = 1, knon
335              T2 = Th2*s(i,k)         pblmin = 700. * ustar(i)
336  c thermodyn functions         pblh(i) = MAX(pblh(i), pblmin)
337              zdelta=MAX(0.,SIGN(1.,RTT-T2))         ! par exemple :
338              qqsat= r2es * FOEEW(T2,zdelta)/pplay(i,k)         pblT(i) = t(i, 2) + (t(i, 3)-t(i, 2)) * &
339              qqsat=MIN(0.5,qqsat)              (pblh(i)-z(i, 2))/(z(i, 3)-z(i, 2))
340              zcor=1./(1.-retv*qqsat)      ENDDO
341              qqsat=qqsat*zcor  
342  c      ! pblh is now available; do preparation for diffusivity calculation:
343              if (qqsat.lt.qT_th(i)) then      DO i = 1, knon
344  c on calcule lcl         check(i) = .TRUE.
345                if (k.eq.2) then         Zsat(i) = .FALSE.
346                  plcl(i) = z(i,k)         ! omegafl utilise pour prolongement CAPE
347                else         omegafl(i) = .FALSE.
348                  plcl(i) =  z(i,k-1) + (z(i,k-1)-z(i,k)) *         Cape(i) = 0.
349       .                 (qT_th(i)-qsatbef(i))/(qsatbef(i)-qqsat)         EauLiq(i) = 0.
350                endif         CTEI(i) = 0.
351                Zsat(i) = .true.  
352                Tbef(i) = T2         ! Do additional preparation for unstable cases only, set temperature
353              endif         ! and moisture perturbations depending on stability.
354  c         ! Remarque : les formule sont prises dans leur forme CS
355           IF (unstbl(i)) THEN
356              ! Niveau de ref du thermique
357              zxt=(T2m(i)-zref*0.5*RG/RCPD/(1.+RVTMP2*qT_th(i))) &
358                   *(1.+RETV*qT_th(i))
359              phiminv(i) = (1. - binm*pblh(i)/obklen(i))**onet
360              wm(i) = ustar(i)*phiminv(i)
361           ENDIF
362        ENDDO
363    
364        ! Main level loop to compute the diffusivities and
365        ! counter-gradient terms:
366        loop_level: DO k = 2, isommet
367           ! Find levels within boundary layer:
368           DO i = 1, knon
369              zp(i) = z(i, k)
370              IF (zkmin == 0. .AND. zp(i) > pblh(i)) zp(i) = pblh(i)
371           ENDDO
372    
373           ! For all layers, compute integral info and CTEI
374           DO i = 1, knon
375              if (check(i) .or. omegafl(i)) then
376                 if (.not. Zsat(i)) then
377                    T2 = T2m(i) * s(i, k)
378                    ! thermodyn functions
379                    qqsat= r2es * FOEEW(T2, RTT >= T2) / pplay(i, k)
380                    qqsat=MIN(0.5, qqsat)
381                    zcor=1./(1.-retv*qqsat)
382                    qqsat=qqsat*zcor
383    
384                    if (qqsat < qT_th(i)) then
385                       ! on calcule lcl
386                       if (k == 2) then
387                          plcl(i) = z(i, k)
388                       else
389                          plcl(i) = z(i, k-1) + (z(i, k-1)-z(i, k)) &
390                               * (qT_th(i)-qsatbef(i)) / (qsatbef(i)-qqsat)
391                       endif
392                       Zsat(i) = .true.
393                    endif
394                 endif
395                 qsatbef(i) = qqsat
396                 ! cette ligne a deja ete faite normalement ?
397            endif            endif
398            qsatbef(i) = qqsat         ENDDO
399  camn ???? cette ligne a deja ete faite normalement ?      end DO loop_level
400          endif  
401  c            print*,'hbtm2 i,k=',i,k    END SUBROUTINE HBTM
402          ENDDO  
403   1000 continue           ! end of level loop  end module HBTM_m
 cIM 170305 BEG  
         IF(1.EQ.0) THEN  
             print*,'hbtm2  ok'  
         ENDIF !(1.EQ.0) THEN  
 cIM 170305 END  
       RETURN  
       END  

Legend:
Removed from v.3  
changed lines
  Added in v.346

  ViewVC Help
Powered by ViewVC 1.1.21