6 !-----------------------------------------------------------------
7 SUBROUTINE CU_SAS(DT,ITIMESTEP,STEPCU, &
8 RTHCUTEN,RQVCUTEN,RQCCUTEN,RQICUTEN, &
10 RAINCV,PRATEC,HTOP,HBOT, &
11 U3D,V3D,W,T3D,QV3D,QC3D,QI3D,PI3D,RHO3D, &
12 DZ8W,PCPS,P8W,XLAND,CU_ACT_FLAG, &
14 MOMMIX, & ! gopal's doing
15 PGCON,sas_mass_flux, &
16 pert_sas, ens_random_seed, ens_sasamp, &
17 shalconv,shal_pgcon, &
18 HPBL2D,EVAP2D,HEAT2D, & !Kwon for shallow convection
19 P_QI,P_FIRST_SCALAR, &
20 ids,ide, jds,jde, kds,kde, &
21 ims,ime, jms,jme, kms,kme, &
22 its,ite, jts,jte, kts,kte )
24 !-------------------------------------------------------------------
25 USE MODULE_GFS_MACHINE , ONLY : kind_phys
26 USE MODULE_GFS_FUNCPHYS , ONLY : gfuncphys
27 USE MODULE_GFS_PHYSCONS, grav => con_g, CP => con_CP, HVAP => con_HVAP &
28 &, RV => con_RV, FV => con_fvirt, T0C => con_T0C &
29 &, CVAP => con_CVAP, CLIQ => con_CLIQ &
30 &, EPS => con_eps, EPSM1 => con_epsm1 &
31 &, ROVCP => con_rocp, RD => con_rd
32 !-------------------------------------------------------------------
34 !-------------------------------------------------------------------
35 !-- U3D 3D u-velocity interpolated to theta points (m/s)
36 !-- V3D 3D v-velocity interpolated to theta points (m/s)
37 !-- TH3D 3D potential temperature (K)
38 !-- T3D temperature (K)
39 !-- QV3D 3D water vapor mixing ratio (Kg/Kg)
40 !-- QC3D 3D cloud mixing ratio (Kg/Kg)
41 !-- QI3D 3D ice mixing ratio (Kg/Kg)
42 !-- P8w 3D pressure at full levels (Pa)
43 !-- Pcps 3D pressure (Pa)
44 !-- PI3D 3D exner function (dimensionless)
45 !-- rr3D 3D dry air density (kg/m^3)
46 !-- RUBLTEN U tendency due to
47 ! PBL parameterization (m/s^2)
48 !-- RVBLTEN V tendency due to
49 ! PBL parameterization (m/s^2)
50 !-- RTHBLTEN Theta tendency due to
51 ! PBL parameterization (K/s)
52 !-- RQVBLTEN Qv tendency due to
53 ! PBL parameterization (kg/kg/s)
54 !-- RQCBLTEN Qc tendency due to
55 ! PBL parameterization (kg/kg/s)
56 !-- RQIBLTEN Qi tendency due to
57 ! PBL parameterization (kg/kg/s)
59 !-- MOMMIX MOMENTUM MIXING COEFFICIENT (can be set in the namelist)
60 !-- RUCUTEN U tendency due to Cumulus Momentum Mixing (gopal's doing for SAS)
61 !-- RVCUTEN V tendency due to Cumulus Momentum Mixing (gopal's doing for SAS)
63 !-- CP heat capacity at constant pressure for dry air (J/kg/K)
64 !-- GRAV acceleration due to gravity (m/s^2)
66 !-- RD gas constant for dry air (J/kg/K)
68 !-- P_QI species index for cloud ice
69 !-- dz8w dz between full levels (m)
70 !-- z height above sea level (m)
71 !-- PSFC pressure at the surface (Pa)
72 !-- UST u* in similarity theory (m/s)
73 !-- PBL PBL height (m)
74 !-- PSIM similarity stability function for momentum
75 !-- PSIH similarity stability function for heat
76 !-- HFX upward heat flux at the surface (W/m^2)
77 !-- QFX upward moisture flux at the surface (kg/m^2/s)
78 !-- TSK surface temperature (K)
79 !-- GZ1OZ0 log(z/z0) where z0 is roughness length
80 !-- WSPD wind speed at lowest model level (m/s)
81 !-- BR bulk Richardson number in surface layer
83 !-- rvovrd R_v divided by R_d (dimensionless)
84 !-- EP1 constant for virtual temperature (R_v/R_d - 1) (dimensionless)
85 !-- KARMAN Von Karman constant
86 !-- ids start index for i in domain
87 !-- ide end index for i in domain
88 !-- jds start index for j in domain
89 !-- jde end index for j in domain
90 !-- kds start index for k in domain
91 !-- kde end index for k in domain
92 !-- ims start index for i in memory
93 !-- ime end index for i in memory
94 !-- jms start index for j in memory
95 !-- jme end index for j in memory
96 !-- kms start index for k in memory
97 !-- kme end index for k in memory
98 !-- its start index for i in tile
99 !-- ite end index for i in tile
100 !-- jts start index for j in tile
101 !-- jte end index for j in tile
102 !-- kts start index for k in tile
103 !-- kte end index for k in tile
104 !-------------------------------------------------------------------
108 INTEGER, INTENT(IN) :: ids,ide, jds,jde, kds,kde, &
109 ims,ime, jms,jme, kms,kme, &
110 its,ite, jts,jte, kts,kte, &
117 REAL, INTENT(IN) :: &
120 REAL, OPTIONAL, INTENT(IN) :: PGCON,sas_mass_flux,shal_pgcon
121 INTEGER, OPTIONAL, INTENT(IN) :: shalconv
122 REAL(kind=kind_phys) :: PGCON_USE,SHAL_PGCON_USE,massf
123 logical,intent(in) :: pert_sas
124 integer,intent(in) :: ens_random_seed
125 real,intent(in) :: ens_sasamp
126 INTEGER :: shalconv_use
127 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: &
132 REAL, DIMENSION(ims:ime, jms:jme, kms:kme), INTENT(INOUT) :: &
135 REAL, OPTIONAL, INTENT(IN) :: MOMMIX
137 REAL, DIMENSION( ims:ime , jms:jme ), OPTIONAL, &
138 INTENT(IN) :: HPBL2D,EVAP2D,HEAT2D !Kwon for sha
140 REAL, DIMENSION(ims:ime, jms:jme), INTENT(IN) :: &
143 REAL, DIMENSION(ims:ime, jms:jme), INTENT(INOUT) :: &
146 REAL, DIMENSION(ims:ime, jms:jme), INTENT(OUT) :: &
150 LOGICAL, DIMENSION(IMS:IME,JMS:JME), INTENT(INOUT) :: &
154 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(IN) :: &
168 !--------------------------- LOCAL VARS ------------------------------
170 REAL, DIMENSION(ims:ime, jms:jme) :: &
173 REAL, DIMENSION(its:ite, jts:jte) :: &
175 REAL, DIMENSION(its:ite, jts:jte) :: &
178 REAL (kind=kind_phys) :: &
184 REAL (kind=kind_phys), DIMENSION(its:ite) :: &
190 HPBL,EVAP,HEAT !Kwon for shallow convection
192 REAL (kind=kind_phys), DIMENSION(its:ite, kts:kte+1) :: &
195 REAL (kind=kind_phys), DIMENSION(its:ite, kts:kte) :: &
208 REAL (kind=kind_phys), DIMENSION(its:ite, kts:kte, 2) :: &
211 INTEGER, DIMENSION(its:ite) :: &
230 !-----------------------------------------------------------------------
233 if(present(shalconv)) then
234 shalconv_use=shalconv
247 if(present(pgcon)) then
250 ! pgcon_use = 0.7 ! Gregory et al. (1997, QJRMS)
251 pgcon_use = 0.55 ! Zhang & Wu (2003,JAS), used in GFS (25km res spectral)
252 ! pgcon_use = 0.2 ! HWRF, for model tuning purposes
253 ! pgcon_use = 0.3 ! GFDL, or so I am told
255 ! For those attempting to tune pgcon:
257 ! The value of 0.55 comes from an observational study of
258 ! synoptic-scale deep convection and 0.7 came from an
259 ! incorrect fit to the same data. That value is likely
260 ! correct for deep convection at gridscales near that of GFS,
261 ! but is questionable in shallow convection, or for scales
262 ! much finer than synoptic scales.
264 ! Then again, the assumptions of SAS break down when the
265 ! gridscale is near the convection scale anyway. In a large
266 ! storm such as a hurricane, there is often no environment to
267 ! detrain into since adjancent gridsquares are also undergoing
268 ! active convection. Each gridsquare will no longer have many
269 ! updrafts and downdrafts. At sub-convective timescales, you
270 ! will find unstable columns for many (say, 5 second length)
271 ! timesteps in a real atmosphere during a convection cell's
272 ! lifetime, so forcing it to be neutrally stable is unphysical.
274 ! Hence, in scales near the convection scale (cells have
275 ! ~0.5-4km diameter in hurricanes), this parameter is more of a
276 ! tuning parameter to get a scheme that is inappropriate for
277 ! that resolution to do a reasonable job.
279 ! Your mileage might vary.
284 if(present(sas_mass_flux)) then
286 ! Use this to reduce the fluxes added by SAS to prevent
287 ! computational instability as a result of large fluxes.
289 massf=9e9 ! large number to disable check
292 if(present(shal_pgcon)) then
293 if(shal_pgcon>=0) then
294 shal_pgcon_use = shal_pgcon
296 ! shal_pgcon<0 means use deep pgcon
297 shal_pgcon_use = pgcon_use
300 ! Default: Same as deep convection pgcon
301 shal_pgcon_use = pgcon_use
302 ! Read the warning above though. It may be advisable for
303 ! these to be different.
308 CU_ACT_FLAG(I,J)=.TRUE.
323 PSFC(i,j)=P8w(i,kms,j)
327 if(igpvs.eq.0) CALL GFUNCPHYS
330 !------------- J LOOP (OUTER) --------------------------------------------------
332 big_outer_j_loop: DO J=jts,jte
334 ! --------------- compute zi and zl -----------------------------------------
342 ZI(I,K)=ZI(I,KM)+dz8w(i,km,j)
349 ZL(I,KM)=(ZI(I,K)+ZI(I,KM))*0.5
354 ZL(I,KTE)=2.*ZI(I,KTE)-ZL(I,KTE-1)
357 ! --------------- end compute zi and zl -------------------------------------
362 SLIMSK(i)=ABS(XLAND(i,j)-2.)
366 if(shalconv_use==1) then
368 HPBL(I) = HPBL2D(I,J) !kwon for shallow convection
369 EVAP(I) = EVAP2D(I,J) !kwon for shallow convection
370 HEAT(I) = HEAT2D(I,J) !kwon for shallow convection
382 PRSL(I,K)=Pcps(i,k,j)*.001
383 PHIL(I,K)=ZL(I,K)*GRAV
384 DOT(i,k)=-5.0E-4*GRAV*rho3d(i,k,j)*(w(i,k,j)+w(i,kp,j))
390 DEL(i,k)=PRSL(i,k)*GRAV/RD*dz8w(i,k,j)/T3D(i,k,j)
393 Q1(i,k)=QV3D(i,k,j)/(1.+QV3D(i,k,j))
395 QL(i,k,1)=QI3D(i,k,j)/(1.+QI3D(i,k,j))
396 QL(i,k,2)=QC3D(i,k,j)/(1.+QC3D(i,k,j))
397 PRSLK(I,K)=(PRSL(i,k)*.01)**ROVCP
404 PRSI(i,k)=PRSI(i,km)-del(i,km)
408 CALL SASCNVN(IM,IM,KX,JCAP,DELT,DEL,PRSL,PS,PHIL, &
409 QL,Q1,T1,U1,V1,RCS,CLDWRK,RN,KBOT, &
410 KTOP,KCNV,SLIMSK,DOT,NCLOUD,PGCON_USE,massf, &
411 pert_sas, ens_random_seed, ens_sasamp)
414 RAINCV1(I,J)=RN(I)*1000./STEPCU
415 PRATEC1(I,J)=RN(I)*1000./(STEPCU * DT)
424 if_shallow_conv: if(shalconv_use==1) then
426 ! NMM calls the new shallow convection developed by J Han
427 ! (Added to WRF by Y.Kwon)
428 call shalcnv(im,im,kx,jcap,delt,del,prsl,ps,phil,ql, &
429 & q1,t1,u1,v1,rcs,rn,kbot,ktop,kcnv,slimsk, &
430 & dot,ncloud,hpbl,heat,evap,shal_pgcon_use)
433 RAINCV2(I,J)=RN(I)*1000./STEPCU
434 PRATEC2(I,J)=RN(I)*1000./(STEPCU * DT)
439 ! NOTE: ARW should be able to call the new shalcnv here, but
440 ! they need to add the three new variables, so I'm leaving the
441 ! old shallow convection call here - Sam Trahan
442 CALL OLD_ARW_SHALCV(IM,IM,KX,DELT,DEL,PRSI,PRSL,PRSLK,KCNV,Q1,T1,DPSHC)
444 ! Shallow convection is untested for other cores.
447 endif if_shallow_conv
450 RAINCV(I,J)= RAINCV1(I,J) + RAINCV2(I,J)
451 PRATEC(I,J)= PRATEC1(I,J) + PRATEC2(I,J)
458 RTHCUTEN(I,K,J)=(T1(I,K)-T3D(I,K,J))/PI3D(I,K,J)*RDELT
459 RQVCUTEN(I,K,J)=(Q1(I,K)/(1.-q1(i,k))-QV3D(I,K,J))*RDELT
463 !===============================================================================
464 ! ADD MOMENTUM MIXING TERM AS TENDENCIES. This is gopal's doing for SAS
465 ! MOMMIX is the reduction factor set to 0.7 by default. Because NMM has
466 ! divergence damping term, a reducion factor for cumulum mixing may be
467 ! required otherwise storms were too weak.
468 !===============================================================================
473 ! RUCUTEN(I,J,K)=MOMMIX*(U1(I,K)-U3D(I,K,J))*RDELT
474 ! RVCUTEN(I,J,K)=MOMMIX*(V1(I,K)-V3D(I,K,J))*RDELT
475 RUCUTEN(I,J,K)=(U1(I,K)-U3D(I,K,J))*RDELT
476 RVCUTEN(I,J,K)=(V1(I,K)-V3D(I,K,J))*RDELT
482 IF(P_QC .ge. P_FIRST_SCALAR)THEN
485 RQCCUTEN(I,K,J)=(QL(I,K,2)/(1.-ql(i,k,2))-QC3D(I,K,J))*RDELT
490 IF(P_QI .ge. P_FIRST_SCALAR)THEN
493 RQICUTEN(I,K,J)=(QL(I,K,1)/(1.-ql(i,k,1))-QI3D(I,K,J))*RDELT
498 ENDDO big_outer_j_loop ! Outer most J loop
500 END SUBROUTINE CU_SAS
502 !====================================================================
503 SUBROUTINE sasinit(RTHCUTEN,RQVCUTEN,RQCCUTEN,RQICUTEN, &
505 RESTART,P_QC,P_QI,P_FIRST_SCALAR, &
507 ids, ide, jds, jde, kds, kde, &
508 ims, ime, jms, jme, kms, kme, &
509 its, ite, jts, jte, kts, kte )
510 !--------------------------------------------------------------------
512 !--------------------------------------------------------------------
513 LOGICAL , INTENT(IN) :: allowed_to_read,restart
514 INTEGER , INTENT(IN) :: ids, ide, jds, jde, kds, kde, &
515 ims, ime, jms, jme, kms, kme, &
516 its, ite, jts, jte, kts, kte
517 INTEGER , INTENT(IN) :: P_FIRST_SCALAR, P_QI, P_QC
519 REAL, DIMENSION( ims:ime , kms:kme , jms:jme ) , INTENT(OUT) :: &
524 REAL, DIMENSION( ims:ime , jms:jme , kms:kme ) , INTENT(OUT) :: &
525 RUCUTEN, & ! gopal's doing for SAS
528 INTEGER :: i, j, k, itf, jtf, ktf
536 IF(.not.restart .or. .not.allowed_to_read)THEN
537 !end of zhang's doing
552 IF (P_QC .ge. P_FIRST_SCALAR) THEN
562 IF (P_QI .ge. P_FIRST_SCALAR) THEN
573 END SUBROUTINE sasinit
575 ! ------------------------------------------------------------------------
577 SUBROUTINE SASCNV(IM,IX,KM,JCAP,DELT,DEL,PRSL,PS,PHIL,QL, &
578 ! SUBROUTINE SASCNV(IM,IX,KM,JCAP,DLT,DEL,PRSL,PHIL,QL, &
579 & Q1,T1,U1,V1,RCS,CLDWRK,RN,KBOT,KTOP,KUO,SLIMSK, &
581 ! for cloud water version
582 ! parameter(ncloud=0)
583 ! SUBROUTINE SASCNV(KM,JCAP,DELT,DEL,SL,SLK,PS,QL,
584 ! & Q1,T1,U1,V1,RCS,CLDWRK,RN,KBOT,KTOP,KUO,SLIMSK,
587 USE MODULE_GFS_MACHINE , ONLY : kind_phys
588 USE MODULE_GFS_FUNCPHYS ,ONLY : fpvs
589 USE MODULE_GFS_PHYSCONS, grav => con_g, CP => con_CP, HVAP => con_HVAP &
590 &, RV => con_RV, FV => con_fvirt, T0C => con_T0C &
591 &, CVAP => con_CVAP, CLIQ => con_CLIQ &
592 &, EPS => con_eps, EPSM1 => con_epsm1
596 ! include 'constant.h'
598 integer IM, IX, KM, JCAP, ncloud, &
599 & KBOT(IM), KTOP(IM), KUO(IM), J
600 real(kind=kind_phys) DELT
601 real(kind=kind_phys) PS(IM), DEL(IX,KM), PRSL(IX,KM), &
602 ! real(kind=kind_phys) DEL(IX,KM), PRSL(IX,KM),
603 & QL(IX,KM,2), Q1(IX,KM), T1(IX,KM), &
604 & U1(IX,KM), V1(IX,KM), RCS(IM), &
605 & CLDWRK(IM), RN(IM), SLIMSK(IM), &
606 & DOT(IX,KM), XKT2(IM), PHIL(IX,KM)
608 integer I, INDX, jmn, k, knumb, latd, lond, km1
610 real(kind=kind_phys) adw, alpha, alphal, alphas, &
611 & aup, beta, betal, betas, &
612 & c0, cpoel, dellat, delta, &
613 & desdt, deta, detad, dg, &
614 & dh, dhh, dlnsig, dp, &
615 & dq, dqsdp, dqsdt, dt, &
616 & dt2, dtmax, dtmin, dv1, &
617 & dv1q, dv2, dv2q, dv1u, &
618 & dv1v, dv2u, dv2v, dv3u, &
619 & dv3v, dv3, dv3q, dvq1, &
620 & dz, dz1, e1, edtmax, &
621 & edtmaxl, edtmaxs, el2orc, elocp, &
623 & evef, evfact, evfactl, fact1, &
624 & fact2, factor, fjcap, fkm, &
625 & fuv, g, gamma, onemf, &
626 & onemfu, pdetrn, pdpdwn, pprime, &
627 & qc, qlk, qrch, qs, &
628 & rain, rfact, shear, tem1, &
629 & tem2, terr, val, val1, &
630 & val2, w1, w1l, w1s, &
631 & w2, w2l, w2s, w3, &
632 & w3l, w3s, w4, w4l, &
633 & w4s, xdby, xpw, xpwd, &
634 & xqc, xqrch, xlambu, mbdt, &
638 integer JMIN(IM), KB(IM), KBCON(IM), KBDTR(IM), &
639 & KT2(IM), KTCON(IM), LMIN(IM), &
640 & kbm(IM), kbmax(IM), kmax(IM)
642 real(kind=kind_phys) AA1(IM), ACRT(IM), ACRTFCT(IM), &
643 & DELHBAR(IM), DELQ(IM), DELQ2(IM), &
644 & DELQBAR(IM), DELQEV(IM), DELTBAR(IM), &
645 & DELTV(IM), DTCONV(IM), EDT(IM), &
646 & EDTO(IM), EDTX(IM), FLD(IM), &
647 & HCDO(IM), HKBO(IM), HMAX(IM), &
648 & HMIN(IM), HSBAR(IM), UCDO(IM), &
649 & UKBO(IM), VCDO(IM), VKBO(IM), &
650 & PBCDIF(IM), PDOT(IM), PO(IM,KM), &
651 & PWAVO(IM), PWEVO(IM), &
652 ! & PSFC(IM), PWAVO(IM), PWEVO(IM), &
653 & QCDO(IM), QCOND(IM), QEVAP(IM), &
654 & QKBO(IM), RNTOT(IM), VSHEAR(IM), &
655 & XAA0(IM), XHCD(IM), XHKB(IM), &
656 & XK(IM), XLAMB(IM), XLAMD(IM), &
657 & XMB(IM), XMBMAX(IM), XPWAV(IM), &
658 & XPWEV(IM), XQCD(IM), XQKB(IM)
660 ! PHYSICAL PARAMETERS
662 PARAMETER(CPOEL=CP/HVAP,ELOCP=HVAP/CP, &
663 & EL2ORC=HVAP*HVAP/(RV*CP))
664 PARAMETER(TERR=0.,C0=.002,DELTA=fv)
665 PARAMETER(FACT1=(CVAP-CLIQ)/RV,FACT2=HVAP/RV-FACT1*T0C)
666 ! LOCAL VARIABLES AND ARRAYS
667 real(kind=kind_phys) PFLD(IM,KM), TO(IM,KM), QO(IM,KM), &
668 & UO(IM,KM), VO(IM,KM), QESO(IM,KM)
670 real(kind=kind_phys) QLKO_KTCON(IM), DELLAL(IM), TVO(IM,KM), &
671 & DBYO(IM,KM), ZO(IM,KM), SUMZ(IM,KM), &
672 & SUMH(IM,KM), HEO(IM,KM), HESO(IM,KM), &
673 & QRCD(IM,KM), DELLAH(IM,KM), DELLAQ(IM,KM),&
674 & DELLAU(IM,KM), DELLAV(IM,KM), HCKO(IM,KM), &
675 & UCKO(IM,KM), VCKO(IM,KM), QCKO(IM,KM), &
676 & ETA(IM,KM), ETAU(IM,KM), ETAD(IM,KM), &
677 & QRCDO(IM,KM), PWO(IM,KM), PWDO(IM,KM), &
680 LOGICAL TOTFLG, CNVFLG(IM), DWNFLG(IM), DWNFLG2(IM), FLG(IM)
682 real(kind=kind_phys) PCRIT(15), ACRITT(15), ACRIT(15)
684 DATA PCRIT/850.,800.,750.,700.,650.,600.,550.,500.,450.,400., &
685 & 350.,300.,250.,200.,150./
686 DATA ACRITT/.0633,.0445,.0553,.0664,.075,.1082,.1521,.2216, &
687 & .3151,.3677,.41,.5255,.7663,1.1686,1.6851/
689 ! DATA ACRITT/.203,.515,.521,.566,.625,.665,.659,.688, &
690 ! & .743,.813,.886,.947,1.138,1.377,1.896/
692 real(kind=kind_phys) TF, TCR, TCRF, RZERO, RONE
693 parameter (TF=233.16, TCR=263.16, TCRF=1.0/(TCR-TF))
694 parameter (RZERO=0.0,RONE=1.0)
695 !-----------------------------------------------------------------------
715 ACRIT(K) = ACRITT(K) * (975. - PCRIT(K))
718 !cmr dtmin = max(dt2,1200.)
720 dtmin = max(dt2, val )
721 !cmr dtmax = max(dt2,3600.)
723 dtmax = max(dt2, val )
724 ! MODEL TUNABLE PARAMETERS ARE ALL HERE
734 ! change for hurricane model
740 ! change for hurricane model
755 fjcap = (float(jcap) / 126.) ** 2
756 !cmr fjcap = max(fjcap,1.)
758 fjcap = max(fjcap,val)
759 fkm = (float(km) / 28.) ** 2
760 !cmr fkm = max(fkm,1.)
770 !CCCC IF(IM.EQ.384) THEN
773 !CCCC ELSEIF(IM.EQ.768) THEN
779 ! DEFINE TOP LAYER FOR SEARCH OF THE DOWNDRAFT ORIGINATING LAYER
780 ! AND THE MAXIMUM THETAE FOR UPDRAFT
791 IF (prSL(I,K)*tx1(I) .GT. 0.45) KBMAX(I) = K + 1
792 IF (prSL(I,K)*tx1(I) .GT. 0.70) KBM(I) = K + 1
793 IF (prSL(I,K)*tx1(I) .GT. 0.04) KMAX(I) = MIN(KM,K + 1)
797 KBMAX(I) = MIN(KBMAX(I),KMAX(I))
798 KBM(I) = MIN(KBM(I),KMAX(I))
801 ! CONVERT SURFACE PRESSURE TO MB FROM CB
806 if (K .le. kmax(i)) then
807 PFLD(I,k) = PRSL(I,K) * 10.0
823 ! P IS PRESSURE OF THE LAYER (MB)
824 ! T IS TEMPERATURE AT T-DT (K)..TN
825 ! Q IS MIXING RATIO AT T-DT (KG/KG)..QN
826 ! TO IS TEMPERATURE AT T+DT (K)... THIS IS AFTER ADVECTION AND TURBULAN
827 ! QO IS MIXING RATIO AT T+DT (KG/KG)..Q1
831 if (k .le. kmax(i)) then
832 !jfe QESO(I,k) = 10. * FPVS(T1(I,k))
834 QESO(I,k) = 0.01 * fpvs(T1(I,K)) ! fpvs is in Pa
836 QESO(I,k) = EPS * QESO(I,k) / (PFLD(I,k) + EPSM1*QESO(I,k))
837 !cmr QESO(I,k) = MAX(QESO(I,k),1.E-8)
839 QESO(I,k) = MAX(QESO(I,k), val1)
840 !cmr QO(I,k) = max(QO(I,k),1.e-10)
842 QO(I,k) = max(QO(I,k), val2 )
843 ! QO(I,k) = MIN(QO(I,k),QESO(I,k))
844 TVO(I,k) = TO(I,k) + DELTA * TO(I,k) * QO(I,k)
850 ! HYDROSTATIC HEIGHT ASSUME ZERO TERR
854 ZO(I,k) = PHIL(I,k) / G
857 ! COMPUTE MOIST STATIC ENERGY
860 if (K .le. kmax(i)) then
861 ! tem = G * ZO(I,k) + CP * TO(I,k)
862 tem = PHIL(I,k) + CP * TO(I,k)
863 HEO(I,k) = tem + HVAP * QO(I,k)
864 HESO(I,k) = tem + HVAP * QESO(I,k)
865 ! HEO(I,k) = MIN(HEO(I,k),HESO(I,k))
870 ! DETERMINE LEVEL WITH LARGEST MOIST STATIC ENERGY
871 ! THIS IS THE LEVEL WHERE UPDRAFT STARTS
880 if (k .le. kbm(i)) then
881 IF(HEO(I,k).GT.HMAX(I).AND.CNVFLG(I)) THEN
889 ! TOL(k) = .5 * (TO(I,k) + TO(I,k+1))
890 ! QOL(k) = .5 * (QO(I,k) + QO(I,k+1))
891 ! QESOL(I,k) = .5 * (QESO(I,k) + QESO(I,k+1))
892 ! HEOL(I,k) = .5 * (HEO(I,k) + HEO(I,k+1))
893 ! HESOL(I,k) = .5 * (HESO(I,k) + HESO(I,k+1))
897 if (k .le. kmax(i)-1) then
898 DZ = .5 * (ZO(I,k+1) - ZO(I,k))
899 DP = .5 * (PFLD(I,k+1) - PFLD(I,k))
900 !jfe ES = 10. * FPVS(TO(I,k+1))
902 ES = 0.01 * fpvs(TO(I,K+1)) ! fpvs is in Pa
904 PPRIME = PFLD(I,k+1) + EPSM1 * ES
905 QS = EPS * ES / PPRIME
906 DQSDP = - QS / PPRIME
907 DESDT = ES * (FACT1 / TO(I,k+1) + FACT2 / (TO(I,k+1)**2))
908 DQSDT = QS * PFLD(I,k+1) * DESDT / (ES * PPRIME)
909 GAMMA = EL2ORC * QESO(I,k+1) / (TO(I,k+1)**2)
910 DT = (G * DZ + HVAP * DQSDP * DP) / (CP * (1. + GAMMA))
911 DQ = DQSDT * DT + DQSDP * DP
912 TO(I,k) = TO(I,k+1) + DT
913 QO(I,k) = QO(I,k+1) + DQ
914 PO(I,k) = .5 * (PFLD(I,k) + PFLD(I,k+1))
921 if (k .le. kmax(I)-1) then
922 !jfe QESO(I,k) = 10. * FPVS(TO(I,k))
924 QESO(I,k) = 0.01 * fpvs(TO(I,K)) ! fpvs is in Pa
926 QESO(I,k) = EPS * QESO(I,k) / (PO(I,k) + EPSM1*QESO(I,k))
927 !cmr QESO(I,k) = MAX(QESO(I,k),1.E-8)
929 QESO(I,k) = MAX(QESO(I,k), val1)
930 !cmr QO(I,k) = max(QO(I,k),1.e-10)
932 QO(I,k) = max(QO(I,k), val2 )
933 ! QO(I,k) = MIN(QO(I,k),QESO(I,k))
934 HEO(I,k) = .5 * G * (ZO(I,k) + ZO(I,k+1)) + &
935 & CP * TO(I,k) + HVAP * QO(I,k)
936 HESO(I,k) = .5 * G * (ZO(I,k) + ZO(I,k+1)) + &
937 & CP * TO(I,k) + HVAP * QESO(I,k)
938 UO(I,k) = .5 * (UO(I,k) + UO(I,k+1))
939 VO(I,k) = .5 * (VO(I,k) + VO(I,k+1))
944 ! HEO(I,k) = HEO(I,k)
945 ! hesol(k) = HESO(I,k)
946 ! IF(LAT.EQ.LATD.AND.lon.eq.lond.and.CNVFLG(I)) THEN
948 ! PRINT 6001, (HEO(I,K),K=1,KMAX)
950 ! PRINT 6001, (HESO(I,K),K=1,KMAX)
952 ! PRINT 6002, (TO(I,K)-273.16,K=1,KMAX)
954 ! PRINT 6003, (QO(I,K),K=1,KMAX)
956 ! PRINT 6003, (QESO(I,K),K=1,KMAX)
959 ! LOOK FOR CONVECTIVE CLOUD BASE AS THE LEVEL OF FREE CONVECTION
964 HKBO(I) = HEO(I,INDX)
975 if (k .le. kbmax(i)) then
976 IF(FLG(I).AND.K.GT.KB(I)) THEN
978 IF(HKBO(I).GT.HSBAR(I)) THEN
988 PBCDIF(I) = -PFLD(I,KBCON(I)) + PFLD(I,KB(I))
989 PDOT(I) = 10.* DOT(I,KBCON(I))
990 IF(PBCDIF(I).GT.150.) CNVFLG(I) = .FALSE.
991 IF(KBCON(I).EQ.KMAX(I)) CNVFLG(I) = .FALSE.
997 TOTFLG = TOTFLG .AND. (.NOT. CNVFLG(I))
1000 ! FOUND LFC, CAN DEFINE REST OF VARIABLES
1001 6001 FORMAT(2X,-2P10F12.2)
1002 6002 FORMAT(2X,10F12.2)
1003 6003 FORMAT(2X,3P10F12.2)
1006 ! DETERMINE ENTRAINMENT RATE BETWEEN KB AND KBCON
1010 if(SLIMSK(I).eq.1.) alpha = alphal
1013 DZ = .5 * (ZO(I,KBCON(I)) + ZO(I,KBCON(I)-1)) - ZO(I,1)
1015 DZ = .5 * (ZO(I,KBCON(I)) + ZO(I,KBCON(I)-1)) &
1016 & - .5 * (ZO(I,KB(I)) + ZO(I,KB(I)-1))
1018 IF(KBCON(I).NE.KB(I)) THEN
1019 !cmr XLAMB(I) = -ALOG(ALPHA) / DZ
1020 XLAMB(I) = - LOG(ALPHA) / DZ
1026 ! DETERMINE UPDRAFT MASS FLUX
1029 if (k .le. kmax(i) .and. CNVFLG(I)) then
1037 if (k .le. kbmax(i)) then
1038 IF(CNVFLG(I).AND.K.LT.KBCON(I).AND.K.GE.KB(I)) THEN
1039 DZ = .5 * (ZO(I,k+1) - ZO(I,k-1))
1040 ETA(I,k) = ETA(I,k+1) * EXP(-XLAMB(I) * DZ)
1041 ETAU(I,k) = ETA(I,k)
1047 IF(CNVFLG(I).AND.KB(I).EQ.1.AND.KBCON(I).GT.1) THEN
1048 DZ = .5 * (ZO(I,2) - ZO(I,1))
1049 ETA(I,1) = ETA(I,2) * EXP(-XLAMB(I) * DZ)
1050 ETAU(I,1) = ETA(I,1)
1054 ! WORK UP UPDRAFT CLOUD PROPERTIES
1059 HCKO(I,INDX) = HKBO(I)
1060 QCKO(I,INDX) = QKBO(I)
1061 UCKO(I,INDX) = UKBO(I)
1062 VCKO(I,INDX) = VKBO(I)
1067 ! CLOUD PROPERTY BELOW CLOUD BASE IS MODIFIED BY THE ENTRAINMENT PROCES
1071 if (k .le. kmax(i)-1) then
1072 IF(CNVFLG(I).AND.K.GT.KB(I).AND.K.LE.KBCON(I)) THEN
1073 FACTOR = ETA(I,k-1) / ETA(I,k)
1075 HCKO(I,k) = FACTOR * HCKO(I,k-1) + ONEMF * &
1076 & .5 * (HEO(I,k) + HEO(I,k+1))
1077 UCKO(I,k) = FACTOR * UCKO(I,k-1) + ONEMF * &
1078 & .5 * (UO(I,k) + UO(I,k+1))
1079 VCKO(I,k) = FACTOR * VCKO(I,k-1) + ONEMF * &
1080 & .5 * (VO(I,k) + VO(I,k+1))
1081 DBYO(I,k) = HCKO(I,k) - HESO(I,k)
1083 IF(CNVFLG(I).AND.K.GT.KBCON(I)) THEN
1084 HCKO(I,k) = HCKO(I,k-1)
1085 UCKO(I,k) = UCKO(I,k-1)
1086 VCKO(I,k) = VCKO(I,k-1)
1087 DBYO(I,k) = HCKO(I,k) - HESO(I,k)
1092 ! DETERMINE CLOUD TOP
1099 ! IF(DBYO(I,kK).GE.0..AND.FLG(I).AND.KK.GT.KBCON(I)) THEN
1106 if (k .le. kmax(i)) then
1107 IF(DBYO(I,k).LT.0..AND.FLG(I).AND.K.GT.KBCON(I)) THEN
1115 IF(CNVFLG(I).AND.(PFLD(I,KBCON(I)) - PFLD(I,KTCON(I))).LT.150.) &
1116 & CNVFLG(I) = .FALSE.
1120 TOTFLG = TOTFLG .AND. (.NOT. CNVFLG(I))
1124 ! SEARCH FOR DOWNDRAFT ORIGINATING LEVEL ABOVE THETA-E MINIMUM
1127 HMIN(I) = HEO(I,KBCON(I))
1132 DO K = KBCON(I), KBMAX(I)
1133 IF(HEO(I,k).LT.HMIN(I).AND.CNVFLG(I)) THEN
1140 ! Make sure that JMIN(I) is within the cloud
1144 JMIN(I) = MIN(LMIN(I),KTCON(I)-1)
1146 JMIN(I) = MAX(JMIN(I),KBCON(I)+1)
1154 if (k .le. kmax(i)-1) then
1155 if(CNVFLG(I).and.k.gt.JMIN(I).and.k.le.KTCON(I)) THEN
1156 SUMZ(I,k) = SUMZ(I,k-1) + .5 * (ZO(I,k+1) - ZO(I,k-1))
1157 SUMH(I,k) = SUMH(I,k-1) + .5 * (ZO(I,k+1) - ZO(I,k-1)) &
1166 ! call random_number(XKT2)
1169 KT2(I) = nint(XKT2(I)*float(KTCON(I)-JMIN(I))-.5)+JMIN(I)+1
1170 ! KT2(I) = nint(sqrt(XKT2(I))*float(KTCON(I)-JMIN(I))-.5) + JMIN(I) + 1
1171 ! KT2(I) = nint(ranf() *float(KTCON(I)-JMIN(I))-.5) + JMIN(I) + 1
1172 tem1 = (HCKO(I,JMIN(I)) - HESO(I,KT2(I)))
1173 tem2 = (SUMZ(I,KT2(I)) * HESO(I,KT2(I)) - SUMH(I,KT2(I)))
1174 if (abs(tem2) .gt. 0.000001) THEN
1175 XLAMB(I) = tem1 / tem2
1179 ! XLAMB(I) = (HCKO(I,JMIN(I)) - HESO(I,KT2(I)))
1180 ! & / (SUMZ(I,KT2(I)) * HESO(I,KT2(I)) - SUMH(I,KT2(I)))
1181 XLAMB(I) = max(XLAMB(I),RZERO)
1182 XLAMB(I) = min(XLAMB(I),2.3/SUMZ(I,KT2(I)))
1187 DWNFLG(I) = CNVFLG(I)
1188 DWNFLG2(I) = CNVFLG(I)
1190 if(KT2(I).ge.KTCON(I)) DWNFLG(I) = .false.
1191 if(XLAMB(I).le.1.e-30.or.HCKO(I,JMIN(I))-HESO(I,KT2(I)).le.1.e-30)&
1192 & DWNFLG(I) = .false.
1193 do k = JMIN(I), KT2(I)
1194 if(DWNFLG(I).and.HEO(I,k).gt.HESO(I,KT2(I))) DWNFLG(I)=.false.
1196 ! IF(CNVFLG(I).AND.(PFLD(KBCON(I))-PFLD(KTCON(I))).GT.PDETRN)
1197 ! & DWNFLG(I)=.FALSE.
1198 IF(CNVFLG(I).AND.(PFLD(I,KBCON(I))-PFLD(I,KTCON(I))).LT.PDPDWN) &
1199 & DWNFLG2(I)=.FALSE.
1205 if (k .le. kmax(i)-1) then
1206 IF(DWNFLG(I).AND.K.GT.JMIN(I).AND.K.LE.KT2(I)) THEN
1207 DZ = .5 * (ZO(I,k+1) - ZO(I,k-1))
1208 ! ETA(I,k) = ETA(I,k-1) * EXP( XLAMB(I) * DZ)
1209 ! to simplify matter, we will take the linear approach here
1211 ETA(I,k) = ETA(I,k-1) * (1. + XLAMB(I) * dz)
1212 ETAU(I,k) = ETAU(I,k-1) * (1. + (XLAMB(I)+xlambu) * dz)
1220 if (k .le. kmax(i)-1) then
1221 ! IF(.NOT.DWNFLG(I).AND.K.GT.JMIN(I).AND.K.LE.KT2(I)) THEN
1222 IF(.NOT.DWNFLG(I).AND.K.GT.JMIN(I).AND.K.LE.KTCON(I)) THEN
1223 DZ = .5 * (ZO(I,k+1) - ZO(I,k-1))
1224 ETAU(I,k) = ETAU(I,k-1) * (1. + xlambu * dz)
1229 ! IF(LAT.EQ.LATD.AND.lon.eq.lond.and.CNVFLG(I)) THEN
1230 ! PRINT *, ' LMIN(I), KT2(I)=', LMIN(I), KT2(I)
1231 ! PRINT *, ' KBOT, KTOP, JMIN(I) =', KBCON(I), KTCON(I), JMIN(I)
1233 ! IF(LAT.EQ.LATD.AND.lon.eq.lond) THEN
1234 ! print *, ' xlamb =', xlamb
1235 ! print *, ' eta =', (eta(k),k=1,KT2(I))
1236 ! print *, ' ETAU =', (ETAU(I,k),k=1,KT2(I))
1237 ! print *, ' HCKO =', (HCKO(I,k),k=1,KT2(I))
1238 ! print *, ' SUMZ =', (SUMZ(I,k),k=1,KT2(I))
1239 ! print *, ' SUMH =', (SUMH(I,k),k=1,KT2(I))
1247 ! CLOUD PROPERTY ABOVE CLOUD Base IS MODIFIED BY THE DETRAINMENT PROCESS
1251 if (k .le. kmax(i)-1) then
1253 IF(CNVFLG(I).AND.K.GT.KBCON(I).AND.K.LE.KTCON(I)) THEN
1254 !jfe IF(K.GT.KBCON(I).AND.K.LE.KTCON(I)) THEN
1255 FACTOR = ETA(I,k-1) / ETA(I,k)
1257 fuv = ETAU(I,k-1) / ETAU(I,k)
1259 HCKO(I,k) = FACTOR * HCKO(I,k-1) + ONEMF * &
1260 & .5 * (HEO(I,k) + HEO(I,k+1))
1261 UCKO(I,k) = fuv * UCKO(I,k-1) + ONEMFu * &
1262 & .5 * (UO(I,k) + UO(I,k+1))
1263 VCKO(I,k) = fuv * VCKO(I,k-1) + ONEMFu * &
1264 & .5 * (VO(I,k) + VO(I,k+1))
1265 DBYO(I,k) = HCKO(I,k) - HESO(I,k)
1270 ! IF(LAT.EQ.LATD.AND.lon.eq.lond.and.CNVFLG(I)) THEN
1271 ! PRINT *, ' UCKO=', (UCKO(I,k),k=KBCON(I)+1,KTCON(I))
1272 ! PRINT *, ' uenv=', (.5*(UO(I,k)+UO(I,k-1)),k=KBCON(I)+1,KTCON(I))
1275 if(CNVFLG(I).and.DWNFLG2(I).and.JMIN(I).le.KBCON(I)) &
1279 DWNFLG2(I) = .false.
1285 TOTFLG = TOTFLG .AND. (.NOT. CNVFLG(I))
1290 ! COMPUTE CLOUD MOISTURE PROPERTY AND PRECIPITATION
1298 if (k .le. kmax(i)) then
1299 IF(CNVFLG(I).AND.K.GT.KB(I).AND.K.LT.KTCON(I)) THEN
1300 DZ = .5 * (ZO(I,k+1) - ZO(I,k-1))
1301 DZ1 = (ZO(I,k) - ZO(I,k-1))
1302 GAMMA = EL2ORC * QESO(I,k) / (TO(I,k)**2)
1304 & + GAMMA * DBYO(I,k) / (HVAP * (1. + GAMMA))
1305 FACTOR = ETA(I,k-1) / ETA(I,k)
1307 QCKO(I,k) = FACTOR * QCKO(I,k-1) + ONEMF * &
1308 & .5 * (QO(I,k) + QO(I,k+1))
1309 DQ = ETA(I,k) * QCKO(I,k) - ETA(I,k) * QRCH
1310 RHBAR(I) = RHBAR(I) + QO(I,k) / QESO(I,k)
1312 ! BELOW LFC CHECK IF THERE IS EXCESS MOISTURE TO RELEASE LATENT HEAT
1315 ETAH = .5 * (ETA(I,k) + ETA(I,k-1))
1316 QLK = DQ / (ETA(I,k) + ETAH * C0 * DZ)
1317 AA1(I) = AA1(I) - DZ1 * G * QLK
1319 PWO(I,k) = ETAH * C0 * DZ * QLK
1321 PWAVO(I) = PWAVO(I) + PWO(I,k)
1328 RHBAR(I) = RHBAR(I) / float(KTCON(I) - KB(I) - 1)
1331 ! this section is ready for cloud water
1333 if(ncloud.gt.0) THEN
1335 ! compute liquid and vapor separation at cloud top
1340 GAMMA = EL2ORC * QESO(I,K) / (TO(I,K)**2)
1342 & + GAMMA * DBYO(I,K) / (HVAP * (1. + GAMMA))
1343 DQ = QCKO(I,K-1) - QRCH
1345 ! CHECK IF THERE IS EXCESS MOISTURE TO RELEASE LATENT HEAT
1355 ! CALCULATE CLOUD WORK FUNCTION AT T+DT
1359 if (k .le. kmax(i)) then
1360 IF(CNVFLG(I).AND.K.GT.KBCON(I).AND.K.LE.KTCON(I)) THEN
1361 DZ1 = ZO(I,k) - ZO(I,k-1)
1362 GAMMA = EL2ORC * QESO(I,k-1) / (TO(I,k-1)**2)
1363 RFACT = 1. + DELTA * CP * GAMMA &
1364 & * TO(I,k-1) / HVAP
1366 & DZ1 * (G / (CP * TO(I,k-1))) &
1367 & * DBYO(I,k-1) / (1. + GAMMA) &
1371 & DZ1 * G * DELTA * &
1372 !cmr & MAX( 0.,(QESO(I,k-1) - QO(I,k-1))) &
1373 & MAX(val,(QESO(I,k-1) - QO(I,k-1)))
1379 IF(CNVFLG(I).AND.AA1(I).LE.0.) DWNFLG(I) = .FALSE.
1380 IF(CNVFLG(I).AND.AA1(I).LE.0.) DWNFLG2(I) = .FALSE.
1381 IF(CNVFLG(I).AND.AA1(I).LE.0.) CNVFLG(I) = .FALSE.
1386 TOTFLG = TOTFLG .AND. (.NOT. CNVFLG(I))
1390 !cccc IF(LAT.EQ.LATD.AND.lon.eq.lond.and.CNVFLG(I)) THEN
1391 !cccc PRINT *, ' AA1(I) BEFORE DWNDRFT =', AA1(I)
1394 !------- DOWNDRAFT CALCULATIONS
1397 !--- DETERMINE DOWNDRAFT STRENGTH IN TERMS OF WINDSHEAR
1406 if (k .le. kmax(i)) then
1407 IF(K.GE.KB(I).AND.K.LE.KTCON(I).AND.CNVFLG(I)) THEN
1408 shear=rcs(I) * sqrt((UO(I,k+1)-UO(I,k)) ** 2 &
1409 & + (VO(I,k+1)-VO(I,k)) ** 2)
1410 VSHEAR(I) = VSHEAR(I) + SHEAR
1418 KNUMB = KTCON(I) - KB(I) + 1
1419 KNUMB = MAX(KNUMB,1)
1420 VSHEAR(I) = 1.E3 * VSHEAR(I) / (ZO(I,KTCON(I))-ZO(I,KB(I)))
1421 E1=1.591-.639*VSHEAR(I) &
1422 & +.0953*(VSHEAR(I)**2)-.00496*(VSHEAR(I)**3)
1424 !cmr EDT(I) = MIN(EDT(I),.9)
1426 EDT(I) = MIN(EDT(I),val)
1427 !cmr EDT(I) = MAX(EDT(I),.0)
1429 EDT(I) = MAX(EDT(I),val)
1434 ! DETERMINE DETRAINMENT RATE BETWEEN 1 AND KBDTR
1438 if(SLIMSK(I).eq.1.) beta = betal
1441 KBDTR(I) = MAX(KBDTR(I),1)
1443 IF(KBDTR(I).GT.1) THEN
1444 DZ = .5 * ZO(I,KBDTR(I)) + .5 * ZO(I,KBDTR(I)-1) &
1446 XLAMD(I) = LOG(BETA) / DZ
1450 ! DETERMINE DOWNDRAFT MASS FLUX
1453 IF(k .le. kmax(i)) then
1463 if (k .le. kbmax(i)) then
1464 IF(CNVFLG(I).AND.K.LT.KBDTR(I)) THEN
1465 DZ = .5 * (ZO(I,k+1) - ZO(I,k-1))
1466 ETAD(I,k) = ETAD(I,k+1) * EXP(XLAMD(I) * DZ)
1473 IF(CNVFLG(I).AND.KBDTR(I).GT.1) THEN
1474 DZ = .5 * (ZO(I,2) - ZO(I,1))
1475 ETAD(I,k) = ETAD(I,k+1) * EXP(XLAMD(I) * DZ)
1479 !--- DOWNDRAFT MOISTURE PROPERTIES
1488 HCDO(I) = HEO(I,JMN)
1490 QRCDO(I,JMN) = QESO(I,JMN)
1497 if (k .le. kmax(i)-1) then
1498 IF(CNVFLG(I).AND.K.LT.JMIN(I)) THEN
1501 GAMMA = EL2ORC * DQ / DT**2
1502 DH = HCDO(I) - HESO(I,k)
1503 QRCDO(I,k) = DQ+(1./HVAP)*(GAMMA/(1.+GAMMA))*DH
1504 DETAD = ETAD(I,k+1) - ETAD(I,k)
1505 PWDO(I,k) = ETAD(I,k+1) * QCDO(I) - &
1506 & ETAD(I,k) * QRCDO(I,k)
1507 PWDO(I,k) = PWDO(I,k) - DETAD * &
1508 & .5 * (QRCDO(I,k) + QRCDO(I,k+1))
1509 QCDO(I) = QRCDO(I,k)
1510 PWEVO(I) = PWEVO(I) + PWDO(I,k)
1515 ! IF(LAT.EQ.LATD.AND.lon.eq.lond.and.DWNFLG(I)) THEN
1516 ! PRINT *, ' PWAVO(I), PWEVO(I) =', PWAVO(I), PWEVO(I)
1519 !--- FINAL DOWNDRAFT STRENGTH DEPENDENT ON PRECIP
1520 !--- EFFICIENCY (EDT), NORMALIZED CONDENSATE (PWAV), AND
1521 !--- EVAPORATE (PWEV)
1525 if(SLIMSK(I).eq.0.) edtmax = edtmaxs
1527 IF(PWEVO(I).LT.0.) THEN
1528 EDTO(I) = -EDTO(I) * PWAVO(I) / PWEVO(I)
1529 EDTO(I) = MIN(EDTO(I),EDTMAX)
1539 !--- DOWNDRAFT CLOUDWORK FUNCTIONS
1544 if (k .le. kmax(i)-1) then
1545 IF(DWNFLG2(I).AND.K.LT.JMIN(I)) THEN
1546 GAMMA = EL2ORC * QESO(I,k+1) / TO(I,k+1)**2
1551 DZ=-1.*(ZO(I,k+1)-ZO(I,k))
1552 AA1(I)=AA1(I)+EDTO(I)*DZ*(G/(CP*DT))*((DHH-DH)/(1.+DG)) &
1553 & *(1.+DELTA*CP*DG*DT/HVAP)
1555 AA1(I)=AA1(I)+EDTO(I)* &
1556 !cmr & DZ*G*DELTA*MAX( 0.,(QESO(I,k+1)-QO(I,k+1))) &
1557 & DZ*G*DELTA*MAX(val,(QESO(I,k+1)-QO(I,k+1)))
1562 !cccc IF(LAT.EQ.LATD.AND.lon.eq.lond.and.DWNFLG2(I)) THEN
1563 !cccc PRINT *, ' AA1(I) AFTER DWNDRFT =', AA1(I)
1566 IF(AA1(I).LE.0.) CNVFLG(I) = .FALSE.
1567 IF(AA1(I).LE.0.) DWNFLG(I) = .FALSE.
1568 IF(AA1(I).LE.0.) DWNFLG2(I) = .FALSE.
1573 TOTFLG = TOTFLG .AND. (.NOT. CNVFLG(I))
1579 !--- WHAT WOULD THE CHANGE BE, THAT A CLOUD WITH UNIT MASS
1580 !--- WILL DO TO THE ENVIRONMENT?
1584 IF(k .le. kmax(i) .and. CNVFLG(I)) THEN
1594 DP = 1000. * DEL(I,1)
1595 DELLAH(I,1) = EDTO(I) * ETAD(I,1) * (HCDO(I) &
1596 & - HEO(I,1)) * G / DP
1597 DELLAQ(I,1) = EDTO(I) * ETAD(I,1) * (QCDO(I) &
1598 & - QO(I,1)) * G / DP
1599 DELLAU(I,1) = EDTO(I) * ETAD(I,1) * (UCDO(I) &
1600 & - UO(I,1)) * G / DP
1601 DELLAV(I,1) = EDTO(I) * ETAD(I,1) * (VCDO(I) &
1602 & - VO(I,1)) * G / DP
1606 !--- CHANGED DUE TO SUBSIDENCE AND ENTRAINMENT
1610 if (k .le. kmax(i)-1) then
1611 IF(CNVFLG(I).AND.K.LT.KTCON(I)) THEN
1613 IF(K.LE.KB(I)) AUP = 0.
1615 IF(K.GT.JMIN(I)) ADW = 0.
1617 DV2 = .5 * (HEO(I,k) + HEO(I,k+1))
1620 DV2Q = .5 * (QO(I,k) + QO(I,k+1))
1623 DV2U = .5 * (UO(I,k) + UO(I,k+1))
1626 DV2V = .5 * (VO(I,k) + VO(I,k+1))
1628 DP = 1000. * DEL(I,K)
1629 DZ = .5 * (ZO(I,k+1) - ZO(I,k-1))
1630 DETA = ETA(I,k) - ETA(I,k-1)
1631 DETAD = ETAD(I,k) - ETAD(I,k-1)
1632 DELLAH(I,k) = DELLAH(I,k) + &
1633 & ((AUP * ETA(I,k) - ADW * EDTO(I) * ETAD(I,k)) * DV1 &
1634 & - (AUP * ETA(I,k-1) - ADW * EDTO(I) * ETAD(I,k-1))* DV3 &
1635 & - AUP * DETA * DV2 &
1636 & + ADW * EDTO(I) * DETAD * HCDO(I)) * G / DP
1637 DELLAQ(I,k) = DELLAQ(I,k) + &
1638 & ((AUP * ETA(I,k) - ADW * EDTO(I) * ETAD(I,k)) * DV1Q &
1639 & - (AUP * ETA(I,k-1) - ADW * EDTO(I) * ETAD(I,k-1))* DV3Q &
1640 & - AUP * DETA * DV2Q &
1641 & +ADW*EDTO(I)*DETAD*.5*(QRCDO(I,k)+QRCDO(I,k-1))) * G / DP
1642 DELLAU(I,k) = DELLAU(I,k) + &
1643 & ((AUP * ETA(I,k) - ADW * EDTO(I) * ETAD(I,k)) * DV1U &
1644 & - (AUP * ETA(I,k-1) - ADW * EDTO(I) * ETAD(I,k-1))* DV3U &
1645 & - AUP * DETA * DV2U &
1646 & + ADW * EDTO(I) * DETAD * UCDO(I) &
1648 DELLAV(I,k) = DELLAV(I,k) + &
1649 & ((AUP * ETA(I,k) - ADW * EDTO(I) * ETAD(I,k)) * DV1V &
1650 & - (AUP * ETA(I,k-1) - ADW * EDTO(I) * ETAD(I,k-1))* DV3V &
1651 & - AUP * DETA * DV2V &
1652 & + ADW * EDTO(I) * DETAD * VCDO(I) &
1664 DP = 1000. * DEL(I,INDX)
1666 DELLAH(I,INDX) = ETA(I,INDX-1) * &
1667 & (HCKO(I,INDX-1) - DV1) * G / DP
1669 DELLAQ(I,INDX) = ETA(I,INDX-1) * &
1670 & (QCKO(I,INDX-1) - DVQ1) * G / DP
1672 DELLAU(I,INDX) = ETA(I,INDX-1) * &
1673 & (UCKO(I,INDX-1) - DV1U) * G / DP
1675 DELLAV(I,INDX) = ETA(I,INDX-1) * &
1676 & (VCKO(I,INDX-1) - DV1V) * G / DP
1680 DELLAL(I) = ETA(I,INDX-1) * QLKO_KTCON(I) * g / dp
1684 !------- FINAL CHANGED VARIABLE PER UNIT MASS FLUX
1688 if (k .le. kmax(i)) then
1689 IF(CNVFLG(I).and.k.gt.KTCON(I)) THEN
1695 IF(CNVFLG(I).AND.K.LE.KTCON(I)) THEN
1696 QO(I,k) = DELLAQ(I,k) * MBDT + Q1(I,k)
1697 DELLAT = (DELLAH(I,k) - HVAP * DELLAQ(I,k)) / CP
1698 TO(I,k) = DELLAT * MBDT + T1(I,k)
1699 !cmr QO(I,k) = max(QO(I,k),1.e-10)
1701 QO(I,k) = max(QO(I,k), val )
1706 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1708 !--- THE ABOVE CHANGED ENVIRONMENT IS NOW USED TO CALULATE THE
1709 !--- EFFECT THE ARBITRARY CLOUD (WITH UNIT MASS FLUX)
1710 !--- WOULD HAVE ON THE STABILITY,
1711 !--- WHICH THEN IS USED TO CALCULATE THE REAL MASS FLUX,
1712 !--- NECESSARY TO KEEP THIS CHANGE IN BALANCE WITH THE LARGE-SCALE
1713 !--- DESTABILIZATION.
1715 !--- ENVIRONMENTAL CONDITIONS AGAIN, FIRST HEIGHTS
1719 IF(k .le. kmax(i) .and. CNVFLG(I)) THEN
1720 !jfe QESO(I,k) = 10. * FPVS(TO(I,k))
1722 QESO(I,k) = 0.01 * fpvs(TO(I,K)) ! fpvs is in Pa
1724 QESO(I,k) = EPS * QESO(I,k) / (PFLD(I,k)+EPSM1*QESO(I,k))
1725 !cmr QESO(I,k) = MAX(QESO(I,k),1.E-8)
1727 QESO(I,k) = MAX(QESO(I,k), val )
1728 TVO(I,k) = TO(I,k) + DELTA * TO(I,k) * QO(I,k)
1739 ! HYDROSTATIC HEIGHT ASSUME ZERO TERR
1742 ! IF(CNVFLG(I)) THEN
1743 ! DLNSIG = LOG(PRSL(I,1)/PS(I))
1744 ! ZO(I,1) = TERR - DLNSIG * RD / G * TVO(I,1)
1749 ! IF(k .le. kmax(i) .and. CNVFLG(I)) THEN
1750 ! DLNSIG = LOG(PRSL(I,K) / PRSL(I,K-1))
1751 ! ZO(I,k) = ZO(I,k-1) - DLNSIG * RD / G
1752 ! & * .5 * (TVO(I,k) + TVO(I,k-1))
1757 !--- MOIST STATIC ENERGY
1761 IF(k .le. kmax(i)-1 .and. CNVFLG(I)) THEN
1762 DZ = .5 * (ZO(I,k+1) - ZO(I,k))
1763 DP = .5 * (PFLD(I,k+1) - PFLD(I,k))
1764 !jfe ES = 10. * FPVS(TO(I,k+1))
1766 ES = 0.01 * fpvs(TO(I,K+1)) ! fpvs is in Pa
1768 PPRIME = PFLD(I,k+1) + EPSM1 * ES
1769 QS = EPS * ES / PPRIME
1770 DQSDP = - QS / PPRIME
1771 DESDT = ES * (FACT1 / TO(I,k+1) + FACT2 / (TO(I,k+1)**2))
1772 DQSDT = QS * PFLD(I,k+1) * DESDT / (ES * PPRIME)
1773 GAMMA = EL2ORC * QESO(I,k+1) / (TO(I,k+1)**2)
1774 DT = (G * DZ + HVAP * DQSDP * DP) / (CP * (1. + GAMMA))
1775 DQ = DQSDT * DT + DQSDP * DP
1776 TO(I,k) = TO(I,k+1) + DT
1777 QO(I,k) = QO(I,k+1) + DQ
1778 PO(I,k) = .5 * (PFLD(I,k) + PFLD(I,k+1))
1784 IF(k .le. kmax(i)-1 .and. CNVFLG(I)) THEN
1785 !jfe QESO(I,k) = 10. * FPVS(TO(I,k))
1787 QESO(I,k) = 0.01 * fpvs(TO(I,K)) ! fpvs is in Pa
1789 QESO(I,k) = EPS * QESO(I,k) / (PO(I,k) + EPSM1 * QESO(I,k))
1790 !cmr QESO(I,k) = MAX(QESO(I,k),1.E-8)
1792 QESO(I,k) = MAX(QESO(I,k), val1)
1793 !cmr QO(I,k) = max(QO(I,k),1.e-10)
1795 QO(I,k) = max(QO(I,k), val2 )
1796 ! QO(I,k) = MIN(QO(I,k),QESO(I,k))
1797 HEO(I,k) = .5 * G * (ZO(I,k) + ZO(I,k+1)) + &
1798 & CP * TO(I,k) + HVAP * QO(I,k)
1799 HESO(I,k) = .5 * G * (ZO(I,k) + ZO(I,k+1)) + &
1800 & CP * TO(I,k) + HVAP * QESO(I,k)
1807 HEO(I,k) = G * ZO(I,k) + CP * TO(I,k) + HVAP * QO(I,k)
1808 HESO(I,k) = G * ZO(I,k) + CP * TO(I,k) + HVAP * QESO(I,k)
1809 ! HEO(I,k) = MIN(HEO(I,k),HESO(I,k))
1815 XHKB(I) = HEO(I,INDX)
1816 XQKB(I) = QO(I,INDX)
1817 HCKO(I,INDX) = XHKB(I)
1818 QCKO(I,INDX) = XQKB(I)
1823 !**************************** STATIC CONTROL
1826 !------- MOISTURE AND CLOUD WORK FUNCTIONS
1830 if (k .le. kmax(i)-1) then
1831 ! IF(CNVFLG(I).AND.K.GT.KB(I).AND.K.LE.KBCON(I)) THEN
1832 IF(CNVFLG(I).AND.K.GT.KB(I).AND.K.LE.KTCON(I)) THEN
1833 FACTOR = ETA(I,k-1) / ETA(I,k)
1835 HCKO(I,k) = FACTOR * HCKO(I,k-1) + ONEMF * &
1836 & .5 * (HEO(I,k) + HEO(I,k+1))
1838 ! IF(CNVFLG(I).AND.K.GT.KBCON(I)) THEN
1839 ! HEO(I,k) = HEO(I,k-1)
1846 if (k .le. kmax(i)-1) then
1847 IF(CNVFLG(I).AND.K.GT.KB(I).AND.K.LT.KTCON(I)) THEN
1848 DZ = .5 * (ZO(I,k+1) - ZO(I,k-1))
1849 GAMMA = EL2ORC * QESO(I,k) / (TO(I,k)**2)
1850 XDBY = HCKO(I,k) - HESO(I,k)
1851 !cmr XDBY = MAX(XDBY,0.)
1853 XDBY = MAX(XDBY,val)
1855 & + GAMMA * XDBY / (HVAP * (1. + GAMMA))
1856 FACTOR = ETA(I,k-1) / ETA(I,k)
1858 QCKO(I,k) = FACTOR * QCKO(I,k-1) + ONEMF * &
1859 & .5 * (QO(I,k) + QO(I,k+1))
1860 DQ = ETA(I,k) * QCKO(I,k) - ETA(I,k) * XQRCH
1862 ETAH = .5 * (ETA(I,k) + ETA(I,k-1))
1863 QLK = DQ / (ETA(I,k) + ETAH * C0 * DZ)
1864 XAA0(I) = XAA0(I) - (ZO(I,k) - ZO(I,k-1)) * G * QLK
1866 XPW = ETAH * C0 * DZ * QLK
1868 XPWAV(I) = XPWAV(I) + XPW
1871 ! IF(CNVFLG(I).AND.K.GT.KBCON(I).AND.K.LT.KTCON(I)) THEN
1872 IF(CNVFLG(I).AND.K.GT.KBCON(I).AND.K.LE.KTCON(I)) THEN
1873 DZ1 = ZO(I,k) - ZO(I,k-1)
1874 GAMMA = EL2ORC * QESO(I,k-1) / (TO(I,k-1)**2)
1875 RFACT = 1. + DELTA * CP * GAMMA &
1876 & * TO(I,k-1) / HVAP
1877 XDBY = HCKO(I,k-1) - HESO(I,k-1)
1879 & + DZ1 * (G / (CP * TO(I,k-1))) &
1880 & * XDBY / (1. + GAMMA) &
1884 & DZ1 * G * DELTA * &
1885 !cmr & MAX( 0.,(QESO(I,k-1) - QO(I,k-1))) &
1886 & MAX(val,(QESO(I,k-1) - QO(I,k-1)))
1891 !cccc IF(LAT.EQ.LATD.AND.lon.eq.lond.and.CNVFLG(I)) THEN
1892 !cccc PRINT *, ' XAA BEFORE DWNDRFT =', XAA0(I)
1895 !------- DOWNDRAFT CALCULATIONS
1898 !--- DOWNDRAFT MOISTURE PROPERTIES
1906 XHCD(I) = HEO(I,JMN)
1908 QRCD(I,JMN) = QESO(I,JMN)
1913 if (k .le. kmax(i)-1) then
1914 IF(DWNFLG2(I).AND.K.LT.JMIN(I)) THEN
1917 GAMMA = EL2ORC * DQ / DT**2
1918 DH = XHCD(I) - HESO(I,k)
1919 QRCD(I,k)=DQ+(1./HVAP)*(GAMMA/(1.+GAMMA))*DH
1920 DETAD = ETAD(I,k+1) - ETAD(I,k)
1921 XPWD = ETAD(I,k+1) * QRCD(I,k+1) - &
1922 & ETAD(I,k) * QRCD(I,k)
1923 XPWD = XPWD - DETAD * &
1924 & .5 * (QRCD(I,k) + QRCD(I,k+1))
1925 XPWEV(I) = XPWEV(I) + XPWD
1933 if(SLIMSK(I).eq.0.) edtmax = edtmaxs
1935 IF(XPWEV(I).GE.0.) THEN
1938 EDTX(I) = -EDTX(I) * XPWAV(I) / XPWEV(I)
1939 EDTX(I) = MIN(EDTX(I),EDTMAX)
1948 !--- DOWNDRAFT CLOUDWORK FUNCTIONS
1953 if (k .le. kmax(i)-1) then
1954 IF(DWNFLG2(I).AND.K.LT.JMIN(I)) THEN
1955 GAMMA = EL2ORC * QESO(I,k+1) / TO(I,k+1)**2
1960 DZ=-1.*(ZO(I,k+1)-ZO(I,k))
1961 XAA0(I)=XAA0(I)+EDTX(I)*DZ*(G/(CP*DT))*((DHH-DH)/(1.+DG)) &
1962 & *(1.+DELTA*CP*DG*DT/HVAP)
1964 XAA0(I)=XAA0(I)+EDTX(I)* &
1965 !cmr & DZ*G*DELTA*MAX( 0.,(QESO(I,k+1)-QO(I,k+1))) &
1966 & DZ*G*DELTA*MAX(val,(QESO(I,k+1)-QO(I,k+1)))
1971 !cccc IF(LAT.EQ.LATD.AND.lon.eq.lond.and.DWNFLG2(I)) THEN
1972 !cccc PRINT *, ' XAA AFTER DWNDRFT =', XAA0(I)
1975 ! CALCULATE CRITICAL CLOUD WORK FUNCTION
1980 ! IF(CNVFLG(I).AND.SLIMSK(I).NE.1.) THEN
1981 IF(PFLD(I,KTCON(I)).LT.PCRIT(15))THEN
1982 ACRT(I)=ACRIT(15)*(975.-PFLD(I,KTCON(I))) &
1984 ELSE IF(PFLD(I,KTCON(I)).GT.PCRIT(1))THEN
1987 !cmr K = IFIX((850. - PFLD(I,KTCON(I)))/50.) + 2
1988 K = int((850. - PFLD(I,KTCON(I)))/50.) + 2
1991 ACRT(I)=ACRIT(K)+(ACRIT(K-1)-ACRIT(K))* &
1992 & (PFLD(I,KTCON(I))-PCRIT(K))/(PCRIT(K-1)-PCRIT(K))
1995 ! ACRT(I) = .5 * (PFLD(I,KBCON(I)) - PFLD(I,KTCON(I)))
2001 if(SLIMSK(I).eq.1.) THEN
2012 !C IF(CNVFLG(I).AND.SLIMSK(I).EQ.1.) THEN
2013 ! ACRTFCT(I) = PDOT(I) / W3
2015 ! modify critical cloud workfunction by cloud base vertical velocity
2017 IF(PDOT(I).LE.W4) THEN
2018 ACRTFCT(I) = (PDOT(I) - W4) / (W3 - W4)
2019 ELSEIF(PDOT(I).GE.-W4) THEN
2020 ACRTFCT(I) = - (PDOT(I) + W4) / (W4 - W3)
2024 !cmr ACRTFCT(I) = MAX(ACRTFCT(I),-1.)
2026 ACRTFCT(I) = MAX(ACRTFCT(I),val1)
2027 !cmr ACRTFCT(I) = MIN(ACRTFCT(I),1.)
2029 ACRTFCT(I) = MIN(ACRTFCT(I),val2)
2030 ACRTFCT(I) = 1. - ACRTFCT(I)
2032 ! modify ACRTFCT(I) by colume mean rh if RHBAR(I) is greater than 80 percent
2034 ! if(RHBAR(I).ge..8) THEN
2035 ! ACRTFCT(I) = ACRTFCT(I) * (.9 - min(RHBAR(I),.9)) * 10.
2038 ! modify adjustment time scale by cloud base vertical velocity
2040 DTCONV(I) = DT2 + max((1800. - DT2),RZERO) * &
2041 & (PDOT(I) - W2) / (W1 - W2)
2042 ! DTCONV(I) = MAX(DTCONV(I), DT2)
2043 ! DTCONV(I) = 1800. * (PDOT(I) - w2) / (w1 - w2)
2044 DTCONV(I) = max(DTCONV(I),dtmin)
2045 DTCONV(I) = min(DTCONV(I),dtmax)
2050 !--- LARGE SCALE FORCING
2055 ! F = AA1(I) / DTCONV(I)
2056 FLD(I) = (AA1(I) - ACRT(I) * ACRTFCT(I)) / DTCONV(I)
2057 IF(FLD(I).LE.0.) FLG(I) = .FALSE.
2061 ! XAA0(I) = MAX(XAA0(I),0.)
2062 XK(I) = (XAA0(I) - AA1(I)) / MBDT
2063 IF(XK(I).GE.0.) FLG(I) = .FALSE.
2066 !--- KERNEL, CLOUD BASE MASS FLUX
2070 XMB(I) = -FLD(I) / XK(I)
2071 XMB(I) = MIN(XMB(I),XMBMAX(I))
2074 ! IF(LAT.EQ.LATD.AND.lon.eq.lond.and.CNVFLG(I)) THEN
2075 ! print *, ' RHBAR(I), ACRTFCT(I) =', RHBAR(I), ACRTFCT(I)
2076 ! PRINT *, ' A1, XA =', AA1(I), XAA0(I)
2077 ! PRINT *, ' XMB(I), ACRT =', XMB(I), ACRT
2081 TOTFLG = TOTFLG .AND. (.NOT. CNVFLG(I))
2085 ! restore t0 and QO to t1 and q1 in case convection stops
2089 if (k .le. kmax(i)) then
2092 !jfe QESO(I,k) = 10. * FPVS(T1(I,k))
2094 QESO(I,k) = 0.01 * fpvs(T1(I,K)) ! fpvs is in Pa
2096 QESO(I,k) = EPS * QESO(I,k) / (PFLD(I,k) + EPSM1*QESO(I,k))
2097 !cmr QESO(I,k) = MAX(QESO(I,k),1.E-8)
2099 QESO(I,k) = MAX(QESO(I,k), val )
2103 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2105 !--- FEEDBACK: SIMPLY THE CHANGES FROM THE CLOUD WITH UNIT MASS FLUX
2106 !--- MULTIPLIED BY THE MASS FLUX NECESSARY TO KEEP THE
2107 !--- EQUILIBRIUM WITH THE LARGER-SCALE.
2117 if (k .le. kmax(i)) then
2118 IF(CNVFLG(I).AND.K.LE.KTCON(I)) THEN
2120 IF(K.Le.KB(I)) AUP = 0.
2122 IF(K.GT.JMIN(I)) ADW = 0.
2123 DELLAT = (DELLAH(I,k) - HVAP * DELLAQ(I,k)) / CP
2124 T1(I,k) = T1(I,k) + DELLAT * XMB(I) * DT2
2125 Q1(I,k) = Q1(I,k) + DELLAQ(I,k) * XMB(I) * DT2
2126 U1(I,k) = U1(I,k) + DELLAU(I,k) * XMB(I) * DT2
2127 V1(I,k) = V1(I,k) + DELLAV(I,k) * XMB(I) * DT2
2128 DP = 1000. * DEL(I,K)
2129 DELHBAR(I) = DELHBAR(I) + DELLAH(I,k)*XMB(I)*DP/G
2130 DELQBAR(I) = DELQBAR(I) + DELLAQ(I,k)*XMB(I)*DP/G
2131 DELTBAR(I) = DELTBAR(I) + DELLAT*XMB(I)*DP/G
2138 if (k .le. kmax(i)) then
2139 IF(CNVFLG(I).AND.K.LE.KTCON(I)) THEN
2140 !jfe QESO(I,k) = 10. * FPVS(T1(I,k))
2142 QESO(I,k) = 0.01 * fpvs(T1(I,K)) ! fpvs is in Pa
2144 QESO(I,k) = EPS * QESO(I,k)/(PFLD(I,k) + EPSM1*QESO(I,k))
2145 !cmr QESO(I,k) = MAX(QESO(I,k),1.E-8)
2147 QESO(I,k) = MAX(QESO(I,k), val )
2151 if(ncloud.gt.0.and.CNVFLG(I).and.k.eq.KTCON(I)) THEN
2152 tem = DELLAL(I) * XMB(I) * dt2
2153 tem1 = MAX(RZERO, MIN(RONE, (TCR-t1(I,K))*TCRF))
2154 if (QL(I,k,2) .gt. -999.0) then
2155 QL(I,k,1) = QL(I,k,1) + tem * tem1 ! Ice
2156 QL(I,k,2) = QL(I,k,2) + tem *(1.0-tem1) ! Water
2158 tem2 = QL(I,k,1) + tem
2159 QL(I,k,1) = tem2 * tem1 ! Ice
2160 QL(I,k,2) = tem2 - QL(I,k,1) ! Water
2162 ! QL(I,k) = QL(I,k) + DELLAL(I) * XMB(I) * dt2
2163 dp = 1000. * del(i,k)
2164 DELLAL(I) = DELLAL(I) * XMB(I) * dp / g
2170 ! IF(LAT.EQ.LATD.AND.lon.eq.lond.and.CNVFLG(I) ) THEN
2171 ! PRINT *, ' DELHBAR, DELQBAR, DELTBAR ='
2172 ! PRINT *, DELHBAR, HVAP*DELQBAR, CP*DELTBAR
2173 ! PRINT *, ' DELLBAR ='
2174 ! PRINT 6003, HVAP*DELLbar
2175 ! PRINT *, ' DELLAQ ='
2176 ! PRINT 6003, (HVAP*DELLAQ(I,k)*XMB(I),K=1,KMAX)
2177 ! PRINT *, ' DELLAT ='
2178 ! PRINT 6003, (DELLAH(i,k)*XMB(I)-HVAP*DELLAQ(I,k)*XMB(I), &
2189 if (k .le. kmax(i)) then
2190 IF(CNVFLG(I).AND.K.LE.KTCON(I)) THEN
2192 IF(K.Le.KB(I)) AUP = 0.
2194 IF(K.GT.JMIN(I)) ADW = 0.
2195 rain = AUP * PWO(I,k) + ADW * EDTO(I) * PWDO(I,k)
2196 RNTOT(I) = RNTOT(I) + rain * XMB(I) * .001 * dt2
2203 if (k .le. kmax(i)) then
2207 IF(CNVFLG(I).AND.K.LE.KTCON(I)) THEN
2209 IF(K.Le.KB(I)) AUP = 0.
2211 IF(K.GT.JMIN(I)) ADW = 0.
2212 rain = AUP * PWO(I,k) + ADW * EDTO(I) * PWDO(I,k)
2213 RN(I) = RN(I) + rain * XMB(I) * .001 * dt2
2215 IF(FLG(I).AND.K.LE.KTCON(I)) THEN
2216 evef = EDT(I) * evfact
2217 if(SLIMSK(I).eq.1.) evef=EDT(I) * evfactl
2218 ! if(SLIMSK(I).eq.1.) evef=.07
2219 ! if(SLIMSK(I).ne.1.) evef = 0.
2220 QCOND(I) = EVEF * (Q1(I,k) - QESO(I,k)) &
2221 & / (1. + EL2ORC * QESO(I,k) / T1(I,k)**2)
2222 DP = 1000. * DEL(I,K)
2223 IF(RN(I).GT.0..AND.QCOND(I).LT.0.) THEN
2224 QEVAP(I) = -QCOND(I) * (1.-EXP(-.32*SQRT(DT2*RN(I))))
2225 QEVAP(I) = MIN(QEVAP(I), RN(I)*1000.*G/DP)
2226 DELQ2(I) = DELQEV(I) + .001 * QEVAP(I) * dp / g
2228 if(RN(I).gt.0..and.QCOND(I).LT.0..and. &
2229 & DELQ2(I).gt.RNTOT(I)) THEN
2230 QEVAP(I) = 1000.* g * (RNTOT(I) - DELQEV(I)) / dp
2233 IF(RN(I).GT.0..AND.QEVAP(I).gt.0.) THEN
2234 Q1(I,k) = Q1(I,k) + QEVAP(I)
2235 T1(I,k) = T1(I,k) - ELOCP * QEVAP(I)
2236 RN(I) = RN(I) - .001 * QEVAP(I) * DP / G
2237 DELTV(I) = - ELOCP*QEVAP(I)/DT2
2238 DELQ(I) = + QEVAP(I)/DT2
2239 DELQEV(I) = DELQEV(I) + .001*dp*QEVAP(I)/g
2241 DELLAQ(I,k) = DELLAQ(I,k) + DELQ(I) / XMB(I)
2242 DELQBAR(I) = DELQBAR(I) + DELQ(I)*DP/G
2243 DELTBAR(I) = DELTBAR(I) + DELTV(I)*DP/G
2248 ! IF(LAT.EQ.LATD.AND.lon.eq.lond.and.CNVFLG(I) ) THEN
2249 ! PRINT *, ' DELLAH ='
2250 ! PRINT 6003, (DELLAH(k)*XMB(I),K=1,KMAX)
2251 ! PRINT *, ' DELLAQ ='
2252 ! PRINT 6003, (HVAP*DELLAQ(I,k)*XMB(I),K=1,KMAX)
2253 ! PRINT *, ' DELHBAR, DELQBAR, DELTBAR ='
2254 ! PRINT *, DELHBAR, HVAP*DELQBAR, CP*DELTBAR
2255 ! PRINT *, ' PRECIP =', HVAP*RN(I)*1000./DT2
2256 !CCCC PRINT *, ' DELLBAR ='
2257 !CCCC PRINT *, HVAP*DELLbar
2260 ! PRECIPITATION RATE CONVERTED TO ACTUAL PRECIP
2261 ! IN UNIT OF M INSTEAD OF KG
2266 ! IN THE EVENT OF UPPER LEVEL RAIN EVAPORATION AND LOWER LEVEL DOWNDRAF
2267 ! MOISTENING, RN CAN BECOME NEGATIVE, IN THIS CASE, WE BACK OUT OF TH
2268 ! HEATING AND THE MOISTENING
2270 if(RN(I).lt.0..and..not.FLG(I)) RN(I) = 0.
2271 IF(RN(I).LE.0.) THEN
2283 if (k .le. kmax(i)) then
2284 IF(CNVFLG(I).AND.RN(I).LE.0.) THEN
2293 END SUBROUTINE SASCNV
2295 ! ------------------------------------------------------------------------
2297 SUBROUTINE OLD_ARW_SHALCV(IM,IX,KM,DT,DEL,PRSI,PRSL,PRSLK,KUO,Q,T,DPSHC)
2299 USE MODULE_GFS_MACHINE , ONLY : kind_phys
2300 USE MODULE_GFS_PHYSCONS, grav => con_g, CP => con_CP, HVAP => con_HVAP &
2305 ! include 'constant.h'
2307 integer IM, IX, KM, KUO(IM)
2308 real(kind=kind_phys) DEL(IX,KM), PRSI(IX,KM+1), PRSL(IX,KM), &
2310 & Q(IX,KM), T(IX,KM), DT, DPSHC
2314 real(kind=kind_phys) ck, cpdt, dmse, dsdz1, dsdz2, &
2315 & dsig, dtodsl, dtodsu, eldq, g, &
2318 integer k,k1,k2,kliftl,kliftu,kt,N2,I,iku,ik1,ik,ii
2319 integer INDEX2(IM), KLCL(IM), KBOT(IM), KTOP(IM),kk &
2322 ! PHYSICAL PARAMETERS
2323 PARAMETER(G=GRAV, GOCP=G/CP)
2324 ! BOUNDS OF PARCEL ORIGIN
2325 PARAMETER(KLIFTL=2,KLIFTU=2)
2327 real(kind=kind_phys) Q2(IM*KM), T2(IM*KM), &
2328 & PRSL2(IM*KM), PRSLK2(IM*KM), &
2329 & AL(IM*(KM-1)), AD(IM*KM), AU(IM*(KM-1))
2330 !-----------------------------------------------------------------------
2331 ! COMPRESS FIELDS TO POINTS WITH NO DEEP CONVECTION
2332 ! AND MOIST STATIC INSTABILITY.
2338 IF(KUO(I).EQ.0) THEN
2339 ELDQ = HVAP*(Q(I,K)-Q(I,K+1))
2340 CPDT = CP*(T(I,K)-T(I,K+1))
2341 RTDLS = (PRSL(I,K)-PRSL(I,K+1)) / &
2342 & PRSI(I,K+1)*RD*0.5*(T(I,K)+T(I,K+1))
2343 DMSE = ELDQ+CPDT-RTDLS
2344 LSHC(I) = LSHC(I).OR.DMSE.GT.0.
2363 PRSL2(IK) = PRSL(II,K)
2364 PRSLK2(IK) = PRSLK(II,K)
2373 if (prsi(ii,1)-prsi(ii,k) .le. dpshc) ktopm(i) = k
2377 !-----------------------------------------------------------------------
2378 ! COMPUTE MOIST ADIABAT AND DETERMINE LIMITS OF SHALLOW CONVECTION.
2379 ! CHECK FOR MOIST STATIC INSTABILITY AGAIN WITHIN CLOUD.
2380 CALL MSTADBT3(N2,KM-1,KLIFTL,KLIFTU,PRSL2,PRSLK2,T2,Q2, &
2381 & KLCL,KBOT,KTOP,AL,AU)
2383 KBOT(I) = min(KLCL(I)-1, ktopm(i)-1)
2384 KTOP(I) = min(KTOP(I)+1, ktopm(i))
2390 IF(K.GE.KBOT(I).AND.K.LT.KTOP(I)) THEN
2393 ELDQ = HVAP * (Q2(IK)-Q2(IKU))
2394 CPDT = CP * (T2(IK)-T2(IKU))
2395 RTDLS = (PRSL2(IK)-PRSL2(IKU)) / &
2396 & PRSI(index2(i),K+1)*RD*0.5*(T2(IK)+T2(IKU))
2397 DMSE = ELDQ + CPDT - RTDLS
2398 LSHC(I) = LSHC(I).OR.DMSE.GT.0.
2406 IF(.NOT.LSHC(I)) THEN
2410 K1 = MIN(K1,KBOT(I))
2411 K2 = MAX(K2,KTOP(I))
2415 !-----------------------------------------------------------------------
2416 ! SET EDDY VISCOSITY COEFFICIENT CKU AT SIGMA INTERFACES.
2417 ! COMPUTE DIAGONALS AND RHS FOR TRIDIAGONAL MATRIX SOLVER.
2418 ! EXPAND FINAL FIELDS.
2428 ! DTODSU= DT/DEL(K+1)
2429 ! DSIG=SL(K)-SL(K+1)
2433 DTODSL = DT/DEL(II,K)
2434 DTODSU = DT/DEL(II,K+1)
2435 DSIG = PRSL(II,K) - PRSL(II,K+1)
2438 IF(K.EQ.KBOT(I)) THEN
2440 ELSEIF(K.EQ.KTOP(I)-1) THEN
2442 ELSEIF(K.EQ.KTOP(I)-2) THEN
2444 ELSEIF(K.GT.KBOT(I).AND.K.LT.KTOP(I)-2) THEN
2449 DSDZ1 = CK*DSIG*AU(IK)*GOCP
2450 DSDZ2 = CK*DSIG*AU(IK)*AU(IK)
2451 AU(IK) = -DTODSL*DSDZ2
2452 AL(IK) = -DTODSU*DSDZ2
2453 AD(IK) = AD(IK)-AU(IK)
2455 T2(IK) = T2(IK)+DTODSL*DSDZ1
2456 T2(IKU) = T2(IKU)-DTODSU*DSDZ1
2460 CALL TRIDI2T3(N2,KT,AL(IK1),AD(IK1),AU(IK1),Q2(IK1),T2(IK1), &
2461 & AU(IK1),Q2(IK1),T2(IK1))
2466 Q(INDEX2(I),K) = Q2(IK)
2467 T(INDEX2(I),K) = T2(IK)
2470 !-----------------------------------------------------------------------
2472 END SUBROUTINE OLD_ARW_SHALCV
2474 !-----------------------------------------------------------------------
2475 SUBROUTINE TRIDI2T3(L,N,CL,CM,CU,R1,R2,AU,A1,A2)
2476 !yt INCLUDE DBTRIDI2;
2478 USE MODULE_GFS_MACHINE , ONLY : kind_phys
2481 real(kind=kind_phys) fk
2483 real(kind=kind_phys) &
2484 & CL(L,2:N),CM(L,N),CU(L,N-1),R1(L,N),R2(L,N), &
2485 & AU(L,N-1),A1(L,N),A2(L,N)
2486 !-----------------------------------------------------------------------
2495 FK=1./(CM(I,K)-CL(I,K)*AU(I,K-1))
2497 A1(I,K)=FK*(R1(I,K)-CL(I,K)*A1(I,K-1))
2498 A2(I,K)=FK*(R2(I,K)-CL(I,K)*A2(I,K-1))
2502 FK=1./(CM(I,N)-CL(I,N)*AU(I,N-1))
2503 A1(I,N)=FK*(R1(I,N)-CL(I,N)*A1(I,N-1))
2504 A2(I,N)=FK*(R2(I,N)-CL(I,N)*A2(I,N-1))
2508 A1(I,K)=A1(I,K)-AU(I,K)*A1(I,K+1)
2509 A2(I,K)=A2(I,K)-AU(I,K)*A2(I,K+1)
2512 !-----------------------------------------------------------------------
2514 END SUBROUTINE TRIDI2T3
2515 !-----------------------------------------------------------------------
2517 SUBROUTINE MSTADBT3(IM,KM,K1,K2,PRSL,PRSLK,TENV,QENV, &
2518 & KLCL,KBOT,KTOP,TCLD,QCLD)
2519 !yt INCLUDE DBMSTADB;
2521 USE MODULE_GFS_MACHINE, ONLY : kind_phys
2522 USE MODULE_GFS_FUNCPHYS, ONLY : FTDP, FTHE, FTLCL, STMA
2523 USE MODULE_GFS_PHYSCONS, EPS => con_eps, EPSM1 => con_epsm1, FV => con_FVirt
2527 ! include 'constant.h'
2529 integer k,k1,k2,km,i,im
2530 real(kind=kind_phys) pv,qma,slklcl,tdpd,thelcl,tlcl
2531 real(kind=kind_phys) tma,tvcld,tvenv
2533 real(kind=kind_phys) PRSL(IM,KM), PRSLK(IM,KM), TENV(IM,KM), &
2534 & QENV(IM,KM), TCLD(IM,KM), QCLD(IM,KM)
2535 INTEGER KLCL(IM), KBOT(IM), KTOP(IM)
2537 real(kind=kind_phys) SLKMA(IM), THEMA(IM)
2538 !-----------------------------------------------------------------------
2539 ! DETERMINE WARMEST POTENTIAL WET-BULB TEMPERATURE BETWEEN K1 AND K2.
2540 ! COMPUTE ITS LIFTING CONDENSATION LEVEL.
2548 PV = 1000.0 * PRSL(I,K)*QENV(I,K)/(EPS-EPSM1*QENV(I,K))
2549 TDPD = TENV(I,K)-FTDP(PV)
2551 TLCL = FTLCL(TENV(I,K),TDPD)
2552 SLKLCL = PRSLK(I,K)*TLCL/TENV(I,K)
2557 THELCL=FTHE(TLCL,SLKLCL)
2558 IF(THELCL.GT.THEMA(I)) THEN
2564 !-----------------------------------------------------------------------
2565 ! SET CLOUD TEMPERATURES AND HUMIDITIES WHEREVER THE PARCEL LIFTED UP
2566 ! THE MOIST ADIABAT IS BUOYANT WITH RESPECT TO THE ENVIRONMENT.
2580 IF(PRSLK(I,K).LE.SLKMA(I)) THEN
2581 KLCL(I)=MIN(KLCL(I),K)
2582 CALL STMA(THEMA(I),PRSLK(I,K),TMA,QMA)
2583 ! TMA=FTMA(THEMA(I),PRSLK(I,K),QMA)
2584 TVCLD=TMA*(1.+FV*QMA)
2585 TVENV=TENV(I,K)*(1.+FV*QENV(I,K))
2586 IF(TVCLD.GT.TVENV) THEN
2587 KBOT(I)=MIN(KBOT(I),K)
2588 KTOP(I)=MAX(KTOP(I),K)
2589 TCLD(I,K)=TMA-TENV(I,K)
2590 QCLD(I,K)=QMA-QENV(I,K)
2595 !-----------------------------------------------------------------------
2597 END SUBROUTINE MSTADBT3
2599 subroutine sascnvn(im,ix,km,jcap,delt,del,prsl,ps,phil,ql, &
2600 & q1,t1,u1,v1,rcs,cldwrk,rn,kbot,ktop,kcnv,slimsk, &
2601 & dot,ncloud,pgcon,sas_mass_flux, &
2602 & pert_sas, ens_random_seed, ens_sasamp)
2603 ! & dot,ncloud,ud_mf,dd_mf,dt_mf)
2604 ! & dot,ncloud,ud_mf,dd_mf,dt_mf,me)
2606 ! use machine , only : kind_phys
2607 ! use funcphys , only : fpvs
2608 ! use physcons, grav => con_g, cp => con_cp, hvap => con_hvap &
2609 USE MODULE_GFS_MACHINE, ONLY : kind_phys
2610 USE MODULE_GFS_FUNCPHYS, ONLY : fpvs
2611 USE MODULE_GFS_PHYSCONS, grav => con_g, cp => con_cp &
2612 &, hvap => con_hvap &
2613 &, rv => con_rv, fv => con_fvirt, t0c => con_t0c &
2614 &, cvap => con_cvap, cliq => con_cliq &
2615 &, eps => con_eps, epsm1 => con_epsm1
2618 integer im, ix, km, jcap, ncloud, &
2619 & kbot(im), ktop(im), kcnv(im)
2621 real(kind=kind_phys) delt,sas_mass_flux
2622 real(kind=kind_phys) ps(im), del(ix,km), prsl(ix,km), &
2623 & ql(ix,km,2),q1(ix,km), t1(ix,km), &
2624 & u1(ix,km), v1(ix,km), rcs(im), &
2625 & cldwrk(im), rn(im), slimsk(im), &
2626 & dot(ix,km), phil(ix,km)
2627 ! hchuang code change mass flux output
2628 ! &, ud_mf(im,km),dd_mf(im,km),dt_mf(im,km)
2630 integer i, j, indx, jmn, k, kk, latd, lond, km1
2632 real(kind=kind_phys) clam, cxlamu, xlamde, xlamdd
2634 real(kind=kind_phys) adw, aup, aafac, &
2635 & beta, betal, betas, &
2636 & c0, cpoel, dellat, delta, &
2637 & desdt, deta, detad, dg, &
2638 & dh, dhh, dlnsig, dp, &
2639 & dq, dqsdp, dqsdt, dt, &
2640 & dt2, dtmax, dtmin, dv1h, &
2641 & dv1q, dv2h, dv2q, dv1u, &
2642 & dv1v, dv2u, dv2v, dv3q, &
2643 & dv3h, dv3u, dv3v, &
2644 & dz, dz1, e1, edtmax, &
2645 & edtmaxl, edtmaxs, el2orc, elocp, &
2646 & es, etah, cthk, dthk, &
2647 & evef, evfact, evfactl, fact1, &
2648 & fact2, factor, fjcap, fkm, &
2649 & g, gamma, pprime, &
2650 & qlk, qrch, qs, c1, &
2651 & rain, rfact, shear, tem1, &
2652 & tem2, terr, val, val1, &
2653 & val2, w1, w1l, w1s, &
2654 & w2, w2l, w2s, w3, &
2655 & w3l, w3s, w4, w4l, &
2656 & w4s, xdby, xpw, xpwd, &
2657 & xqrch, mbdt, tem, &
2660 real(kind=kind_phys), intent(in) :: pgcon
2661 logical,intent(in) :: pert_sas
2662 integer,intent(in) :: ens_random_seed
2663 real,intent(in) :: ens_sasamp
2665 integer kb(im), kbcon(im), kbcon1(im), &
2666 & ktcon(im), ktcon1(im), &
2667 & jmin(im), lmin(im), kbmax(im), &
2670 real(kind=kind_phys) aa1(im), acrt(im), acrtfct(im), &
2671 & delhbar(im), delq(im), delq2(im), &
2672 & delqbar(im), delqev(im), deltbar(im), &
2673 & deltv(im), dtconv(im), edt(im), &
2674 & edto(im), edtx(im), fld(im), &
2675 & hcdo(im,km), hmax(im), hmin(im), &
2676 & ucdo(im,km), vcdo(im,km),aa2(im), &
2677 & pbcdif(im), pdot(im), po(im,km), &
2678 & pwavo(im), pwevo(im), xlamud(im), &
2679 & qcdo(im,km), qcond(im), qevap(im), &
2680 & rntot(im), vshear(im), xaa0(im), &
2681 & xk(im), xlamd(im), &
2682 & xmb(im), xmbmax(im), xpwav(im), &
2683 & xpwev(im), delubar(im),delvbar(im)
2685 real(kind=kind_phys) cincr, cincrmax, cincrmin
2686 real(kind=kind_phys) xmbmx1
2688 !c physical parameters
2690 parameter(cpoel=cp/hvap,elocp=hvap/cp, &
2691 & el2orc=hvap*hvap/(rv*cp))
2692 parameter(terr=0.,c0=.002,c1=.002,delta=fv)
2693 parameter(fact1=(cvap-cliq)/rv,fact2=hvap/rv-fact1*t0c)
2694 parameter(cthk=150.,cincrmax=180.,cincrmin=120.,dthk=25.)
2695 !c local variables and arrays
2696 real(kind=kind_phys) pfld(im,km),to(im,km), qo(im,km), &
2697 & uo(im,km), vo(im,km), qeso(im,km)
2699 real(kind=kind_phys)qlko_ktcon(im),dellal(im,km),tvo(im,km), &
2700 & dbyo(im,km), zo(im,km), xlamue(im,km), &
2701 & fent1(im,km),fent2(im,km), frh(im,km), &
2702 & heo(im,km), heso(im,km), &
2703 & qrcd(im,km), dellah(im,km), dellaq(im,km), &
2704 & dellau(im,km),dellav(im,km), hcko(im,km), &
2705 & ucko(im,km), vcko(im,km), qcko(im,km), &
2706 & eta(im,km), etad(im,km), zi(im,km), &
2707 & qrcdo(im,km),pwo(im,km), pwdo(im,km), &
2711 logical totflg, cnvflg(im), flg(im)
2713 real(kind=kind_phys) pcrit(15), acritt(15), acrit(15)
2714 ! save pcrit, acritt
2715 data pcrit/850.,800.,750.,700.,650.,600.,550.,500.,450.,400.,&
2716 & 350.,300.,250.,200.,150./
2717 data acritt/.0633,.0445,.0553,.0664,.075,.1082,.1521,.2216, &
2718 & .3151,.3677,.41,.5255,.7663,1.1686,1.6851/
2719 !c gdas derived acrit
2720 !c data acritt/.203,.515,.521,.566,.625,.665,.659,.688,
2721 !c & .743,.813,.886,.947,1.138,1.377,1.896/
2722 real(kind=kind_phys) tf, tcr, tcrf
2723 parameter (tf=233.16, tcr=263.16, tcrf=1.0/(tcr-tf))
2725 real*8 :: gasdev,ran1 !zhang
2727 logical,save :: pert_sas_local !zhang
2728 integer,save :: ens_random_seed_local !zhang
2729 real,save :: ens_sasamp_local !zhang
2730 data ens_random_seed_local/0/
2731 if ( ens_random_seed_local .eq. 0 ) then
2732 ens_random_seed_local=ens_random_seed
2733 pert_sas_local=pert_sas
2734 ens_sasamp_local=ens_sasamp
2738 !c-----------------------------------------------------------------------
2743 !c initialize arrays
2774 ! hchuang code change
2784 acrit(k) = acritt(k) * (975. - pcrit(k))
2788 dtmin = max(dt2, val )
2790 dtmax = max(dt2, val )
2791 !c model tunable parameters are all here
2804 #if ( EM_CORE == 1 )
2816 fjcap = (float(jcap) / 126.) ** 2
2818 fjcap = max(fjcap,val)
2819 fkm = (float(km) / 28.) ** 2
2830 !c define top layer for search of the downdraft originating layer
2831 !c and the maximum thetae for updraft
2837 tx1(i) = 1.0 / ps(i)
2842 IF (prSL(I,K)*tx1(I) .GT. 0.04) KMAX(I) = MIN(KM,K + 1)
2843 !2011bugfix if (prsl(i,k)*tx1(i) .gt. 0.04) kmax(i) = k + 1
2844 if (prsl(i,k)*tx1(i) .gt. 0.45) kbmax(i) = k + 1
2845 if (prsl(i,k)*tx1(i) .gt. 0.70) kbm(i) = k + 1
2849 kbmax(i) = min(kbmax(i),kmax(i))
2850 kbm(i) = min(kbm(i),kmax(i))
2853 !c hydrostatic height assume zero terr and initially assume
2854 !c updraft entrainment rate as an inverse function of height
2858 zo(i,k) = phil(i,k) / g
2863 zi(i,k) = 0.5*(zo(i,k)+zo(i,k+1))
2864 xlamue(i,k) = clam / zi(i,k)
2868 !c!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2869 !c convert surface pressure to mb from cb
2873 if (k .le. kmax(i)) then
2874 pfld(i,k) = prsl(i,k) * 10.0
2896 uo(i,k) = u1(i,k) * rcs(i)
2897 vo(i,k) = v1(i,k) * rcs(i)
2903 !c p is pressure of the layer (mb)
2904 !c t is temperature at t-dt (k)..tn
2905 !c q is mixing ratio at t-dt (kg/kg)..qn
2906 !c to is temperature at t+dt (k)... this is after advection and turbulan
2907 !c qo is mixing ratio at t+dt (kg/kg)..q1
2911 if (k .le. kmax(i)) then
2912 qeso(i,k) = 0.01 * fpvs(to(i,k)) ! fpvs is in pa
2913 qeso(i,k) = eps * qeso(i,k) / (pfld(i,k) + epsm1*qeso(i,k))
2915 qeso(i,k) = max(qeso(i,k), val1)
2917 qo(i,k) = max(qo(i,k), val2 )
2918 ! qo(i,k) = min(qo(i,k),qeso(i,k))
2919 ! tvo(i,k) = to(i,k) + delta * to(i,k) * qo(i,k)
2924 !c compute moist static energy
2928 if (k .le. kmax(i)) then
2929 ! tem = g * zo(i,k) + cp * to(i,k)
2930 tem = phil(i,k) + cp * to(i,k)
2931 heo(i,k) = tem + hvap * qo(i,k)
2932 heso(i,k) = tem + hvap * qeso(i,k)
2933 !c heo(i,k) = min(heo(i,k),heso(i,k))
2938 !c determine level with largest moist static energy
2939 !c this is the level where updraft starts
2947 if (k .le. kbm(i)) then
2948 if(heo(i,k).gt.hmax(i)) then
2958 if (k .le. kmax(i)-1) then
2959 dz = .5 * (zo(i,k+1) - zo(i,k))
2960 dp = .5 * (pfld(i,k+1) - pfld(i,k))
2961 es = 0.01 * fpvs(to(i,k+1)) ! fpvs is in pa
2962 pprime = pfld(i,k+1) + epsm1 * es
2963 qs = eps * es / pprime
2964 dqsdp = - qs / pprime
2965 desdt = es * (fact1 / to(i,k+1) + fact2 / (to(i,k+1)**2))
2966 dqsdt = qs * pfld(i,k+1) * desdt / (es * pprime)
2967 gamma = el2orc * qeso(i,k+1) / (to(i,k+1)**2)
2968 dt = (g * dz + hvap * dqsdp * dp) / (cp * (1. + gamma))
2969 dq = dqsdt * dt + dqsdp * dp
2970 to(i,k) = to(i,k+1) + dt
2971 qo(i,k) = qo(i,k+1) + dq
2972 po(i,k) = .5 * (pfld(i,k) + pfld(i,k+1))
2979 if (k .le. kmax(i)-1) then
2980 qeso(i,k) = 0.01 * fpvs(to(i,k)) ! fpvs is in pa
2981 qeso(i,k) = eps * qeso(i,k) / (po(i,k) + epsm1*qeso(i,k))
2983 qeso(i,k) = max(qeso(i,k), val1)
2985 qo(i,k) = max(qo(i,k), val2 )
2986 ! qo(i,k) = min(qo(i,k),qeso(i,k))
2988 frh(i,k) = 1. - min(qo(i,k)/qeso(i,k), val1)
2989 heo(i,k) = .5 * g * (zo(i,k) + zo(i,k+1)) + &
2990 & cp * to(i,k) + hvap * qo(i,k)
2991 heso(i,k) = .5 * g * (zo(i,k) + zo(i,k+1)) + &
2992 & cp * to(i,k) + hvap * qeso(i,k)
2993 uo(i,k) = .5 * (uo(i,k) + uo(i,k+1))
2994 vo(i,k) = .5 * (vo(i,k) + vo(i,k+1))
2999 !c look for the level of free convection as cloud base
3007 if (flg(i).and.k.le.kbmax(i)) then
3008 if(k.gt.kb(i).and.heo(i,kb(i)).gt.heso(i,k)) then
3017 if(kbcon(i).eq.kmax(i)) cnvflg(i) = .false.
3022 totflg = totflg .and. (.not. cnvflg(i))
3027 !c determine critical convective inhibition
3028 !c as a function of vertical velocity at cloud base.
3032 pdot(i) = 10.* dot(i,kbcon(i))
3037 if(slimsk(i).eq.1.) then
3048 if(pdot(i).le.w4) then
3049 tem = (pdot(i) - w4) / (w3 - w4)
3050 elseif(pdot(i).ge.-w4) then
3051 tem = - (pdot(i) + w4) / (w4 - w3)
3060 tem1= .5*(cincrmax-cincrmin)
3061 cincr = cincrmax - tem * tem1
3062 pbcdif(i) = pfld(i,kb(i)) - pfld(i,kbcon(i))
3064 ! randomly perturb the convection trigger
3065 if( pert_sas_local ) then
3066 rr=2.0*ens_sasamp_local*ran1(ens_random_seed_local)-ens_sasamp_local
3067 print*, "zhang inde sas=", rr,ens_sasamp_local,ens_random_seed_local
3071 if(pbcdif(i).gt.cincr) then
3079 totflg = totflg .and. (.not. cnvflg(i))
3084 !c assume that updraft entrainment rate above cloud base is
3085 !c same as that at cloud base
3090 & (k.gt.kbcon(i).and.k.lt.kmax(i))) then
3091 xlamue(i,k) = xlamue(i,kbcon(i))
3096 !c assume the detrainment rate for the updrafts to be same as
3097 !c the entrainment rate at cloud base
3101 xlamud(i) = xlamue(i,kbcon(i))
3105 !c functions rapidly decreasing with height, mimicking a cloud ensemble
3106 !c (Bechtold et al., 2008)
3111 & (k.gt.kbcon(i).and.k.lt.kmax(i))) then
3112 tem = qeso(i,k)/qeso(i,kbcon(i))
3119 !c final entrainment rate as the sum of turbulent part and organized entrainment
3120 !c depending on the environmental relative humidity
3121 !c (Bechtold et al., 2008)
3126 & (k.ge.kbcon(i).and.k.lt.kmax(i))) then
3127 tem = cxlamu * frh(i,k) * fent2(i,k)
3128 xlamue(i,k) = xlamue(i,k)*fent1(i,k) + tem
3133 !c determine updraft mass flux for the subcloud layers
3138 if(k.lt.kbcon(i).and.k.ge.kb(i)) then
3139 dz = zi(i,k+1) - zi(i,k)
3140 ptem = 0.5*(xlamue(i,k)+xlamue(i,k+1))-xlamud(i)
3141 eta(i,k) = eta(i,k+1) / (1. + ptem * dz)
3147 !c compute mass flux above cloud base
3152 if(k.gt.kbcon(i).and.k.lt.kmax(i)) then
3153 dz = zi(i,k) - zi(i,k-1)
3154 ptem = 0.5*(xlamue(i,k)+xlamue(i,k-1))-xlamud(i)
3155 eta(i,k) = eta(i,k-1) * (1 + ptem * dz)
3161 !c compute updraft cloud properties
3166 hcko(i,indx) = heo(i,indx)
3167 ucko(i,indx) = uo(i,indx)
3168 vcko(i,indx) = vo(i,indx)
3173 !c cloud property is modified by the entrainment process
3178 if(k.gt.kb(i).and.k.lt.kmax(i)) then
3179 dz = zi(i,k) - zi(i,k-1)
3180 tem = 0.5 * (xlamue(i,k)+xlamue(i,k-1)) * dz
3181 tem1 = 0.5 * xlamud(i) * dz
3182 factor = 1. + tem - tem1
3183 ptem = 0.5 * tem + pgcon
3184 ptem1= 0.5 * tem - pgcon
3185 hcko(i,k) = ((1.-tem1)*hcko(i,k-1)+tem*0.5* &
3186 & (heo(i,k)+heo(i,k-1)))/factor
3187 ucko(i,k) = ((1.-tem1)*ucko(i,k-1)+ptem*uo(i,k) &
3188 & +ptem1*uo(i,k-1))/factor
3189 vcko(i,k) = ((1.-tem1)*vcko(i,k-1)+ptem*vo(i,k) &
3190 & +ptem1*vo(i,k-1))/factor
3191 dbyo(i,k) = hcko(i,k) - heso(i,k)
3197 !c taking account into convection inhibition due to existence of
3198 !c dry layers below cloud base
3206 if (flg(i).and.k.lt.kmax(i)) then
3207 if(k.ge.kbcon(i).and.dbyo(i,k).gt.0.) then
3216 if(kbcon1(i).eq.kmax(i)) cnvflg(i) = .false.
3221 tem = pfld(i,kbcon(i)) - pfld(i,kbcon1(i))
3222 if(tem.gt.dthk) then
3230 totflg = totflg .and. (.not. cnvflg(i))
3235 !c determine first guess cloud top as the level of zero buoyancy
3243 if (flg(i).and.k .lt. kmax(i)) then
3244 if(k.gt.kbcon1(i).and.dbyo(i,k).lt.0.) then
3254 tem = pfld(i,kbcon(i))-pfld(i,ktcon(i))
3255 if(tem.lt.cthk) cnvflg(i) = .false.
3261 totflg = totflg .and. (.not. cnvflg(i))
3266 !c search for downdraft originating level above theta-e minimum
3270 hmin(i) = heo(i,kbcon1(i))
3277 if (cnvflg(i) .and. k .le. kbmax(i)) then
3278 if(k.gt.kbcon1(i).and.heo(i,k).lt.hmin(i)) then
3286 !c make sure that jmin(i) is within the cloud
3290 jmin(i) = min(lmin(i),ktcon(i)-1)
3291 jmin(i) = max(jmin(i),kbcon1(i)+1)
3292 if(jmin(i).ge.ktcon(i)) cnvflg(i) = .false.
3296 !c specify upper limit of mass flux at cloud base
3303 dp = 1000. * del(i,k)
3304 xmbmax(i) = dp / (g * dt2)
3305 xmbmax(i) = min(sas_mass_flux,xmbmax(i))
3307 ! tem = dp / (g * dt2)
3308 ! xmbmax(i) = min(tem, xmbmax(i))
3312 !c compute cloud moisture property and precipitation
3317 qcko(i,kb(i)) = qo(i,kb(i))
3324 if(k.gt.kb(i).and.k.lt.ktcon(i)) then
3325 dz = zi(i,k) - zi(i,k-1)
3326 gamma = el2orc * qeso(i,k) / (to(i,k)**2)
3328 & + gamma * dbyo(i,k) / (hvap * (1. + gamma))
3330 tem = 0.5 * (xlamue(i,k)+xlamue(i,k-1)) * dz
3331 tem1 = 0.5 * xlamud(i) * dz
3332 factor = 1. + tem - tem1
3333 qcko(i,k) = ((1.-tem1)*qcko(i,k-1)+tem*0.5* &
3334 & (qo(i,k)+qo(i,k-1)))/factor
3336 dq = eta(i,k) * (qcko(i,k) - qrch)
3338 ! rhbar(i) = rhbar(i) + qo(i,k) / qeso(i,k)
3340 !c check if there is excess moisture to release latent heat
3342 if(k.ge.kbcon(i).and.dq.gt.0.) then
3343 etah = .5 * (eta(i,k) + eta(i,k-1))
3344 if(ncloud.gt.0..and.k.gt.jmin(i)) then
3345 dp = 1000. * del(i,k)
3346 qlk = dq / (eta(i,k) + etah * (c0 + c1) * dz)
3347 dellal(i,k) = etah * c1 * dz * qlk * g / dp
3349 qlk = dq / (eta(i,k) + etah * c0 * dz)
3351 aa1(i) = aa1(i) - dz * g * qlk
3352 qcko(i,k) = qlk + qrch
3353 pwo(i,k) = etah * c0 * dz * qlk
3354 pwavo(i) = pwavo(i) + pwo(i,k)
3362 ! if(cnvflg(i)) then
3363 ! indx = ktcon(i) - kb(i) - 1
3364 ! rhbar(i) = rhbar(i) / float(indx)
3368 !c calculate cloud work function
3373 if(k.ge.kbcon(i).and.k.lt.ktcon(i)) then
3374 dz1 = zo(i,k+1) - zo(i,k)
3375 gamma = el2orc * qeso(i,k) / (to(i,k)**2)
3376 rfact = 1. + delta * cp * gamma &
3379 & dz1 * (g / (cp * to(i,k))) &
3380 & * dbyo(i,k) / (1. + gamma) &
3384 & dz1 * g * delta * &
3385 & max(val,(qeso(i,k) - qo(i,k)))
3391 if(cnvflg(i).and.aa1(i).le.0.) cnvflg(i) = .false.
3396 totflg = totflg .and. (.not. cnvflg(i))
3401 !c estimate the onvective overshooting as the level
3402 !c where the [aafac * cloud work function] becomes zero,
3403 !c which is the final cloud top
3407 aa2(i) = aafac * aa1(i)
3413 ktcon1(i) = kmax(i) - 1
3418 if(k.ge.ktcon(i).and.k.lt.kmax(i)) then
3419 dz1 = zo(i,k+1) - zo(i,k)
3420 gamma = el2orc * qeso(i,k) / (to(i,k)**2)
3421 rfact = 1. + delta * cp * gamma &
3424 & dz1 * (g / (cp * to(i,k))) &
3425 & * dbyo(i,k) / (1. + gamma) &
3427 if(aa2(i).lt.0.) then
3436 !c compute cloud moisture property, detraining cloud water
3437 !c and precipitation in overshooting layers
3442 if(k.ge.ktcon(i).and.k.lt.ktcon1(i)) then
3443 dz = zi(i,k) - zi(i,k-1)
3444 gamma = el2orc * qeso(i,k) / (to(i,k)**2)
3446 & + gamma * dbyo(i,k) / (hvap * (1. + gamma))
3448 tem = 0.5 * (xlamue(i,k)+xlamue(i,k-1)) * dz
3449 tem1 = 0.5 * xlamud(i) * dz
3450 factor = 1. + tem - tem1
3451 qcko(i,k) = ((1.-tem1)*qcko(i,k-1)+tem*0.5* &
3452 & (qo(i,k)+qo(i,k-1)))/factor
3454 dq = eta(i,k) * (qcko(i,k) - qrch)
3456 !c check if there is excess moisture to release latent heat
3459 etah = .5 * (eta(i,k) + eta(i,k-1))
3460 if(ncloud.gt.0.) then
3461 dp = 1000. * del(i,k)
3462 qlk = dq / (eta(i,k) + etah * (c0 + c1) * dz)
3463 dellal(i,k) = etah * c1 * dz * qlk * g / dp
3465 qlk = dq / (eta(i,k) + etah * c0 * dz)
3467 qcko(i,k) = qlk + qrch
3468 pwo(i,k) = etah * c0 * dz * qlk
3469 pwavo(i) = pwavo(i) + pwo(i,k)
3476 !c exchange ktcon with ktcon1
3481 ktcon(i) = ktcon1(i)
3486 !c this section is ready for cloud water
3488 if(ncloud.gt.0) then
3490 !c compute liquid and vapor separation at cloud top
3495 gamma = el2orc * qeso(i,k) / (to(i,k)**2)
3497 & + gamma * dbyo(i,k) / (hvap * (1. + gamma))
3498 dq = qcko(i,k) - qrch
3500 !c check if there is excess moisture to release latent heat
3510 !ccccc if(lat.eq.latd.and.lon.eq.lond.and.cnvflg(i)) then
3511 !ccccc print *, ' aa1(i) before dwndrft =', aa1(i)
3514 !c------- downdraft calculations
3516 !c--- compute precipitation efficiency in terms of windshear
3526 if(k.gt.kb(i).and.k.le.ktcon(i)) then
3527 shear= sqrt((uo(i,k)-uo(i,k-1)) ** 2 &
3528 & + (vo(i,k)-vo(i,k-1)) ** 2)
3529 vshear(i) = vshear(i) + shear
3536 vshear(i) = 1.e3 * vshear(i) / (zi(i,ktcon(i))-zi(i,kb(i)))
3537 e1=1.591-.639*vshear(i) &
3538 & +.0953*(vshear(i)**2)-.00496*(vshear(i)**3)
3541 edt(i) = min(edt(i),val)
3543 edt(i) = max(edt(i),val)
3549 !c determine detrainment rate between 1 and kbcon
3558 if(cnvflg(i).and.k.ge.1.and.k.lt.kbcon(i)) then
3559 dz = zi(i,k+1) - zi(i,k)
3560 sumx(i) = sumx(i) + dz
3566 if(slimsk(i).eq.1.) beta = betal
3568 dz = (sumx(i)+zi(i,1))/float(kbcon(i))
3569 tem = 1./float(kbcon(i))
3570 xlamd(i) = (1.-beta**tem)/dz
3574 !c determine downdraft mass flux
3578 if (cnvflg(i) .and. k .le. kmax(i)-1) then
3579 if(k.lt.jmin(i).and.k.ge.kbcon(i)) then
3580 dz = zi(i,k+1) - zi(i,k)
3581 ptem = xlamdd - xlamde
3582 etad(i,k) = etad(i,k+1) * (1. - ptem * dz)
3583 else if(k.lt.kbcon(i)) then
3584 dz = zi(i,k+1) - zi(i,k)
3585 ptem = xlamd(i) + xlamdd - xlamde
3586 etad(i,k) = etad(i,k+1) * (1. - ptem * dz)
3592 !c--- downdraft moisture properties
3597 hcdo(i,jmn) = heo(i,jmn)
3598 qcdo(i,jmn) = qo(i,jmn)
3599 qrcdo(i,jmn)= qeso(i,jmn)
3600 ucdo(i,jmn) = uo(i,jmn)
3601 vcdo(i,jmn) = vo(i,jmn)
3608 if (cnvflg(i) .and. k.lt.jmin(i)) then
3609 dz = zi(i,k+1) - zi(i,k)
3610 if(k.ge.kbcon(i)) then
3612 tem1 = 0.5 * xlamdd * dz
3615 tem1 = 0.5 * (xlamd(i)+xlamdd) * dz
3617 factor = 1. + tem - tem1
3618 ptem = 0.5 * tem - pgcon
3619 ptem1= 0.5 * tem + pgcon
3620 hcdo(i,k) = ((1.-tem1)*hcdo(i,k+1)+tem*0.5* &
3621 & (heo(i,k)+heo(i,k+1)))/factor
3622 ucdo(i,k) = ((1.-tem1)*ucdo(i,k+1)+ptem*uo(i,k+1) &
3623 & +ptem1*uo(i,k))/factor
3624 vcdo(i,k) = ((1.-tem1)*vcdo(i,k+1)+ptem*vo(i,k+1) &
3625 & +ptem1*vo(i,k))/factor
3626 dbyo(i,k) = hcdo(i,k) - heso(i,k)
3633 if (cnvflg(i).and.k.lt.jmin(i)) then
3634 gamma = el2orc * qeso(i,k) / (to(i,k)**2)
3635 qrcdo(i,k) = qeso(i,k)+ &
3636 & (1./hvap)*(gamma/(1.+gamma))*dbyo(i,k)
3637 ! detad = etad(i,k+1) - etad(i,k)
3639 dz = zi(i,k+1) - zi(i,k)
3640 if(k.ge.kbcon(i)) then
3642 tem1 = 0.5 * xlamdd * dz
3645 tem1 = 0.5 * (xlamd(i)+xlamdd) * dz
3647 factor = 1. + tem - tem1
3648 qcdo(i,k) = ((1.-tem1)*qcdo(i,k+1)+tem*0.5* &
3649 & (qo(i,k)+qo(i,k+1)))/factor
3651 ! pwdo(i,k) = etad(i,k+1) * qcdo(i,k+1) -
3652 ! & etad(i,k) * qrcdo(i,k)
3653 ! pwdo(i,k) = pwdo(i,k) - detad *
3654 ! & .5 * (qrcdo(i,k) + qrcdo(i,k+1))
3656 pwdo(i,k) = etad(i,k+1) * (qcdo(i,k) - qrcdo(i,k))
3657 qcdo(i,k) = qrcdo(i,k)
3658 pwevo(i) = pwevo(i) + pwdo(i,k)
3663 !c--- final downdraft strength dependent on precip
3664 !c--- efficiency (edt), normalized condensate (pwav), and
3665 !c--- evaporate (pwev)
3669 if(slimsk(i).eq.0.) edtmax = edtmaxs
3671 if(pwevo(i).lt.0.) then
3672 edto(i) = -edto(i) * pwavo(i) / pwevo(i)
3673 edto(i) = min(edto(i),edtmax)
3680 !c--- downdraft cloudwork functions
3684 if (cnvflg(i) .and. k .lt. jmin(i)) then
3685 gamma = el2orc * qeso(i,k) / to(i,k)**2
3690 dz=-1.*(zo(i,k+1)-zo(i,k))
3691 aa1(i)=aa1(i)+edto(i)*dz*(g/(cp*dt))*((dhh-dh)/(1.+dg)) &
3692 & *(1.+delta*cp*dg*dt/hvap)
3694 aa1(i)=aa1(i)+edto(i)* &
3695 & dz*g*delta*max(val,(qeso(i,k)-qo(i,k)))
3700 if(cnvflg(i).and.aa1(i).le.0.) then
3707 totflg = totflg .and. (.not. cnvflg(i))
3712 !c--- what would the change be, that a cloud with unit mass
3713 !c--- will do to the environment?
3717 if(cnvflg(i) .and. k .le. kmax(i)) then
3727 dp = 1000. * del(i,1)
3728 dellah(i,1) = edto(i) * etad(i,1) * (hcdo(i,1) &
3729 & - heo(i,1)) * g / dp
3730 dellaq(i,1) = edto(i) * etad(i,1) * (qcdo(i,1) &
3731 & - qo(i,1)) * g / dp
3732 dellau(i,1) = edto(i) * etad(i,1) * (ucdo(i,1) &
3733 & - uo(i,1)) * g / dp
3734 dellav(i,1) = edto(i) * etad(i,1) * (vcdo(i,1) &
3735 & - vo(i,1)) * g / dp
3739 !c--- changed due to subsidence and entrainment
3743 if (cnvflg(i).and.k.lt.ktcon(i)) then
3745 if(k.le.kb(i)) aup = 0.
3747 if(k.gt.jmin(i)) adw = 0.
3748 dp = 1000. * del(i,k)
3749 dz = zi(i,k) - zi(i,k-1)
3752 dv2h = .5 * (heo(i,k) + heo(i,k-1))
3755 dv2q = .5 * (qo(i,k) + qo(i,k-1))
3758 dv2u = .5 * (uo(i,k) + uo(i,k-1))
3761 dv2v = .5 * (vo(i,k) + vo(i,k-1))
3764 tem = 0.5 * (xlamue(i,k)+xlamue(i,k-1))
3767 if(k.le.kbcon(i)) then
3769 ptem1 = xlamd(i)+xlamdd
3775 dellah(i,k) = dellah(i,k) + &
3776 & ((aup*eta(i,k)-adw*edto(i)*etad(i,k))*dv1h &
3777 & - (aup*eta(i,k-1)-adw*edto(i)*etad(i,k-1))*dv3h &
3778 & - (aup*tem*eta(i,k-1)+adw*edto(i)*ptem*etad(i,k))*dv2h*dz &
3779 & + aup*tem1*eta(i,k-1)*.5*(hcko(i,k)+hcko(i,k-1))*dz &
3780 & + adw*edto(i)*ptem1*etad(i,k)*.5*(hcdo(i,k)+hcdo(i,k-1)) &
3783 dellaq(i,k) = dellaq(i,k) + &
3784 & ((aup*eta(i,k)-adw*edto(i)*etad(i,k))*dv1q &
3785 & - (aup*eta(i,k-1)-adw*edto(i)*etad(i,k-1))*dv3q &
3786 & - (aup*tem*eta(i,k-1)+adw*edto(i)*ptem*etad(i,k))*dv2q*dz &
3787 & + aup*tem1*eta(i,k-1)*.5*(qcko(i,k)+qcko(i,k-1))*dz &
3788 & + adw*edto(i)*ptem1*etad(i,k)*.5*(qrcdo(i,k)+qrcdo(i,k-1)) &
3790 !23456789012345678901234567890123456789012345678901234567890123456789012
3792 dellau(i,k) = dellau(i,k) + &
3793 & ((aup*eta(i,k)-adw*edto(i)*etad(i,k))*dv1u &
3794 & - (aup*eta(i,k-1)-adw*edto(i)*etad(i,k-1))*dv3u &
3795 & - (aup*tem*eta(i,k-1)+adw*edto(i)*ptem*etad(i,k))*dv2u*dz &
3796 & + aup*tem1*eta(i,k-1)*.5*(ucko(i,k)+ucko(i,k-1))*dz &
3797 & + adw*edto(i)*ptem1*etad(i,k)*.5*(ucdo(i,k)+ucdo(i,k-1))*dz &
3798 & - pgcon*(aup*eta(i,k-1)-adw*edto(i)*etad(i,k))*(dv1u-dv3u) &
3801 dellav(i,k) = dellav(i,k) + &
3802 & ((aup*eta(i,k)-adw*edto(i)*etad(i,k))*dv1v &
3803 & - (aup*eta(i,k-1)-adw*edto(i)*etad(i,k-1))*dv3v &
3804 & - (aup*tem*eta(i,k-1)+adw*edto(i)*ptem*etad(i,k))*dv2v*dz &
3805 & + aup*tem1*eta(i,k-1)*.5*(vcko(i,k)+vcko(i,k-1))*dz &
3806 & + adw*edto(i)*ptem1*etad(i,k)*.5*(vcdo(i,k)+vcdo(i,k-1))*dz &
3807 & - pgcon*(aup*eta(i,k-1)-adw*edto(i)*etad(i,k))*(dv1v-dv3v) &
3819 dp = 1000. * del(i,indx)
3820 dv1h = heo(i,indx-1)
3821 dellah(i,indx) = eta(i,indx-1) * &
3822 & (hcko(i,indx-1) - dv1h) * g / dp
3824 dellaq(i,indx) = eta(i,indx-1) * &
3825 & (qcko(i,indx-1) - dv1q) * g / dp
3827 dellau(i,indx) = eta(i,indx-1) * &
3828 & (ucko(i,indx-1) - dv1u) * g / dp
3830 dellav(i,indx) = eta(i,indx-1) * &
3831 & (vcko(i,indx-1) - dv1v) * g / dp
3835 dellal(i,indx) = eta(i,indx-1) * &
3836 & qlko_ktcon(i) * g / dp
3840 !c------- final changed variable per unit mass flux
3844 if (cnvflg(i).and.k .le. kmax(i)) then
3845 if(k.gt.ktcon(i)) then
3849 if(k.le.ktcon(i)) then
3850 qo(i,k) = dellaq(i,k) * mbdt + q1(i,k)
3851 dellat = (dellah(i,k) - hvap * dellaq(i,k)) / cp
3852 to(i,k) = dellat * mbdt + t1(i,k)
3854 qo(i,k) = max(qo(i,k), val )
3859 !c!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
3861 !c--- the above changed environment is now used to calulate the
3862 !c--- effect the arbitrary cloud (with unit mass flux)
3863 !c--- would have on the stability,
3864 !c--- which then is used to calculate the real mass flux,
3865 !c--- necessary to keep this change in balance with the large-scale
3866 !c--- destabilization.
3868 !c--- environmental conditions again, first heights
3872 if(cnvflg(i) .and. k .le. kmax(i)) then
3873 qeso(i,k) = 0.01 * fpvs(to(i,k)) ! fpvs is in pa
3874 qeso(i,k) = eps * qeso(i,k) / (pfld(i,k)+epsm1*qeso(i,k))
3876 qeso(i,k) = max(qeso(i,k), val )
3877 ! tvo(i,k) = to(i,k) + delta * to(i,k) * qo(i,k)
3882 !c--- moist static energy
3886 if(cnvflg(i) .and. k .le. kmax(i)-1) then
3887 dz = .5 * (zo(i,k+1) - zo(i,k))
3888 dp = .5 * (pfld(i,k+1) - pfld(i,k))
3889 es = 0.01 * fpvs(to(i,k+1)) ! fpvs is in pa
3890 pprime = pfld(i,k+1) + epsm1 * es
3891 qs = eps * es / pprime
3892 dqsdp = - qs / pprime
3893 desdt = es * (fact1 / to(i,k+1) + fact2 / (to(i,k+1)**2))
3894 dqsdt = qs * pfld(i,k+1) * desdt / (es * pprime)
3895 gamma = el2orc * qeso(i,k+1) / (to(i,k+1)**2)
3896 dt = (g * dz + hvap * dqsdp * dp) / (cp * (1. + gamma))
3897 dq = dqsdt * dt + dqsdp * dp
3898 to(i,k) = to(i,k+1) + dt
3899 qo(i,k) = qo(i,k+1) + dq
3900 po(i,k) = .5 * (pfld(i,k) + pfld(i,k+1))
3906 if(cnvflg(i) .and. k .le. kmax(i)-1) then
3907 qeso(i,k) = 0.01 * fpvs(to(i,k)) ! fpvs is in pa
3908 qeso(i,k) = eps * qeso(i,k) / (po(i,k) + epsm1 * qeso(i,k))
3910 qeso(i,k) = max(qeso(i,k), val1)
3912 qo(i,k) = max(qo(i,k), val2 )
3913 ! qo(i,k) = min(qo(i,k),qeso(i,k))
3914 heo(i,k) = .5 * g * (zo(i,k) + zo(i,k+1)) + &
3915 & cp * to(i,k) + hvap * qo(i,k)
3916 heso(i,k) = .5 * g * (zo(i,k) + zo(i,k+1)) + &
3917 & cp * to(i,k) + hvap * qeso(i,k)
3924 heo(i,k) = g * zo(i,k) + cp * to(i,k) + hvap * qo(i,k)
3925 heso(i,k) = g * zo(i,k) + cp * to(i,k) + hvap * qeso(i,k)
3926 !c heo(i,k) = min(heo(i,k),heso(i,k))
3930 !c**************************** static control
3932 !c------- moisture and cloud work functions
3944 hcko(i,indx) = heo(i,indx)
3945 qcko(i,indx) = qo(i,indx)
3951 if(k.gt.kb(i).and.k.le.ktcon(i)) then
3952 dz = zi(i,k) - zi(i,k-1)
3953 tem = 0.5 * (xlamue(i,k)+xlamue(i,k-1)) * dz
3954 tem1 = 0.5 * xlamud(i) * dz
3955 factor = 1. + tem - tem1
3956 hcko(i,k) = ((1.-tem1)*hcko(i,k-1)+tem*0.5* &
3957 & (heo(i,k)+heo(i,k-1)))/factor
3965 if(k.gt.kb(i).and.k.lt.ktcon(i)) then
3966 dz = zi(i,k) - zi(i,k-1)
3967 gamma = el2orc * qeso(i,k) / (to(i,k)**2)
3968 xdby = hcko(i,k) - heso(i,k)
3970 & + gamma * xdby / (hvap * (1. + gamma))
3972 tem = 0.5 * (xlamue(i,k)+xlamue(i,k-1)) * dz
3973 tem1 = 0.5 * xlamud(i) * dz
3974 factor = 1. + tem - tem1
3975 qcko(i,k) = ((1.-tem1)*qcko(i,k-1)+tem*0.5* &
3976 & (qo(i,k)+qo(i,k-1)))/factor
3978 dq = eta(i,k) * (qcko(i,k) - xqrch)
3980 if(k.ge.kbcon(i).and.dq.gt.0.) then
3981 etah = .5 * (eta(i,k) + eta(i,k-1))
3982 if(ncloud.gt.0..and.k.gt.jmin(i)) then
3983 qlk = dq / (eta(i,k) + etah * (c0 + c1) * dz)
3985 qlk = dq / (eta(i,k) + etah * c0 * dz)
3987 if(k.lt.ktcon1(i)) then
3988 xaa0(i) = xaa0(i) - dz * g * qlk
3990 qcko(i,k) = qlk + xqrch
3991 xpw = etah * c0 * dz * qlk
3992 xpwav(i) = xpwav(i) + xpw
3995 if(k.ge.kbcon(i).and.k.lt.ktcon1(i)) then
3996 dz1 = zo(i,k+1) - zo(i,k)
3997 gamma = el2orc * qeso(i,k) / (to(i,k)**2)
3998 rfact = 1. + delta * cp * gamma &
4001 & + dz1 * (g / (cp * to(i,k))) &
4002 & * xdby / (1. + gamma) &
4006 & dz1 * g * delta * &
4007 & max(val,(qeso(i,k) - qo(i,k)))
4013 !c------- downdraft calculations
4015 !c--- downdraft moisture properties
4020 hcdo(i,jmn) = heo(i,jmn)
4021 qcdo(i,jmn) = qo(i,jmn)
4022 qrcd(i,jmn) = qeso(i,jmn)
4029 if (cnvflg(i) .and. k.lt.jmin(i)) then
4030 dz = zi(i,k+1) - zi(i,k)
4031 if(k.ge.kbcon(i)) then
4033 tem1 = 0.5 * xlamdd * dz
4036 tem1 = 0.5 * (xlamd(i)+xlamdd) * dz
4038 factor = 1. + tem - tem1
4039 hcdo(i,k) = ((1.-tem1)*hcdo(i,k+1)+tem*0.5* &
4040 & (heo(i,k)+heo(i,k+1)))/factor
4047 if (cnvflg(i) .and. k .lt. jmin(i)) then
4050 gamma = el2orc * dq / dt**2
4051 dh = hcdo(i,k) - heso(i,k)
4052 qrcd(i,k)=dq+(1./hvap)*(gamma/(1.+gamma))*dh
4053 ! detad = etad(i,k+1) - etad(i,k)
4055 dz = zi(i,k+1) - zi(i,k)
4056 if(k.ge.kbcon(i)) then
4058 tem1 = 0.5 * xlamdd * dz
4061 tem1 = 0.5 * (xlamd(i)+xlamdd) * dz
4063 factor = 1. + tem - tem1
4064 qcdo(i,k) = ((1.-tem1)*qcdo(i,k+1)+tem*0.5* &
4065 & (qo(i,k)+qo(i,k+1)))/factor
4067 ! xpwd = etad(i,k+1) * qcdo(i,k+1) -
4068 ! & etad(i,k) * qrcd(i,k)
4069 ! xpwd = xpwd - detad *
4070 ! & .5 * (qrcd(i,k) + qrcd(i,k+1))
4072 xpwd = etad(i,k+1) * (qcdo(i,k) - qrcd(i,k))
4073 qcdo(i,k)= qrcd(i,k)
4074 xpwev(i) = xpwev(i) + xpwd
4081 if(slimsk(i).eq.0.) edtmax = edtmaxs
4083 if(xpwev(i).ge.0.) then
4086 edtx(i) = -edtx(i) * xpwav(i) / xpwev(i)
4087 edtx(i) = min(edtx(i),edtmax)
4093 !c--- downdraft cloudwork functions
4098 if (cnvflg(i) .and. k.lt.jmin(i)) then
4099 gamma = el2orc * qeso(i,k) / to(i,k)**2
4104 dz=-1.*(zo(i,k+1)-zo(i,k))
4105 xaa0(i)=xaa0(i)+edtx(i)*dz*(g/(cp*dt))*((dhh-dh)/(1.+dg)) &
4106 & *(1.+delta*cp*dg*dt/hvap)
4108 xaa0(i)=xaa0(i)+edtx(i)* &
4109 & dz*g*delta*max(val,(qeso(i,k)-qo(i,k)))
4114 !c calculate critical cloud work function
4118 if(pfld(i,ktcon(i)).lt.pcrit(15))then
4119 acrt(i)=acrit(15)*(975.-pfld(i,ktcon(i))) &
4121 else if(pfld(i,ktcon(i)).gt.pcrit(1))then
4124 k = int((850. - pfld(i,ktcon(i)))/50.) + 2
4127 acrt(i)=acrit(k)+(acrit(k-1)-acrit(k))* &
4128 & (pfld(i,ktcon(i))-pcrit(k))/(pcrit(k-1)-pcrit(k))
4134 if(slimsk(i).eq.1.) then
4146 !c modify critical cloud workfunction by cloud base vertical velocity
4148 if(pdot(i).le.w4) then
4149 acrtfct(i) = (pdot(i) - w4) / (w3 - w4)
4150 elseif(pdot(i).ge.-w4) then
4151 acrtfct(i) = - (pdot(i) + w4) / (w4 - w3)
4156 acrtfct(i) = max(acrtfct(i),val1)
4158 acrtfct(i) = min(acrtfct(i),val2)
4159 acrtfct(i) = 1. - acrtfct(i)
4161 !c modify acrtfct(i) by colume mean rh if rhbar(i) is greater than 80 percent
4163 !c if(rhbar(i).ge..8) then
4164 !c acrtfct(i) = acrtfct(i) * (.9 - min(rhbar(i),.9)) * 10.
4167 !c modify adjustment time scale by cloud base vertical velocity
4170 dtconv(i) = dt2 + max((1800. - dt2),val1) * &
4171 & (pdot(i) - w2) / (w1 - w2)
4172 !c dtconv(i) = max(dtconv(i), dt2)
4173 !c dtconv(i) = 1800. * (pdot(i) - w2) / (w1 - w2)
4174 dtconv(i) = max(dtconv(i),dtmin)
4175 dtconv(i) = min(dtconv(i),dtmax)
4180 !c--- large scale forcing
4185 fld(i)=(aa1(i)-acrt(i)* acrtfct(i))/dtconv(i)
4186 if(fld(i).le.0.) cnvflg(i) = .false.
4189 !c xaa0(i) = max(xaa0(i),0.)
4190 xk(i) = (xaa0(i) - aa1(i)) / mbdt
4191 if(xk(i).ge.0.) cnvflg(i) = .false.
4194 !c--- kernel, cloud base mass flux
4197 xmb(i) = -fld(i) / xk(i)
4198 xmb(i) = min(xmb(i),xmbmax(i))
4199 xmbmx1=max(xmbmx1,xmb(i))
4202 ! if(xmbmx1.gt.0.4)print*,'qingfu test xmbmx1=',xmbmx1
4206 totflg = totflg .and. (.not. cnvflg(i))
4211 !c restore to,qo,uo,vo to t1,q1,u1,v1 in case convection stops
4215 if (cnvflg(i) .and. k .le. kmax(i)) then
4220 qeso(i,k) = 0.01 * fpvs(t1(i,k)) ! fpvs is in pa
4221 qeso(i,k) = eps * qeso(i,k) / (pfld(i,k) + epsm1*qeso(i,k))
4223 qeso(i,k) = max(qeso(i,k), val )
4227 !c!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
4229 !c--- feedback: simply the changes from the cloud with unit mass flux
4230 !c--- multiplied by the mass flux necessary to keep the
4231 !c--- equilibrium with the larger-scale.
4243 if (cnvflg(i) .and. k .le. kmax(i)) then
4244 if(k.le.ktcon(i)) then
4245 dellat = (dellah(i,k) - hvap * dellaq(i,k)) / cp
4246 t1(i,k) = t1(i,k) + dellat * xmb(i) * dt2
4247 q1(i,k) = q1(i,k) + dellaq(i,k) * xmb(i) * dt2
4249 u1(i,k) = u1(i,k) + dellau(i,k) * xmb(i) * dt2 * tem
4250 v1(i,k) = v1(i,k) + dellav(i,k) * xmb(i) * dt2 * tem
4251 dp = 1000. * del(i,k)
4252 delhbar(i) = delhbar(i) + dellah(i,k)*xmb(i)*dp/g
4253 delqbar(i) = delqbar(i) + dellaq(i,k)*xmb(i)*dp/g
4254 deltbar(i) = deltbar(i) + dellat*xmb(i)*dp/g
4255 delubar(i) = delubar(i) + dellau(i,k)*xmb(i)*dp/g
4256 delvbar(i) = delvbar(i) + dellav(i,k)*xmb(i)*dp/g
4263 if (cnvflg(i) .and. k .le. kmax(i)) then
4264 if(k.le.ktcon(i)) then
4265 qeso(i,k) = 0.01 * fpvs(t1(i,k)) ! fpvs is in pa
4266 qeso(i,k) = eps * qeso(i,k)/(pfld(i,k) + epsm1*qeso(i,k))
4268 qeso(i,k) = max(qeso(i,k), val )
4282 if (cnvflg(i) .and. k .le. kmax(i)) then
4283 if(k.lt.ktcon(i)) then
4285 if(k.le.kb(i)) aup = 0.
4287 if(k.ge.jmin(i)) adw = 0.
4288 rain = aup * pwo(i,k) + adw * edto(i) * pwdo(i,k)
4289 rntot(i) = rntot(i) + rain * xmb(i) * .001 * dt2
4296 if (k .le. kmax(i)) then
4300 if(cnvflg(i).and.k.lt.ktcon(i)) then
4302 if(k.le.kb(i)) aup = 0.
4304 if(k.ge.jmin(i)) adw = 0.
4305 rain = aup * pwo(i,k) + adw * edto(i) * pwdo(i,k)
4306 rn(i) = rn(i) + rain * xmb(i) * .001 * dt2
4308 if(flg(i).and.k.lt.ktcon(i)) then
4309 evef = edt(i) * evfact
4310 if(slimsk(i).eq.1.) evef=edt(i) * evfactl
4311 ! if(slimsk(i).eq.1.) evef=.07
4312 !c if(slimsk(i).ne.1.) evef = 0.
4313 qcond(i) = evef * (q1(i,k) - qeso(i,k)) &
4314 & / (1. + el2orc * qeso(i,k) / t1(i,k)**2)
4315 dp = 1000. * del(i,k)
4316 if(rn(i).gt.0..and.qcond(i).lt.0.) then
4317 qevap(i) = -qcond(i) * (1.-exp(-.32*sqrt(dt2*rn(i))))
4318 qevap(i) = min(qevap(i), rn(i)*1000.*g/dp)
4319 delq2(i) = delqev(i) + .001 * qevap(i) * dp / g
4321 if(rn(i).gt.0..and.qcond(i).lt.0..and. &
4322 & delq2(i).gt.rntot(i)) then
4323 qevap(i) = 1000.* g * (rntot(i) - delqev(i)) / dp
4326 if(rn(i).gt.0..and.qevap(i).gt.0.) then
4327 q1(i,k) = q1(i,k) + qevap(i)
4328 t1(i,k) = t1(i,k) - elocp * qevap(i)
4329 rn(i) = rn(i) - .001 * qevap(i) * dp / g
4330 deltv(i) = - elocp*qevap(i)/dt2
4331 delq(i) = + qevap(i)/dt2
4332 delqev(i) = delqev(i) + .001*dp*qevap(i)/g
4334 dellaq(i,k) = dellaq(i,k) + delq(i) / xmb(i)
4335 delqbar(i) = delqbar(i) + delq(i)*dp/g
4336 deltbar(i) = deltbar(i) + deltv(i)*dp/g
4343 ! if(me.eq.31.and.cnvflg(i)) then
4344 ! if(cnvflg(i)) then
4345 ! print *, ' deep delhbar, delqbar, deltbar = ',
4346 ! & delhbar(i),hvap*delqbar(i),cp*deltbar(i)
4347 ! print *, ' deep delubar, delvbar = ',delubar(i),delvbar(i)
4348 ! print *, ' precip =', hvap*rn(i)*1000./dt2
4349 ! print*,'pdif= ',pfld(i,kbcon(i))-pfld(i,ktcon(i))
4353 !c precipitation rate converted to actual precip
4354 !c in unit of m instead of kg
4359 !c in the event of upper level rain evaporation and lower level downdraft
4360 !c moistening, rn can become negative, in this case, we back out of the
4361 !c heating and the moistening
4363 if(rn(i).lt.0..and..not.flg(i)) rn(i) = 0.
4364 if(rn(i).le.0.) then
4377 if (ncloud.gt.0) then
4383 if (cnvflg(i) .and. rn(i).gt.0.) then
4384 if (k.gt.kb(i).and.k.le.ktcon(i)) then
4385 tem = dellal(i,k) * xmb(i) * dt2
4386 tem1 = max(val2, min(val1, (tcr-t1(i,k))*tcrf))
4387 if (ql(i,k,2) .gt. -999.0) then
4388 ql(i,k,1) = ql(i,k,1) + tem * tem1 ! ice
4389 ql(i,k,2) = ql(i,k,2) + tem *(1.0-tem1) ! water
4391 ql(i,k,1) = ql(i,k,1) + tem
4402 if(cnvflg(i).and.rn(i).le.0.) then
4403 if (k .le. kmax(i)) then
4413 ! hchuang code change
4417 ! if(cnvflg(i).and.rn(i).gt.0.) then
4418 ! if(k.ge.kb(i) .and. k.lt.ktop(i)) then
4419 ! ud_mf(i,k) = eta(i,k) * xmb(i) * dt2
4425 ! if(cnvflg(i).and.rn(i).gt.0.) then
4427 ! dt_mf(i,k) = ud_mf(i,k)
4432 ! if(cnvflg(i).and.rn(i).gt.0.) then
4433 ! if(k.ge.1 .and. k.le.jmin(i)) then
4434 ! dd_mf(i,k) = edto(i) * etad(i,k) * xmb(i) * dt2
4441 end subroutine sascnvn
4443 subroutine shalcnv(im,ix,km,jcap,delt,del,prsl,ps,phil,ql, &
4444 & q1,t1,u1,v1,rcs,rn,kbot,ktop,kcnv,slimsk, &
4445 & dot,ncloud,hpbl,heat,evap,pgcon)
4447 use MODULE_GFS_machine , only : kind_phys
4448 use MODULE_GFS_funcphys , only : fpvs
4449 use MODULE_GFS_physcons, grav => con_g, cp => con_cp, hvap => con_hvap &
4450 &, rv => con_rv, fv => con_fvirt, t0c => con_t0c &
4451 &, rd => con_rd, cvap => con_cvap, cliq => con_cliq &
4452 &, eps => con_eps, epsm1 => con_epsm1
4455 integer im, ix, km, jcap, ncloud, &
4456 & kbot(im), ktop(im), kcnv(im)
4457 real(kind=kind_phys) delt
4458 real(kind=kind_phys) ps(im), del(ix,km), prsl(ix,km), &
4459 & ql(ix,km,2),q1(ix,km), t1(ix,km), &
4460 & u1(ix,km), v1(ix,km), rcs(im), &
4461 & rn(im), slimsk(im), &
4462 & dot(ix,km), phil(ix,km), hpbl(im), &
4463 & heat(im), evap(im)
4464 ! &, ud_mf(im,km),dt_mf(im,km)
4466 real ud_mf(im,km),dt_mf(im,km)
4468 integer i,j,indx, jmn, k, kk, latd, lond, km1
4471 real(kind=kind_phys) c0, cpoel, dellat, delta, &
4472 & desdt, deta, detad, dg, &
4473 & dh, dhh, dlnsig, dp, &
4474 & dq, dqsdp, dqsdt, dt, &
4475 & dt2, dtmax, dtmin, dv1h, &
4476 & dv1q, dv2h, dv2q, dv1u, &
4477 & dv1v, dv2u, dv2v, dv3q, &
4478 & dv3h, dv3u, dv3v, clam, &
4480 & el2orc, elocp, aafac, cthk, &
4481 & es, etah, h1, dthk, &
4482 & evef, evfact, evfactl, fact1, &
4483 & fact2, factor, fjcap, &
4484 & g, gamma, pprime, betaw, &
4485 & qlk, qrch, qs, c1, &
4486 & rain, rfact, shear, tem1, &
4487 & tem2, terr, val, val1, &
4488 & val2, w1, w1l, w1s, &
4489 & w2, w2l, w2s, w3, &
4490 & w3l, w3s, w4, w4l, &
4491 & w4s, tem, ptem, ptem1, &
4494 integer kb(im), kbcon(im), kbcon1(im), &
4495 & ktcon(im), ktcon1(im), &
4498 real(kind=kind_phys) aa1(im), &
4499 & delhbar(im), delq(im), delq2(im), &
4500 & delqbar(im), delqev(im), deltbar(im), &
4501 & deltv(im), edt(im), &
4502 & wstar(im), sflx(im), &
4503 & pdot(im), po(im,km), &
4504 & qcond(im), qevap(im), hmax(im), &
4505 & rntot(im), vshear(im), &
4506 & xlamud(im), xmb(im), xmbmax(im), &
4507 & delubar(im), delvbar(im)
4509 real(kind=kind_phys) cincr, cincrmax, cincrmin
4511 !c physical parameters
4513 parameter(cpoel=cp/hvap,elocp=hvap/cp, &
4514 & el2orc=hvap*hvap/(rv*cp))
4515 parameter(terr=0.,c0=.002,c1=5.e-4,delta=fv)
4516 parameter(fact1=(cvap-cliq)/rv,fact2=hvap/rv-fact1*t0c)
4517 parameter(cthk=50.,cincrmax=180.,cincrmin=120.,dthk=25.)
4518 parameter(h1=0.33333333)
4519 !c local variables and arrays
4520 real(kind=kind_phys) pfld(im,km), to(im,km), qo(im,km), &
4521 & uo(im,km), vo(im,km), qeso(im,km)
4523 real(kind=kind_phys) qlko_ktcon(im), dellal(im,km), &
4524 & dbyo(im,km), zo(im,km), xlamue(im,km), &
4525 & heo(im,km), heso(im,km), &
4526 & dellah(im,km), dellaq(im,km), &
4527 & dellau(im,km), dellav(im,km), hcko(im,km), &
4528 & ucko(im,km), vcko(im,km), qcko(im,km), &
4529 & eta(im,km), zi(im,km), pwo(im,km), &
4532 logical totflg, cnvflg(im), flg(im)
4534 real(kind=kind_phys) tf, tcr, tcrf
4535 parameter (tf=233.16, tcr=263.16, tcrf=1.0/(tcr-tf))
4537 !c-----------------------------------------------------------------------
4541 !c compute surface buoyancy flux
4544 sflx(i) = heat(i)+fv*t1(i,1)*evap(i)
4547 !c initialize arrays
4551 if(kcnv(i).eq.1) cnvflg(i) = .false.
4552 if(sflx(i).le.0.) cnvflg(i) = .false.
4567 ! hchuang code change
4577 totflg = totflg .and. (.not. cnvflg(i))
4584 dtmin = max(dt2, val )
4586 dtmax = max(dt2, val )
4587 !c model tunable parameters are all here
4595 fjcap = (float(jcap) / 126.) ** 2
4597 fjcap = max(fjcap,val)
4607 !c define top layer for search of the downdraft originating layer
4608 !c and the maximum thetae for updraft
4613 tx1(i) = 1.0 / ps(i)
4618 if (prsl(i,k)*tx1(i) .gt. 0.70) kbm(i) = k + 1
4619 if (prsl(i,k)*tx1(i) .gt. 0.60) kmax(i) = k + 1
4623 kbm(i) = min(kbm(i),kmax(i))
4626 !!c hydrostatic height assume zero terr and compute
4627 !c updraft entrainment rate as an inverse function of height
4631 zo(i,k) = phil(i,k) / g
4636 zi(i,k) = 0.5*(zo(i,k)+zo(i,k+1))
4637 xlamue(i,k) = clam / zi(i,k)
4641 xlamue(i,km) = xlamue(i,km1)
4652 if (flg(i).and.zo(i,k).le.hpbl(i)) then
4660 kpbl(i)= min(kpbl(i),kbm(i))
4663 !c!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
4664 !c convert surface pressure to mb from cb
4668 if (cnvflg(i) .and. k .le. kmax(i)) then
4669 pfld(i,k) = prsl(i,k) * 10.0
4680 uo(i,k) = u1(i,k) * rcs(i)
4681 vo(i,k) = v1(i,k) * rcs(i)
4687 !c p is pressure of the layer (mb)
4688 !c t is temperature at t-dt (k)..tn
4689 !c q is mixing ratio at t-dt (kg/kg)..qn
4690 !c to is temperature at t+dt (k)... this is after advection and turbulan
4691 !c qo is mixing ratio at t+dt (kg/kg)..q1
4695 if (cnvflg(i) .and. k .le. kmax(i)) then
4696 qeso(i,k) = 0.01 * fpvs(to(i,k)) ! fpvs is in pa
4697 qeso(i,k) = eps * qeso(i,k) / (pfld(i,k) + epsm1*qeso(i,k))
4699 qeso(i,k) = max(qeso(i,k), val1)
4701 qo(i,k) = max(qo(i,k), val2 )
4702 ! qo(i,k) = min(qo(i,k),qeso(i,k))
4703 ! tvo(i,k) = to(i,k) + delta * to(i,k) * qo(i,k)
4708 !c compute moist static energy
4712 if (cnvflg(i) .and. k .le. kmax(i)) then
4713 ! tem = g * zo(i,k) + cp * to(i,k)
4714 tem = phil(i,k) + cp * to(i,k)
4715 heo(i,k) = tem + hvap * qo(i,k)
4716 heso(i,k) = tem + hvap * qeso(i,k)
4717 !c heo(i,k) = min(heo(i,k),heso(i,k))
4722 !c determine level with largest moist static energy within pbl
4723 !c this is the level where updraft starts
4733 if (cnvflg(i).and.k.le.kpbl(i)) then
4734 if(heo(i,k).gt.hmax(i)) then
4744 if (cnvflg(i) .and. k .le. kmax(i)-1) then
4745 dz = .5 * (zo(i,k+1) - zo(i,k))
4746 dp = .5 * (pfld(i,k+1) - pfld(i,k))
4747 es = 0.01 * fpvs(to(i,k+1)) ! fpvs is in pa
4748 pprime = pfld(i,k+1) + epsm1 * es
4749 qs = eps * es / pprime
4750 dqsdp = - qs / pprime
4751 desdt = es * (fact1 / to(i,k+1) + fact2 / (to(i,k+1)**2))
4752 dqsdt = qs * pfld(i,k+1) * desdt / (es * pprime)
4753 gamma = el2orc * qeso(i,k+1) / (to(i,k+1)**2)
4754 dt = (g * dz + hvap * dqsdp * dp) / (cp * (1. + gamma))
4755 dq = dqsdt * dt + dqsdp * dp
4756 to(i,k) = to(i,k+1) + dt
4757 qo(i,k) = qo(i,k+1) + dq
4758 po(i,k) = .5 * (pfld(i,k) + pfld(i,k+1))
4765 if (cnvflg(i) .and. k .le. kmax(i)-1) then
4766 qeso(i,k) = 0.01 * fpvs(to(i,k)) ! fpvs is in pa
4767 qeso(i,k) = eps * qeso(i,k) / (po(i,k) + epsm1*qeso(i,k))
4769 qeso(i,k) = max(qeso(i,k), val1)
4771 qo(i,k) = max(qo(i,k), val2 )
4772 ! qo(i,k) = min(qo(i,k),qeso(i,k))
4773 heo(i,k) = .5 * g * (zo(i,k) + zo(i,k+1)) + &
4774 & cp * to(i,k) + hvap * qo(i,k)
4775 heso(i,k) = .5 * g * (zo(i,k) + zo(i,k+1)) + &
4776 & cp * to(i,k) + hvap * qeso(i,k)
4777 uo(i,k) = .5 * (uo(i,k) + uo(i,k+1))
4778 vo(i,k) = .5 * (vo(i,k) + vo(i,k+1))
4783 !c look for the level of free convection as cloud base
4787 if(flg(i)) kbcon(i) = kmax(i)
4791 if (flg(i).and.k.lt.kbm(i)) then
4792 if(k.gt.kb(i).and.heo(i,kb(i)).gt.heso(i,k)) then
4802 if(kbcon(i).eq.kmax(i)) cnvflg(i) = .false.
4808 totflg = totflg .and. (.not. cnvflg(i))
4813 !c determine critical convective inhibition
4814 !c as a function of vertical velocity at cloud base.
4818 pdot(i) = 10.* dot(i,kbcon(i))
4823 if(slimsk(i).eq.1.) then
4834 if(pdot(i).le.w4) then
4835 ptem = (pdot(i) - w4) / (w3 - w4)
4836 elseif(pdot(i).ge.-w4) then
4837 ptem = - (pdot(i) + w4) / (w4 - w3)
4842 ptem = max(ptem,val1)
4844 ptem = min(ptem,val2)
4846 ptem1= .5*(cincrmax-cincrmin)
4847 cincr = cincrmax - ptem * ptem1
4848 tem1 = pfld(i,kb(i)) - pfld(i,kbcon(i))
4849 if(tem1.gt.cincr) then
4857 totflg = totflg .and. (.not. cnvflg(i))
4862 !c assume the detrainment rate for the updrafts to be same as
4863 !c the entrainment rate at cloud base
4867 xlamud(i) = xlamue(i,kbcon(i))
4871 !c determine updraft mass flux for the subcloud layers
4876 if(k.lt.kbcon(i).and.k.ge.kb(i)) then
4877 dz = zi(i,k+1) - zi(i,k)
4878 ptem = 0.5*(xlamue(i,k)+xlamue(i,k+1))-xlamud(i)
4879 eta(i,k) = eta(i,k+1) / (1. + ptem * dz)
4885 !c compute mass flux above cloud base
4890 if(k.gt.kbcon(i).and.k.lt.kmax(i)) then
4891 dz = zi(i,k) - zi(i,k-1)
4892 ptem = 0.5*(xlamue(i,k)+xlamue(i,k-1))-xlamud(i)
4893 eta(i,k) = eta(i,k-1) * (1 + ptem * dz)
4899 !c compute updraft cloud property
4904 hcko(i,indx) = heo(i,indx)
4905 ucko(i,indx) = uo(i,indx)
4906 vcko(i,indx) = vo(i,indx)
4913 if(k.gt.kb(i).and.k.lt.kmax(i)) then
4914 dz = zi(i,k) - zi(i,k-1)
4915 tem = 0.5 * (xlamue(i,k)+xlamue(i,k-1)) * dz
4916 tem1 = 0.5 * xlamud(i) * dz
4917 factor = 1. + tem - tem1
4918 ptem = 0.5 * tem + pgcon
4919 ptem1= 0.5 * tem - pgcon
4920 hcko(i,k) = ((1.-tem1)*hcko(i,k-1)+tem*0.5* &
4921 & (heo(i,k)+heo(i,k-1)))/factor
4922 ucko(i,k) = ((1.-tem1)*ucko(i,k-1)+ptem*uo(i,k) &
4923 & +ptem1*uo(i,k-1))/factor
4924 vcko(i,k) = ((1.-tem1)*vcko(i,k-1)+ptem*vo(i,k) &
4925 & +ptem1*vo(i,k-1))/factor
4926 dbyo(i,k) = hcko(i,k) - heso(i,k)
4932 !c taking account into convection inhibition due to existence of
4933 !c dry layers below cloud base
4941 if (flg(i).and.k.lt.kbm(i)) then
4942 if(k.ge.kbcon(i).and.dbyo(i,k).gt.0.) then
4951 if(kbcon1(i).eq.kmax(i)) cnvflg(i) = .false.
4956 tem = pfld(i,kbcon(i)) - pfld(i,kbcon1(i))
4957 if(tem.gt.dthk) then
4965 totflg = totflg .and. (.not. cnvflg(i))
4970 !c determine first guess cloud top as the level of zero buoyancy
4971 !c limited to the level of sigma=0.7
4975 if(flg(i)) ktcon(i) = kbm(i)
4979 if (flg(i).and.k .lt. kbm(i)) then
4980 if(k.gt.kbcon1(i).and.dbyo(i,k).lt.0.) then
4988 !c turn off shallow convection if cloud top is less than pbl top
4993 if(ktcon(i).le.kk) cnvflg(i) = .false.
4997 ! c turn off shallow convection if cloud depth is less than
4998 ! c a threshold value (cthk)
5002 tem = pfld(i,kbcon(i))-pfld(i,ktcon(i))
5003 if(tem.lt.cthk) cnvflg(i) = .false.
5009 totflg = totflg .and. (.not. cnvflg(i))
5014 !c specify upper limit of mass flux at cloud base
5021 dp = 1000. * del(i,k)
5022 xmbmax(i) = dp / (g * dt2)
5024 ! tem = dp / (g * dt2)
5025 ! xmbmax(i) = min(tem, xmbmax(i))
5029 !c compute cloud moisture property and precipitation
5034 qcko(i,kb(i)) = qo(i,kb(i))
5040 if(k.gt.kb(i).and.k.lt.ktcon(i)) then
5041 dz = zi(i,k) - zi(i,k-1)
5042 gamma = el2orc * qeso(i,k) / (to(i,k)**2)
5044 & + gamma * dbyo(i,k) / (hvap * (1. + gamma))
5046 tem = 0.5 * (xlamue(i,k)+xlamue(i,k-1)) * dz
5047 tem1 = 0.5 * xlamud(i) * dz
5048 factor = 1. + tem - tem1
5049 qcko(i,k) = ((1.-tem1)*qcko(i,k-1)+tem*0.5* &
5050 & (qo(i,k)+qo(i,k-1)))/factor
5052 dq = eta(i,k) * (qcko(i,k) - qrch)
5054 ! rhbar(i) = rhbar(i) + qo(i,k) / qeso(i,k)
5056 !c below lfc check if there is excess moisture to release latent heat
5058 if(k.ge.kbcon(i).and.dq.gt.0.) then
5059 etah = .5 * (eta(i,k) + eta(i,k-1))
5060 if(ncloud.gt.0.) then
5061 dp = 1000. * del(i,k)
5062 qlk = dq / (eta(i,k) + etah * (c0 + c1) * dz)
5063 dellal(i,k) = etah * c1 * dz * qlk * g / dp
5065 qlk = dq / (eta(i,k) + etah * c0 * dz)
5067 aa1(i) = aa1(i) - dz * g * qlk
5068 qcko(i,k)= qlk + qrch
5069 pwo(i,k) = etah * c0 * dz * qlk
5076 !c calculate cloud work function
5081 if(k.ge.kbcon(i).and.k.lt.ktcon(i)) then
5082 dz1 = zo(i,k+1) - zo(i,k)
5083 gamma = el2orc * qeso(i,k) / (to(i,k)**2)
5084 rfact = 1. + delta * cp * gamma &
5087 & dz1 * (g / (cp * to(i,k))) &
5088 & * dbyo(i,k) / (1. + gamma) &
5092 & dz1 * g * delta * &
5093 & max(val,(qeso(i,k) - qo(i,k)))
5099 if(cnvflg(i).and.aa1(i).le.0.) cnvflg(i) = .false.
5104 totflg = totflg .and. (.not. cnvflg(i))
5109 !c estimate the onvective overshooting as the level
5110 !c where the [aafac * cloud work function] becomes zero,
5111 !c which is the final cloud top
5112 !c limited to the level of sigma=0.7
5116 aa1(i) = aafac * aa1(i)
5127 if(k.ge.ktcon(i).and.k.lt.kbm(i)) then
5128 dz1 = zo(i,k+1) - zo(i,k)
5129 gamma = el2orc * qeso(i,k) / (to(i,k)**2)
5130 rfact = 1. + delta * cp * gamma &
5133 & dz1 * (g / (cp * to(i,k))) &
5134 & * dbyo(i,k) / (1. + gamma) &
5136 if(aa1(i).lt.0.) then
5145 !c compute cloud moisture property, detraining cloud water
5146 !c and precipitation in overshooting layers
5151 if(k.ge.ktcon(i).and.k.lt.ktcon1(i)) then
5152 dz = zi(i,k) - zi(i,k-1)
5153 gamma = el2orc * qeso(i,k) / (to(i,k)**2)
5155 & + gamma * dbyo(i,k) / (hvap * (1. + gamma))
5157 tem = 0.5 * (xlamue(i,k)+xlamue(i,k-1)) * dz
5158 tem1 = 0.5 * xlamud(i) * dz
5159 factor = 1. + tem - tem1
5160 qcko(i,k) = ((1.-tem1)*qcko(i,k-1)+tem*0.5* &
5161 & (qo(i,k)+qo(i,k-1)))/factor
5163 dq = eta(i,k) * (qcko(i,k) - qrch)
5165 !c check if there is excess moisture to release latent heat
5168 etah = .5 * (eta(i,k) + eta(i,k-1))
5169 if(ncloud.gt.0.) then
5170 dp = 1000. * del(i,k)
5171 qlk = dq / (eta(i,k) + etah * (c0 + c1) * dz)
5172 dellal(i,k) = etah * c1 * dz * qlk * g / dp
5174 qlk = dq / (eta(i,k) + etah * c0 * dz)
5176 qcko(i,k) = qlk + qrch
5177 pwo(i,k) = etah * c0 * dz * qlk
5184 !c exchange ktcon with ktcon1
5189 ktcon(i) = ktcon1(i)
5194 !c this section is ready for cloud water
5196 if(ncloud.gt.0) then
5198 !c compute liquid and vapor separation at cloud top
5203 gamma = el2orc * qeso(i,k) / (to(i,k)**2)
5205 & + gamma * dbyo(i,k) / (hvap * (1. + gamma))
5206 dq = qcko(i,k) - qrch
5208 !c check if there is excess moisture to release latent heat
5218 !c--- compute precipitation efficiency in terms of windshear
5228 if(k.gt.kb(i).and.k.le.ktcon(i)) then
5229 shear= sqrt((uo(i,k)-uo(i,k-1)) ** 2 &
5230 & + (vo(i,k)-vo(i,k-1)) ** 2)
5231 vshear(i) = vshear(i) + shear
5238 vshear(i) = 1.e3 * vshear(i) / (zi(i,ktcon(i))-zi(i,kb(i)))
5239 e1=1.591-.639*vshear(i) &
5240 & +.0953*(vshear(i)**2)-.00496*(vshear(i)**3)
5243 edt(i) = min(edt(i),val)
5245 edt(i) = max(edt(i),val)
5249 !c--- what would the change be, that a cloud with unit mass
5250 !c--- will do to the environment?
5254 if(cnvflg(i) .and. k .le. kmax(i)) then
5263 !c--- changed due to subsidence and entrainment
5268 if(k.gt.kb(i).and.k.lt.ktcon(i)) then
5269 dp = 1000. * del(i,k)
5270 dz = zi(i,k) - zi(i,k-1)
5273 dv2h = .5 * (heo(i,k) + heo(i,k-1))
5276 dv2q = .5 * (qo(i,k) + qo(i,k-1))
5279 dv2u = .5 * (uo(i,k) + uo(i,k-1))
5282 dv2v = .5 * (vo(i,k) + vo(i,k-1))
5285 tem = 0.5 * (xlamue(i,k)+xlamue(i,k-1))
5288 dellah(i,k) = dellah(i,k) + &
5289 & ( eta(i,k)*dv1h - eta(i,k-1)*dv3h &
5290 & - tem*eta(i,k-1)*dv2h*dz &
5291 & + tem1*eta(i,k-1)*.5*(hcko(i,k)+hcko(i,k-1))*dz &
5294 dellaq(i,k) = dellaq(i,k) + &
5295 & ( eta(i,k)*dv1q - eta(i,k-1)*dv3q &
5296 & - tem*eta(i,k-1)*dv2q*dz &
5297 & + tem1*eta(i,k-1)*.5*(qcko(i,k)+qcko(i,k-1))*dz &
5300 dellau(i,k) = dellau(i,k) + &
5301 & ( eta(i,k)*dv1u - eta(i,k-1)*dv3u &
5302 & - tem*eta(i,k-1)*dv2u*dz &
5303 & + tem1*eta(i,k-1)*.5*(ucko(i,k)+ucko(i,k-1))*dz &
5304 & - pgcon*eta(i,k-1)*(dv1u-dv3u) &
5307 dellav(i,k) = dellav(i,k) + &
5308 & ( eta(i,k)*dv1v - eta(i,k-1)*dv3v &
5309 & - tem*eta(i,k-1)*dv2v*dz &
5310 & + tem1*eta(i,k-1)*.5*(vcko(i,k)+vcko(i,k-1))*dz &
5311 & - pgcon*eta(i,k-1)*(dv1v-dv3v) &
5324 dp = 1000. * del(i,indx)
5325 dv1h = heo(i,indx-1)
5326 dellah(i,indx) = eta(i,indx-1) * &
5327 & (hcko(i,indx-1) - dv1h) * g / dp
5329 dellaq(i,indx) = eta(i,indx-1) * &
5330 & (qcko(i,indx-1) - dv1q) * g / dp
5332 dellau(i,indx) = eta(i,indx-1) * &
5333 & (ucko(i,indx-1) - dv1u) * g / dp
5335 dellav(i,indx) = eta(i,indx-1) * &
5336 & (vcko(i,indx-1) - dv1v) * g / dp
5340 dellal(i,indx) = eta(i,indx-1) * &
5341 & qlko_ktcon(i) * g / dp
5345 !c mass flux at cloud base for shallow convection
5351 ! ptem = g*sflx(i)*zi(i,k)/t1(i,1)
5352 ptem = g*sflx(i)*hpbl(i)/t1(i,1)
5354 tem = po(i,k)*100. / (rd*t1(i,k))
5355 xmb(i) = betaw*tem*wstar(i)
5356 xmb(i) = min(xmb(i),xmbmax(i))
5360 !c!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
5364 if (cnvflg(i) .and. k .le. kmax(i)) then
5365 qeso(i,k) = 0.01 * fpvs(t1(i,k)) ! fpvs is in pa
5366 qeso(i,k) = eps * qeso(i,k) / (pfld(i,k) + epsm1*qeso(i,k))
5368 qeso(i,k) = max(qeso(i,k), val )
5372 !c!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
5385 if(k.gt.kb(i).and.k.le.ktcon(i)) then
5386 dellat = (dellah(i,k) - hvap * dellaq(i,k)) / cp
5387 t1(i,k) = t1(i,k) + dellat * xmb(i) * dt2
5388 q1(i,k) = q1(i,k) + dellaq(i,k) * xmb(i) * dt2
5390 u1(i,k) = u1(i,k) + dellau(i,k) * xmb(i) * dt2 * tem
5391 v1(i,k) = v1(i,k) + dellav(i,k) * xmb(i) * dt2 * tem
5392 dp = 1000. * del(i,k)
5393 delhbar(i) = delhbar(i) + dellah(i,k)*xmb(i)*dp/g
5394 delqbar(i) = delqbar(i) + dellaq(i,k)*xmb(i)*dp/g
5395 deltbar(i) = deltbar(i) + dellat*xmb(i)*dp/g
5396 delubar(i) = delubar(i) + dellau(i,k)*xmb(i)*dp/g
5397 delvbar(i) = delvbar(i) + dellav(i,k)*xmb(i)*dp/g
5405 if(k.gt.kb(i).and.k.le.ktcon(i)) then
5406 qeso(i,k) = 0.01 * fpvs(t1(i,k)) ! fpvs is in pa
5407 qeso(i,k) = eps * qeso(i,k)/(pfld(i,k) + epsm1*qeso(i,k))
5409 qeso(i,k) = max(qeso(i,k), val )
5424 if(k.lt.ktcon(i).and.k.gt.kb(i)) then
5425 rntot(i) = rntot(i) + pwo(i,k) * xmb(i) * .001 * dt2
5435 if (k .le. kmax(i)) then
5440 if(k.lt.ktcon(i).and.k.gt.kb(i)) then
5441 rn(i) = rn(i) + pwo(i,k) * xmb(i) * .001 * dt2
5444 if(flg(i).and.k.lt.ktcon(i)) then
5445 evef = edt(i) * evfact
5446 if(slimsk(i).eq.1.) evef=edt(i) * evfactl
5447 ! if(slimsk(i).eq.1.) evef=.07
5448 !c if(slimsk(i).ne.1.) evef = 0.
5449 qcond(i) = evef * (q1(i,k) - qeso(i,k)) &
5450 & / (1. + el2orc * qeso(i,k) / t1(i,k)**2)
5451 dp = 1000. * del(i,k)
5452 if(rn(i).gt.0..and.qcond(i).lt.0.) then
5453 qevap(i) = -qcond(i) * (1.-exp(-.32*sqrt(dt2*rn(i))))
5454 qevap(i) = min(qevap(i), rn(i)*1000.*g/dp)
5455 delq2(i) = delqev(i) + .001 * qevap(i) * dp / g
5457 if(rn(i).gt.0..and.qcond(i).lt.0..and. &
5458 & delq2(i).gt.rntot(i)) then
5459 qevap(i) = 1000.* g * (rntot(i) - delqev(i)) / dp
5462 if(rn(i).gt.0..and.qevap(i).gt.0.) then
5464 tem1 = qevap(i) * tem
5465 if(tem1.gt.rn(i)) then
5466 qevap(i) = rn(i) / tem
5469 rn(i) = rn(i) - tem1
5471 q1(i,k) = q1(i,k) + qevap(i)
5472 t1(i,k) = t1(i,k) - elocp * qevap(i)
5473 deltv(i) = - elocp*qevap(i)/dt2
5474 delq(i) = + qevap(i)/dt2
5475 delqev(i) = delqev(i) + .001*dp*qevap(i)/g
5477 dellaq(i,k) = dellaq(i,k) + delq(i) / xmb(i)
5478 delqbar(i) = delqbar(i) + delq(i)*dp/g
5479 deltbar(i) = deltbar(i) + deltv(i)*dp/g
5486 ! if(me.eq.31.and.cnvflg(i)) then
5487 ! if(cnvflg(i)) then
5488 ! print *, ' shallow delhbar, delqbar, deltbar = ',
5489 ! & delhbar(i),hvap*delqbar(i),cp*deltbar(i)
5490 ! print *, ' shallow delubar, delvbar = ',delubar(i),delvbar(i)
5491 ! print *, ' precip =', hvap*rn(i)*1000./dt2
5492 ! print*,'pdif= ',pfld(i,kbcon(i))-pfld(i,ktcon(i))
5498 if(rn(i).lt.0..or..not.flg(i)) rn(i) = 0.
5507 if (ncloud.gt.0) then
5514 if (k.gt.kb(i).and.k.le.ktcon(i)) then
5515 tem = dellal(i,k) * xmb(i) * dt2
5516 ! tem1 = max(0.0, min(1.0, (tcr-t1(i,k))*tcrf))
5517 tem1 = max(val2, min(val1, (tcr-t1(i,k))*tcrf))
5518 if (ql(i,k,2) .gt. -999.0) then
5519 ql(i,k,1) = ql(i,k,1) + tem * tem1 ! ice
5520 ql(i,k,2) = ql(i,k,2) + tem *(1.0-tem1) ! water
5522 ql(i,k,1) = ql(i,k,1) + tem
5531 ! hchuang code change
5536 if(k.ge.kb(i) .and. k.lt.ktop(i)) then
5537 ud_mf(i,k) = eta(i,k) * xmb(i) * dt2
5545 dt_mf(i,k) = ud_mf(i,k)
5550 end subroutine shalcnv
5551 END MODULE module_cu_sas
5555 integer idum,ia,im,iq,ir,ntab,ndiv
5558 parameter (ia=16807,im=2147483647,am=1./im,iq=127773,ir=2836, &
5559 & ntab=32,ndiv=1+(im-1)/ntab,eps=1.2e-7,rnmx=1.-eps)
5560 integer j,k,iv(32),iy,junk
5561 common /random/ junk,iv,iy
5562 data iv /ntab*0/, iy /0/
5563 if (idum.le.0.or.iy.eq.0) then
5567 idum=ia*(idum-k*iq)-ir*k
5568 if (idum.lt.0) idum=idum+im
5569 if (j.le.ntab) iv(j)=idum
5574 idum=ia*(idum-k*iq)-ir*k
5575 if (idum.lt.0) idum=idum+im
5579 ran1=min(am*iy,rnmx)
5583 FUNCTION gasdev(idum)
5588 REAL*8 fac,gset,rsq,v1,v2,ran1
5592 1 v1=2.*ran1(idum)-1.
5595 if(rsq.ge.1..or.rsq.eq.0.)goto 1
5596 fac=sqrt(-2.*log(rsq)/rsq)