/[lmdze]/trunk/phylmd/hbtm.f
ViewVC logotype

Diff of /trunk/phylmd/hbtm.f

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/Sources/phylmd/hbtm.f revision 252 by guez, Mon Jan 22 15:02:56 2018 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  
48        INTEGER knon ! nombre de points a calculer      REAL, intent(in):: u(klon, klev) ! vitesse U (m/s)
49  cAM      REAL, intent(in):: v(klon, klev) ! vitesse V (m/s)
50        REAL t2m(klon), t10m(klon) ! temperature a 2 et 10m  
51        REAL q2m(klon), q10m(klon) ! q a 2 et 10m      ! temperature (K)
52        REAL ustar(klon)      REAL, intent(in):: t(klon, klev)
53        REAL paprs(klon,klev+1) ! pression a inter-couche (Pa)      ! vapeur d'eau (kg/kg)
54        REAL pplay(klon,klev)   ! pression au milieu de couche (Pa)      REAL, intent(in):: q(klon, klev)
55        REAL flux_t(klon,klev), flux_q(klon,klev)     ! Flux  
56        REAL u(klon,klev) ! vitesse U (m/s)      REAL, intent(out):: pblh(:) ! (knon)
57        REAL v(klon,klev) ! vitesse V (m/s)      ! Cape du thermique
58        REAL t(klon,klev) ! temperature (K)      REAL Cape(klon)
59        REAL q(klon,klev) ! vapeur d'eau (kg/kg)      ! Eau liqu integr du thermique
60  cAM      REAL cd_h(klon) ! coefficient de friction au sol pour chaleur      REAL EauLiq(klon)
61  cAM      REAL cd_m(klon) ! coefficient de friction au sol pour vitesse      ! Critere d'instab d'entrainmt des nuages de
62  c      REAL ctei(klon)
63        INTEGER isommet      REAL pblT(klon)
64        PARAMETER (isommet=klev) ! limite max sommet pbl      ! thermal virtual temperature excess
65        REAL vk      REAL therm(klon)
66        PARAMETER (vk=0.35)     ! Von Karman => passer a .41 ! cf U.Olgstrom      REAL plcl(klon)
67        REAL ricr  
68        PARAMETER (ricr=0.4)      ! Local:
69        REAL fak      
70        PARAMETER (fak=8.5)     ! b calcul du Prandtl et de dTetas      INTEGER knon ! nombre de points a calculer
71        REAL fakn      INTEGER isommet
72        PARAMETER (fakn=7.2)    ! a      ! limite max sommet pbl
73        REAL onet      PARAMETER (isommet=klev)
74        PARAMETER (onet=1.0/3.0)      REAL vk
75        REAL t_coup      ! Von Karman => passer a .41 ! cf U.Olgstrom
76        PARAMETER(t_coup=273.15)      PARAMETER (vk=0.35)
77        REAL zkmin      REAL ricr
78        PARAMETER (zkmin=0.01)      PARAMETER (ricr=0.4)
79        REAL betam      ! a
80        PARAMETER (betam=15.0)  ! pour Phim / h dans la S.L stable      REAL onet
81        REAL betah      PARAMETER (onet=1.0/3.0)
82        PARAMETER (betah=15.0)      REAL zkmin
83        REAL betas      PARAMETER (zkmin=0.01)
84        PARAMETER (betas=5.0)   ! Phit dans la S.L. stable (mais 2 formes / z/OBL<>1      REAL betam
85        REAL sffrac      ! pour Phim / h dans la S.L stable
86        PARAMETER (sffrac=0.1)  ! S.L. = z/h < .1      PARAMETER (betam=15.0)
87        REAL binm      ! z/OBL<>1
88        PARAMETER (binm=betam*sffrac)      REAL sffrac
89        REAL binh      ! S.L. = z/h < .1
90        PARAMETER (binh=betah*sffrac)      PARAMETER (sffrac=0.1)
91        REAL ccon      REAL binm
92        PARAMETER (ccon=fak*sffrac*vk)      PARAMETER (binm=betam*sffrac)
93  c  
94        REAL q_star,t_star      REAL q_star, t_star
95        REAL b1,b2,b212,b2sr     ! Lambert correlations T' q' avec T* q*      ! Lambert correlations T' q' avec T* q*
96        PARAMETER (b1=70.,b2=20.)      REAL b1, b2, b212, b2sr
97  c      PARAMETER (b1=70., b2=20.)
98        REAL z(klon,klev)  
99  cAM      REAL pcfm(klon,klev), pcfh(klon,klev)      REAL z(klon, klev)
100  cAM  
101        REAL zref      REAL zref
102        PARAMETER (zref=2.)    ! Niveau de ref a 2m peut eventuellement      ! Niveau de ref a 2m peut eventuellement
103  c                              etre choisi a 10m      PARAMETER (zref=2.)
104  cMA      ! etre choisi a 10m
105  c  
106        INTEGER i, k, j      INTEGER i, k
107        REAL zxt      REAL zxt
108  cAM      REAL zxt, zxq, zxu, zxv, zxmod, taux, tauy      ! surface kinematic heat flux [mK/s]
109  cAM      REAL zx_alf1, zx_alf2 ! parametres pour extrapolation      REAL khfs(klon)
110        REAL khfs(klon)       ! surface kinematic heat flux [mK/s]      ! sfc kinematic constituent flux [m/s]
111        REAL kqfs(klon)       ! sfc kinematic constituent flux [m/s]      REAL kqfs(klon)
112        REAL heatv(klon)      ! surface virtual heat flux      ! surface virtual heat flux
113        REAL rhino(klon,klev) ! bulk Richardon no. mais en Theta_v      REAL heatv(klon)
114        LOGICAL unstbl(klon)  ! pts w/unstbl pbl (positive virtual ht flx)      ! bulk Richardon no. mais en Theta_v
115        LOGICAL stblev(klon)  ! stable pbl with levels within pbl      REAL rhino(klon, klev)
116        LOGICAL unslev(klon)  ! unstbl pbl with levels within pbl      ! pts w/unstbl pbl (positive virtual ht flx)
117        LOGICAL unssrf(klon)  ! unstb pbl w/lvls within srf pbl lyr      LOGICAL unstbl(klon)
118        LOGICAL unsout(klon)  ! unstb pbl w/lvls in outer pbl lyr      LOGICAL check(klon) ! Richardson number > critical
119        LOGICAL check(klon)   ! True=>chk if Richardson no.>critcal      ! flag de prolongerment cape pour pt Omega
120        LOGICAL omegafl(klon) ! flag de prolongerment cape pour pt Omega      LOGICAL omegafl(klon)
121        REAL pblh(klon)  
122        REAL pblT(klon)      ! Monin-Obukhov lengh
123        REAL plcl(klon)      REAL obklen(klon)
124  cAM      REAL cgh(klon,2:klev) ! counter-gradient term for heat [K/m]  
125  cAM      REAL cgq(klon,2:klev) ! counter-gradient term for constituents      REAL zdu2
126  cAM      REAL cgs(klon,2:klev) ! counter-gradient star (cg/flux)      ! Algorithme thermique
127        REAL obklen(klon)     ! Monin-Obukhov lengh      REAL s(klon, klev) ! [P/Po]^Kappa milieux couches
128  cAM      REAL ztvd, ztvu,      ! total water of thermal
129        REAL zdu2      REAL qT_th(klon)
130        REAL therm(klon)      ! thermal virtual temperature excess      ! T thermique niveau precedent
131        REAL trmb1(klon),trmb2(klon),trmb3(klon)      REAL qsatbef(klon)
132  C  Algorithme thermique      ! le thermique est sature
133        REAL s(klon,klev)     ! [P/Po]^Kappa milieux couches      LOGICAL Zsat(klon)
134        REAL Th_th(klon)      ! potential temperature of thermal      REAL zthvd, zthvu, qqsat
135        REAL The_th(klon)     ! equivalent potential temperature of thermal      REAL t2
136        REAL qT_th(klon)      ! total water  of thermal  
137        REAL Tbef(klon)       ! T thermique niveau precedent      ! inverse phi function for momentum
138        REAL qsatbef(klon)      REAL phiminv(klon)
139        LOGICAL Zsat(klon)    ! le thermique est sature      ! turbulent velocity scale for momentum
140        REAL Cape(klon)       ! Cape du thermique      REAL wm(klon)
141        REAL Kape(klon)       ! Cape locale      ! current level height + one level up
142        REAL EauLiq(klon)     ! Eau liqu integr du thermique      REAL zp(klon)
143        REAL ctei(klon)       ! Critere d'instab d'entrainmt des nuages de CL      REAL zcor
144        REAL the1,the2,aa,bb,zthvd,zthvu,xintpos,qqsat  
145  cIM 091204 BEG      REAL pblmin
146        REAL a1,a2,a3  
147  cIM 091204 END      !-----------------------------------------------------------------
148        REAL xhis,rnum,denom,th1,th2,thv1,thv2,ql2  
149        REAL dqsat_dt,qsat2,qT1,q2,t1,t2,xnull,delt_the      knon = size(pblh)
150        REAL delt_qt,delt_2,quadsat,spblh,reduc  
151  c      ! initialisations
152        REAL phiminv(klon)    ! inverse phi function for momentum      q_star = 0
153        REAL phihinv(klon)    ! inverse phi function for heat      t_star = 0
154        REAL wm(klon)         ! turbulent velocity scale for momentum  
155        REAL fak1(klon)       ! k*ustar*pblh      b212=sqrt(b1*b2)
156        REAL fak2(klon)       ! k*wm*pblh      b2sr=sqrt(b2)
157        REAL fak3(klon)       ! fakn*wstr/wm  
158        REAL pblk(klon)       ! level eddy diffusivity for momentum      ! Calculer les hauteurs de chaque couche
159        REAL pr(klon)         ! Prandtl number for eddy diffusivities      ! (geopotentielle Int_dp/ro = Int_[Rd.T.dp/p] z = geop/g)
160        REAL zl(klon)         ! zmzp / Obukhov length      ! pourquoi ne pas utiliser Phi/RG ?
161        REAL zh(klon)         ! zmzp / pblh      DO i = 1, knon
162        REAL zzh(klon)        ! (1-(zmzp/pblh))**2         z(i, 1) = RD * t(i, 1) / (0.5*(paprs(i, 1)+pplay(i, 1))) &
163        REAL wstr(klon)       ! w*, convective velocity scale              * (paprs(i, 1)-pplay(i, 1)) / RG
164        REAL zm(klon)         ! current level height         s(i, 1) = (pplay(i, 1)/paprs(i, 1))**RKappa
165        REAL zp(klon)         ! current level height + one level up      ENDDO
166        REAL zcor, zdelta, zcvm5      ! s(k) = [pplay(k)/ps]^kappa
167  cAM      REAL zxqs      ! + + + + + + + + + pplay <-> s(k) t dp=pplay(k-1)-pplay(k)
168        REAL fac, pblmin, zmzp, term      ! ----------------- paprs <-> sig(k)
169  c      ! + + + + + + + + + pplay <-> s(k-1)
170        ! + + + + + + + + + pplay <-> s(1) t dp=paprs-pplay z(1)
171        ! ----------------- paprs <-> sig(1)
172    
173  ! initialisations (Anne)      DO k = 2, klev
174        th_th(:) = 0.         DO i = 1, knon
175        q_star = 0            z(i, k) = z(i, k-1) &
176        t_star = 0                 + RD * 0.5*(t(i, k-1)+t(i, k)) / paprs(i, k) &
177                   * (pplay(i, k-1)-pplay(i, k)) / RG
178              s(i, k) = (pplay(i, k) / paprs(i, 1))**RKappa
179        b212=sqrt(b1*b2)         ENDDO
180        b2sr=sqrt(b2)      ENDDO
181  c  
182  C ============================================================      ! Determination des grandeurs de surface
183  C     Fonctions thermo implicites      DO i = 1, knon
184  C ============================================================         ! Niveau de ref choisi a 2m
185  c +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++         zxt = t2m(i)
186  c Tetens : pression partielle de vap d'eau e_sat(T)  
187  c =================================================         ! convention >0 vers le bas ds lmdz
188  C++ e_sat(T) = r2*exp( r3*(T-Tf)/(T-r4) ) id a r2*FOEWE         khfs(i) = - flux_t(i)*zxt*Rd / (RCPD*paprs(i, 1))
189  C++ avec :         kqfs(i) = - flux_q(i)*zxt*Rd / paprs(i, 1)
190  C++ Tf = 273.16 K  (Temp de fusion de la glace)         ! verifier que khfs et kqfs sont bien de la forme w'l'
191  C++ r2 = 611.14 Pa         heatv(i) = khfs(i) + 0.608*zxt*kqfs(i)
192  C++ r3 = 17.269 (liquide) 21.875 (solide) adim         ! a comparer aussi aux sorties de clqh : flux_T/RoCp et flux_q/RoLv
193  C++ r4 = 35.86             7.66           Kelvin         ! Theta et qT du thermique sans exces (interpolin vers surf)
194  C++  q_sat = eps*e_sat/(p-(1-eps)*e_sat)         ! chgt de niveau du thermique (jeudi 30/12/1999)
195  C++ derivée :         ! (interpolation lineaire avant integration phi_h)
196  C++ =========         qT_th(i) = q2m(i)
197  C++                   r3*(Tf-r4)*q_sat(T,p)      ENDDO
198  C++ d_qsat_dT = --------------------------------  
199  C++             (T-r4)^2*( 1-(1-eps)*e_sat(T)/p )      DO i = 1, knon
200  c++ pour zcvm5=Lv, c'est FOEDE         ! Global Richardson
201  c++ Rq :(1.-REPS)*esarg/Parg id a RETV*Qsat         rhino(i, 1) = 0.0
202  C     ------------------------------------------------------------------         check(i) = .TRUE.
203  c         ! on initialise pblh a l'altitude du 1er niv
204  c Initialisation         pblh(i) = z(i, 1)
205        RLvCp = RLVTT/RCPD         plcl(i) = 6000.
206        REPS  = RD/RV         ! Lambda = -u*^3 / (alpha.g.kvon.<w'Theta'v>
207           obklen(i) = -t(i, 1)*ustar(i)**3/(RG*vk*heatv(i))
208  c      ENDDO
209  c      DO i = 1, klon  
210  c         pcfh(i,1) = cd_h(i)      ! PBL height calculation: Search for level of pbl. Scan upward
211  c         pcfm(i,1) = cd_m(i)      ! until the Richardson number between the first level and the
212  c      ENDDO      ! current level exceeds the "critical" value.  (bonne idee Nu de
213  c      DO k = 2, klev      ! separer le Ric et l'exces de temp du thermique)
214  c      DO i = 1, klon      DO k = 2, isommet
215  c         pcfh(i,k) = zkmin         DO i = 1, knon
216  c         pcfm(i,k) = zkmin            IF (check(i)) THEN
217  c         cgs(i,k) = 0.0               ! pourquoi / niveau 1 (au lieu du sol) et le terme en u*^2 ?
218  c         cgh(i,k) = 0.0               zdu2 = u(i, k)**2+v(i, k)**2
219  c         cgq(i,k) = 0.0               zdu2 = max(zdu2, 1.0e-20)
220  c      ENDDO               ! Theta_v environnement
221  c      ENDDO               zthvd=t(i, k)/s(i, k)*(1.+RETV*q(i, k))
222  c  
223  c Calculer les hauteurs de chaque couche               ! therm Theta_v sans exces (avec hypothese fausse de H&B, sinon,
224  c (geopotentielle Int_dp/ro = Int_[Rd.T.dp/p] z = geop/g)               ! passer par Theta_e et virpot)
225  c  pourquoi ne pas utiliser Phi/RG ?               zthvu = T2m(i)*(1.+RETV*qT_th(i))
226        DO i = 1, knon               ! Le Ri par Theta_v
227           z(i,1) = RD * t(i,1) / (0.5*(paprs(i,1)+pplay(i,1)))               ! On a nveau de ref a 2m ???
228       .               * (paprs(i,1)-pplay(i,1)) / RG               rhino(i, k) = (z(i, k)-zref)*RG*(zthvd-zthvu) &
229           s(i,1) = (pplay(i,1)/paprs(i,1))**RKappa                    /(zdu2*0.5*(zthvd+zthvu))
230        ENDDO  
231  c                                 s(k) = [pplay(k)/ps]^kappa               IF (rhino(i, k).GE.ricr) THEN
232  c    + + + + + + + + + pplay  <-> s(k)   t  dp=pplay(k-1)-pplay(k)                  pblh(i) = z(i, k-1) + (z(i, k-1)-z(i, k)) * &
233  c                       (ricr-rhino(i, k-1))/(rhino(i, k-1)-rhino(i, k))
234  c    -----------------  paprs <-> sig(k)                  ! test04
235  c                  pblh(i) = pblh(i) + 100.
236  c    + + + + + + + + + pplay  <-> s(k-1)                  pblT(i) = t(i, k-1) + (t(i, k)-t(i, k-1)) * &
237  c                       (pblh(i)-z(i, k-1))/(z(i, k)-z(i, k-1))
238  c                  check(i) = .FALSE.
239  c    + + + + + + + + + pplay  <-> s(1)   t  dp=paprs-pplay   z(1)               ENDIF
 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))  
240            ENDIF            ENDIF
241          ENDDO         ENDDO
242  c        print*,'fin counter-gradient terms zero'      ENDDO
243  C  
244  C Unstable for outer layer; counter-gradient terms non-zero:      ! Set pbl height to maximum value where computation exceeds number of
245  C      ! layers allowed
246          DO i = 1, knon      DO i = 1, knon
247            IF (unsout(i)) THEN         if (check(i)) pblh(i) = z(i, isommet)
248              pblk(i) = fak2(i)*zh(i)*zzh(i)      ENDDO
249  c            cgs(i,k) = fak3(i)/(pblh(i)*wm(i))  
250  c            cgh(i,k) = khfs(i)*cgs(i,k)      ! Improve estimate of pbl height for the unstable points.
251              pr(i) = phiminv(i)/phihinv(i) + ccon*fak3(i)/fak      ! Find unstable points (sensible heat flux is upward):
252  c            cgq(i,k) = kqfs(i)*cgs(i,k)      DO i = 1, knon
253           IF (heatv(i) > 0.) THEN
254              unstbl(i) = .TRUE.
255              check(i) = .TRUE.
256           ELSE
257              unstbl(i) = .FALSE.
258              check(i) = .FALSE.
259           ENDIF
260        ENDDO
261    
262        ! For the unstable case, compute velocity scale and the
263        ! convective temperature excess:
264        DO i = 1, knon
265           IF (check(i)) THEN
266              phiminv(i) = (1.-binm*pblh(i)/obklen(i))**onet
267    
268              ! CALCUL DE wm
269              ! Ici on considerera que l'on est dans la couche de surf jusqu'a 100
270              ! On prend svt couche de surface=0.1*h mais on ne connait pas h
271              ! Dans la couche de surface
272              wm(i)= ustar(i)*phiminv(i)
273    
274              ! forme Mathieu :
275              q_star = kqfs(i)/wm(i)
276              t_star = khfs(i)/wm(i)
277    
278              therm(i) = sqrt( b1*(1.+2.*RETV*qT_th(i))*t_star**2 &
279                   + (RETV*T2m(i))**2*b2*q_star**2 &
280                   + max(0., 2.*RETV*T2m(i)*b212*q_star*t_star))
281    
282              ! Theta et qT du thermique (forme H&B) avec exces
283              ! (attention, on ajoute therm(i) qui est virtuelle ...)
284              ! pourquoi pas sqrt(b1)*t_star ?
285              qT_th(i) = qT_th(i) + b2sr*q_star
286              ! new on differre le calcul de Theta_e
287              rhino(i, 1) = 0.
288           ENDIF
289        ENDDO
290    
291        ! Improve pblh estimate for unstable conditions using the
292        ! convective temperature excess :
293        DO k = 2, isommet
294           DO i = 1, knon
295              IF (check(i)) THEN
296                 zdu2 = u(i, k)**2 + v(i, k)**2
297                 zdu2 = max(zdu2, 1e-20)
298                 ! Theta_v environnement
299                 zthvd=t(i, k)/s(i, k)*(1.+RETV*q(i, k))
300    
301                 ! et therm Theta_v (avec hypothese de constance de H&B,
302                 zthvu = T2m(i)*(1.+RETV*qT_th(i)) + therm(i)
303    
304                 ! Le Ri par Theta_v
305                 ! Niveau de ref 2m
306                 rhino(i, k) = (z(i, k)-zref)*RG*(zthvd-zthvu) &
307                      /(zdu2*0.5*(zthvd+zthvu))
308    
309                 IF (rhino(i, k).GE.ricr) THEN
310                    pblh(i) = z(i, k-1) + (z(i, k-1)-z(i, k)) * &
311                         (ricr-rhino(i, k-1))/(rhino(i, k-1)-rhino(i, k))
312                    ! test04
313                    pblh(i) = pblh(i) + 100.
314                    pblT(i) = t(i, k-1) + (t(i, k)-t(i, k-1)) * &
315                         (pblh(i)-z(i, k-1))/(z(i, k)-z(i, k-1))
316                    check(i) = .FALSE.
317                 ENDIF
318            ENDIF            ENDIF
319          ENDDO         ENDDO
320  c        print*,'fin counter-gradient terms non zero'      ENDDO
321  C  
322  C For all unstable layers, compute diffusivities and ctrgrad ter m      ! Set pbl height to maximum value where computation exceeds number of
323  C      ! layers allowed
324  c        DO i = 1, knon      DO i = 1, knon
325  c        IF (unslev(i)) THEN         if (check(i)) pblh(i) = z(i, isommet)
326  c            pcfm(i,k) = pblk(i)      ENDDO
327  c            pcfh(i,k) = pblk(i)/pr(i)  
328  c etc cf original      ! PBL height must be greater than some minimum mechanical mixing depth
329  c        ENDIF      ! Several investigators have proposed minimum mechanical mixing depth
330  c        ENDDO      ! relationships as a function of the local friction velocity, u*. We
331  C      ! make use of a linear relationship of the form h = c u* where c=700.
332  C For all layers, compute integral info and CTEI      ! The scaling arguments that give rise to this relationship most often
333  C      ! represent the coefficient c as some constant over the local coriolis
334          DO i = 1, knon      ! parameter. Here we make use of the experimental results of Koracin
335          if (check(i).or.omegafl(i)) then      ! and Berkowicz (1988) [BLM, Vol 43] for wich they recommend 0.07/f
336            if (.not.Zsat(i)) then      ! where f was evaluated at 39.5 N and 52 N. Thus we use a typical mid
337  c            Th2 = The_th(i) - RLvCp*qT_th(i)      ! latitude value for f so that c = 0.07/f = 700.
338              Th2 = Th_th(i)      DO i = 1, knon
339              T2 = Th2*s(i,k)         pblmin = 700. * ustar(i)
340  c thermodyn functions         pblh(i) = MAX(pblh(i), pblmin)
341              zdelta=MAX(0.,SIGN(1.,RTT-T2))         ! par exemple :
342              qqsat= r2es * FOEEW(T2,zdelta)/pplay(i,k)         pblT(i) = t(i, 2) + (t(i, 3)-t(i, 2)) * &
343              qqsat=MIN(0.5,qqsat)              (pblh(i)-z(i, 2))/(z(i, 3)-z(i, 2))
344              zcor=1./(1.-retv*qqsat)      ENDDO
345              qqsat=qqsat*zcor  
346  c      ! pblh is now available; do preparation for diffusivity calculation:
347              if (qqsat.lt.qT_th(i)) then      DO i = 1, knon
348  c on calcule lcl         check(i) = .TRUE.
349                if (k.eq.2) then         Zsat(i) = .FALSE.
350                  plcl(i) = z(i,k)         ! omegafl utilise pour prolongement CAPE
351                else         omegafl(i) = .FALSE.
352                  plcl(i) =  z(i,k-1) + (z(i,k-1)-z(i,k)) *         Cape(i) = 0.
353       .                 (qT_th(i)-qsatbef(i))/(qsatbef(i)-qqsat)         EauLiq(i) = 0.
354                endif         CTEI(i) = 0.
355                Zsat(i) = .true.  
356                Tbef(i) = T2         ! Do additional preparation for unstable cases only, set temperature
357              endif         ! and moisture perturbations depending on stability.
358  c         ! Remarque : les formule sont prises dans leur forme CS
359           IF (unstbl(i)) THEN
360              ! Niveau de ref du thermique
361              zxt=(T2m(i)-zref*0.5*RG/RCPD/(1.+RVTMP2*qT_th(i))) &
362                   *(1.+RETV*qT_th(i))
363              phiminv(i) = (1. - binm*pblh(i)/obklen(i))**onet
364              wm(i) = ustar(i)*phiminv(i)
365           ENDIF
366        ENDDO
367    
368        ! Main level loop to compute the diffusivities and
369        ! counter-gradient terms:
370        loop_level: DO k = 2, isommet
371           ! Find levels within boundary layer:
372           DO i = 1, knon
373              zp(i) = z(i, k)
374              IF (zkmin == 0. .AND. zp(i) > pblh(i)) zp(i) = pblh(i)
375           ENDDO
376    
377           ! For all layers, compute integral info and CTEI
378           DO i = 1, knon
379              if (check(i) .or. omegafl(i)) then
380                 if (.not. Zsat(i)) then
381                    T2 = T2m(i) * s(i, k)
382                    ! thermodyn functions
383                    qqsat= r2es * FOEEW(T2, RTT >= T2) / pplay(i, k)
384                    qqsat=MIN(0.5, qqsat)
385                    zcor=1./(1.-retv*qqsat)
386                    qqsat=qqsat*zcor
387    
388                    if (qqsat < qT_th(i)) then
389                       ! on calcule lcl
390                       if (k == 2) then
391                          plcl(i) = z(i, k)
392                       else
393                          plcl(i) = z(i, k-1) + (z(i, k-1)-z(i, k)) &
394                               * (qT_th(i)-qsatbef(i)) / (qsatbef(i)-qqsat)
395                       endif
396                       Zsat(i) = .true.
397                    endif
398                 endif
399                 qsatbef(i) = qqsat
400                 ! cette ligne a deja ete faite normalement ?
401            endif            endif
402            qsatbef(i) = qqsat         ENDDO
403  camn ???? cette ligne a deja ete faite normalement ?      end DO loop_level
404          endif  
405  c            print*,'hbtm2 i,k=',i,k    END SUBROUTINE HBTM
406          ENDDO  
407   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.252

  ViewVC Help
Powered by ViewVC 1.1.21