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

  ViewVC Help
Powered by ViewVC 1.1.21