1 !WRF:MODEL_LAYER:PHYSICS
8 !-------------------------------------------------------------
13 ,dz8w,p8w,XLV,CP,G,r_v &
14 ,htop,hbot,ktop_deep &
15 ,CU_ACT_FLAG,warm_rain &
16 ,APR_GR,APR_W,APR_MC,APR_ST,APR_AS &
17 ,APR_CAPMA,APR_CAPME,APR_CAPMI &
18 ,MASS_FLUX,XF_ENS,PR_ENS,HT,XLAND,gsw &
20 ,ensdim,maxiens,maxens,maxens2,maxens3 &
21 ,ids,ide, jds,jde, kds,kde &
22 ,ims,ime, jms,jme, kms,kme &
23 ,its,ite, jts,jte, kts,kte &
24 ,periodic_x,periodic_y &
25 ,RQVCUTEN,RQCCUTEN,RQICUTEN &
27 ,RTHFTEN,RTHCUTEN,RTHRATEN,RTHBLTEN &
28 ,F_QV ,F_QC ,F_QR ,F_QI ,F_QS &
29 ,CFU1,CFD1,DFU1,EFU1,DFD1,EFD1,f_flux )
31 !-------------------------------------------------------------
33 !-------------------------------------------------------------
34 INTEGER, INTENT(IN ) :: &
35 ids,ide, jds,jde, kds,kde, &
36 ims,ime, jms,jme, kms,kme, &
37 its,ite, jts,jte, kts,kte
38 LOGICAL periodic_x,periodic_y
40 integer, intent (in ) :: &
41 ensdim,maxiens,maxens,maxens2,maxens3
43 INTEGER, INTENT(IN ) :: ITIMESTEP
44 LOGICAL, INTENT(IN ) :: warm_rain
46 REAL, INTENT(IN ) :: XLV, R_v
47 REAL, INTENT(IN ) :: CP,G
49 REAL, DIMENSION( ims:ime , kms:kme , jms:jme ) , &
61 REAL, DIMENSION( ims:ime , kms:kme , jms:jme ) , &
67 REAL, DIMENSION( ims:ime , jms:jme ),INTENT(IN) :: GSW,HT,XLAND
69 REAL, INTENT(IN ) :: DT, DX
72 REAL, DIMENSION( ims:ime , jms:jme ), &
73 INTENT(INOUT) :: RAINCV, PRATEC, MASS_FLUX, &
74 APR_GR,APR_W,APR_MC,APR_ST,APR_AS, &
75 APR_CAPMA,APR_CAPME,APR_CAPMI,htop,hbot
77 ! REAL, DIMENSION( ims:ime , jms:jme ) :: & !, INTENT(INOUT) :: &
78 ! HTOP, &! highest model layer penetrated by cumulus since last reset in radiation_driver
79 ! HBOT ! lowest model layer penetrated by cumulus since last reset in radiation_driver
80 ! ! HBOT>HTOP follow physics leveling convention
82 LOGICAL, DIMENSION( ims:ime , jms:jme ), &
83 INTENT(INOUT) :: CU_ACT_FLAG
88 INTEGER, DIMENSION( ims:ime, jms:jme ), &
90 INTENT( OUT) :: ktop_deep
92 REAL, DIMENSION( ims:ime , kms:kme , jms:jme ), &
94 INTENT(INOUT) :: RTHFTEN, &
97 REAL, DIMENSION( ims:ime , kms:kme , jms:jme ), &
103 REAL, DIMENSION( ims:ime , kms:kme , jms:jme ), &
110 REAL, DIMENSION( ims:ime , kms:kme , jms:jme ), &
120 ! Flags relating to the optional tendency arrays declared above
121 ! Models that carry the optional tendencies will provdide the
122 ! optional arguments at compile time; these flags all the model
123 ! to determine at run-time whether a particular tracer is in
126 LOGICAL, OPTIONAL :: &
132 LOGICAL, intent(in), OPTIONAL :: f_flux
137 real, dimension ( ims:ime , jms:jme , 1:ensdim) :: &
138 massfln,xf_ens,pr_ens
139 real, dimension (its:ite,kts:kte+1) :: &
140 OUTT,OUTQ,OUTQC,phh,cupclw, &
141 outCFU1,outCFD1,outDFU1,outEFU1,outDFD1,outEFD1
143 real, dimension (its:ite) :: &
146 integer, dimension (its:ite) :: &
149 integer, dimension (its:ite,jts:jte) :: &
151 integer :: ichoice,iens,ibeg,iend,jbeg,jend
154 ! basic environmental input includes moisture convergence (mconv)
155 ! omega (omeg), windspeed (us,vs), and a flag (aaeq) to turn off
156 ! convection for this call only and at that particular gridpoint
158 real, dimension (its:ite,kts:kte+1) :: &
159 T2d,TN,q2d,qo,PO,P2d,US,VS,omeg
160 real, dimension (its:ite) :: &
161 Z1,PSUR,AAEQ,direction,mconv,cuten,umean,vmean,pmean
163 INTEGER :: i,j,k,ICLDCK,ipr,jpr
165 INTEGER :: itf,jtf,ktf
166 REAL :: rkbcon,rktop !-lxz
169 if (present(f_flux)) l_flux=f_flux
171 l_flux = l_flux .and. present(cfu1) .and. present(cfd1) &
172 .and. present(dfu1) .and. present(efu1) &
173 .and. present(dfd1) .and. present(efd1)
181 IF ( periodic_x ) THEN
188 IF ( periodic_y ) THEN
210 CU_ACT_FLAG(i,j) = .true.
221 RTHFTEN(i,k,j)=(RTHFTEN(i,k,j)+RTHRATEN(i,k,j)+RTHBLTEN(i,k,j))*pi(i,k,j)
222 RQVFTEN(i,k,j)=RQVFTEN(i,k,j)+RQVBLTEN(i,k,j)
226 ! put hydrostatic pressure on half levels
233 PSUR(I)=p8w(I,1,J)*.01
253 omeg(I,K)= -g*rho(i,k,j)*w(i,k,j)
254 TN(I,K)=t2d(i,k)+RTHFTEN(i,k,j)*dt
255 IF(TN(I,K).LT.200.)TN(I,K)=T2d(I,K)
256 QO(I,K)=q2d(i,k)+RQVFTEN(i,k,j)*dt
257 IF(Q2d(I,K).LT.1.E-08)Q2d(I,K)=1.E-08
258 IF(QO(I,K).LT.1.E-08)QO(I,K)=1.E-08
268 if((p2d(i,1)-p2d(i,k)).gt.150.and.p2d(i,k).gt.300)then
269 dp=-.5*(p2d(i,k+1)-p2d(i,k-1))
270 umean(i)=umean(i)+us(i,k)*dp
271 vmean(i)=vmean(i)+vs(i,k)*dp
277 if(pmean(i).gt.0)then
278 umean(i)=umean(i)/pmean(i)
279 vmean(i)=vmean(i)/pmean(i)
280 direction(i)=(atan2(umean(i),vmean(i))+3.1415926)*57.29578
281 if(direction(i).gt.360.)direction(i)=direction(i)-360.
286 dq=(q2d(i,k+1)-q2d(i,k))
287 mconv(i)=mconv(i)+omeg(i,k)*dq/g
291 if(mconv(i).lt.0.)mconv(i)=0.
294 !---- CALL CUMULUS PARAMETERIZATION
296 CALL CUP_enss(outqc,j,AAEQ,T2d,Q2d,TER11,TN,QO,PO,PRET, &
297 P2d,OUTT,OUTQ,DT,PSUR,US,VS,tcrit,iens, &
298 mconv,massfln,iact_old_gr,omeg,direction,MASS_FLUX, &
299 maxiens,maxens,maxens2,maxens3,ensdim, &
300 APR_GR,APR_W,APR_MC,APR_ST,APR_AS, &
301 APR_CAPMA,APR_CAPME,APR_CAPMI,kbcon,ktop, &
302 xf_ens,pr_ens,XLAND,gsw,cupclw, &
303 xlv,r_v,cp,g,ichoice,ipr,jpr, &
304 outCFU1,outCFD1,outDFU1,outEFU1,outDFD1,outEFD1,l_flux,&
305 ids,ide, jds,jde, kds,kde, &
306 ims,ime, jms,jme, kms,kme, &
307 its,ite, jts,jte, kts,kte )
309 CALL neg_check(dt,q2d,outq,outt,outqc,pret,its,ite,kts,kte,itf,ktf)
310 if(j.ge.jbeg.and.j.le.jend)then
314 ktop_deep(i,j) = ktop(i)
315 if(i.ge.ibeg.and.i.le.iend)then
316 if(pret(i).gt.0.)then
318 raincv(i,j)=pret(i)*dt
320 rkbcon = kte+kts - kbcon(i)
321 rktop = kte+kts - ktop(i)
322 if (ktop(i) > HTOP(i,j)) HTOP(i,j) = ktop(i)+.001
323 if (kbcon(i) < HBOT(i,j)) HBOT(i,j) = kbcon(i)+.001
331 RTHCUTEN(I,K,J)=outt(i,k)*cuten(i)/pi(i,k,j)
332 RQVCUTEN(I,K,J)=outq(i,k)*cuten(i)
336 IF(PRESENT(RQCCUTEN)) THEN
340 RQCCUTEN(I,K,J)=outqc(I,K)*cuten(i)
341 IF ( PRESENT( GDC ) ) GDC(I,K,J)=CUPCLW(I,K)*cuten(i)
342 IF ( PRESENT( GDC2 ) ) GDC2(I,K,J)=0.
348 !...... QSTEN STORES GRAUPEL TENDENCY IF IT EXISTS, OTHERISE SNOW (V2)
350 IF(PRESENT(RQICUTEN).AND.PRESENT(RQCCUTEN))THEN
354 if(t2d(i,k).lt.258.)then
355 RQICUTEN(I,K,J)=outqc(I,K)*cuten(i)
357 IF ( PRESENT( GDC2 ) ) GDC2(I,K,J)=CUPCLW(I,K)*cuten(i)
360 RQCCUTEN(I,K,J)=outqc(I,K)*cuten(i)
361 IF ( PRESENT( GDC ) ) GDC(I,K,J)=CUPCLW(I,K)*cuten(i)
371 cfu1(i,k,j)=outcfu1(i,k)*cuten(i)
372 cfd1(i,k,j)=outcfd1(i,k)*cuten(i)
373 dfu1(i,k,j)=outdfu1(i,k)*cuten(i)
374 efu1(i,k,j)=outefu1(i,k)*cuten(i)
375 dfd1(i,k,j)=outdfd1(i,k)*cuten(i)
376 efd1(i,k,j)=outefd1(i,k)*cuten(i)
384 END SUBROUTINE GRELLDRV
387 SUBROUTINE CUP_enss(OUTQC,J,AAEQ,T,Q,Z1, &
388 TN,QO,PO,PRE,P,OUTT,OUTQ,DTIME,PSUR,US,VS, &
389 TCRIT,iens,mconv,massfln,iact, &
390 omeg,direction,massflx,maxiens, &
391 maxens,maxens2,maxens3,ensdim, &
392 APR_GR,APR_W,APR_MC,APR_ST,APR_AS, &
393 APR_CAPMA,APR_CAPME,APR_CAPMI,kbcon,ktop, & !-lxz
394 xf_ens,pr_ens,xland,gsw,cupclw, &
395 xl,rv,cp,g,ichoice,ipr,jpr, &
396 outCFU1,outCFD1,outDFU1,outEFU1,outDFD1,outEFD1,l_flux, &
397 ids,ide, jds,jde, kds,kde, &
398 ims,ime, jms,jme, kms,kme, &
399 its,ite, jts,jte, kts,kte )
405 ids,ide, jds,jde, kds,kde, &
406 ims,ime, jms,jme, kms,kme, &
407 its,ite, jts,jte, kts,kte,ipr,jpr
408 integer, intent (in ) :: &
409 j,ensdim,maxiens,maxens,maxens2,maxens3,ichoice,iens
413 real, dimension (ims:ime,jms:jme,1:ensdim) &
415 massfln,xf_ens,pr_ens
416 real, dimension (ims:ime,jms:jme) &
417 ,intent (inout ) :: &
418 APR_GR,APR_W,APR_MC,APR_ST,APR_AS,APR_CAPMA, &
419 APR_CAPME,APR_CAPMI,massflx
420 real, dimension (ims:ime,jms:jme) &
423 integer, dimension (its:ite,jts:jte) &
426 ! outtem = output temp tendency (per s)
427 ! outq = output q tendency (per s)
428 ! outqc = output qc tendency (per s)
429 ! pre = output precip
430 real, dimension (its:ite,kts:kte) &
432 OUTT,OUTQ,OUTQC,CUPCLW, &
433 outCFU1,outCFD1,outDFU1,outEFU1,outDFD1,outEFD1
434 logical, intent(in) :: l_flux
435 real, dimension (its:ite) &
439 integer, dimension (its:ite) &
444 ! basic environmental input includes moisture convergence (mconv)
445 ! omega (omeg), windspeed (us,vs), and a flag (aaeq) to turn off
446 ! convection for this call only and at that particular gridpoint
448 real, dimension (its:ite,kts:kte) &
451 real, dimension (its:ite,kts:kte) &
454 real, dimension (its:ite) &
456 Z1,PSUR,AAEQ,direction,mconv
461 dtime,tcrit,xl,cp,rv,g
465 ! local ensemble dependent variables in this routine
467 real, dimension (its:ite,1:maxens) :: &
469 real, dimension (1:maxens) :: &
471 real, dimension (1:maxens2) :: &
473 real, dimension (its:ite,1:maxens2) :: &
475 real, dimension (its:ite,kts:kte,1:maxens2) :: &
476 dellat_ens,dellaqc_ens,dellaq_ens,pwo_ens
477 real, dimension (its:ite,kts:kte,1:maxens2) :: &
478 CFU1_ens,CFD1_ens,DFU1_ens,EFU1_ens,DFD1_ens,EFD1_ens
482 !***************** the following are your basic environmental
483 ! variables. They carry a "_cup" if they are
484 ! on model cloud levels (staggered). They carry
485 ! an "o"-ending (z becomes zo), if they are the forced
486 ! variables. They are preceded by x (z becomes xz)
487 ! to indicate modification by some typ of cloud
489 ! z = heights of model levels
490 ! q = environmental mixing ratio
491 ! qes = environmental saturation mixing ratio
492 ! t = environmental temp
493 ! p = environmental pressure
494 ! he = environmental moist static energy
495 ! hes = environmental saturation moist static energy
496 ! z_cup = heights of model cloud levels
497 ! q_cup = environmental q on model cloud levels
498 ! qes_cup = saturation q on model cloud levels
499 ! t_cup = temperature (Kelvin) on model cloud levels
500 ! p_cup = environmental pressure
501 ! he_cup = moist static energy on model cloud levels
502 ! hes_cup = saturation moist static energy on model cloud levels
503 ! gamma_cup = gamma on model cloud levels
506 ! hcd = moist static energy in downdraft
507 ! zd normalized downdraft mass flux
509 ! entr = entrainment rate
510 ! zd = downdraft normalized mass flux
511 ! entr= entrainment rate
512 ! hcd = h in model cloud
514 ! zd = normalized downdraft mass flux
515 ! gamma_cup = gamma on model cloud levels
516 ! mentr_rate = entrainment rate
517 ! qcd = cloud q (including liquid water) after entrainment
518 ! qrch = saturation q in cloud
519 ! pwd = evaporate at that level
520 ! pwev = total normalized integrated evaoprate (I2)
521 ! entr= entrainment rate
522 ! z1 = terrain elevation
523 ! entr = downdraft entrainment rate
524 ! jmin = downdraft originating level
525 ! kdet = level above ground where downdraft start detraining
526 ! psur = surface pressure
527 ! z1 = terrain elevation
528 ! pr_ens = precipitation ensemble
529 ! xf_ens = mass flux ensembles
530 ! massfln = downdraft mass flux ensembles used in next timestep
531 ! omeg = omega from large scale model
532 ! mconv = moisture convergence from large scale model
533 ! zd = downdraft normalized mass flux
534 ! zu = updraft normalized mass flux
535 ! dir = "storm motion"
536 ! mbdt = arbitrary numerical parameter
537 ! dtime = dt over which forcing is applied
538 ! iact_gr_old = flag to tell where convection was active
539 ! kbcon = LFC of parcel from k22
540 ! k22 = updraft originating level
541 ! icoic = flag if only want one closure (usually set to zero!)
543 ! ktop = cloud top (output)
544 ! xmb = total base mass flux
545 ! hc = cloud moist static energy
546 ! hkb = moist static energy at originating level
547 ! mentr_rate = entrainment rate
549 real, dimension (its:ite,kts:kte) :: &
552 xhe,xhes,xqes,xz,xt,xq, &
554 qes_cup,q_cup,he_cup,hes_cup,z_cup,p_cup,gamma_cup,t_cup, &
555 qeso_cup,qo_cup,heo_cup,heso_cup,zo_cup,po_cup,gammao_cup, &
557 xqes_cup,xq_cup,xhe_cup,xhes_cup,xz_cup,xp_cup,xgamma_cup, &
560 dby,qc,qrcd,pwd,pw,hcd,qcd,dbyd,hc,qrc,zu,zd,clw_all, &
561 dbyo,qco,qrcdo,pwdo,pwo,hcdo,qcdo,dbydo,hco,qrco,zuo,zdo, &
562 xdby,xqc,xqrcd,xpwd,xpw,xhcd,xqcd,xhc,xqrc,xzu,xzd, &
564 ! cd = detrainment function for updraft
565 ! cdd = detrainment function for downdraft
566 ! dellat = change of temperature per unit mass flux of cloud ensemble
567 ! dellaq = change of q per unit mass flux of cloud ensemble
568 ! dellaqc = change of qc per unit mass flux of cloud ensemble
570 cd,cdd,scr1,DELLAH,DELLAQ,DELLAT,DELLAQC, &
571 CFU1,CFD1,DFU1,EFU1,DFD1,EFD1
573 ! aa0 cloud work function for downdraft
575 ! aa0 = cloud work function without forcing effects
576 ! aa1 = cloud work function with forcing effects
577 ! xaa0 = cloud work function with cloud effects (ensemble dependent)
579 real, dimension (its:ite) :: &
580 edt,edto,edtx,AA1,AA0,XAA0,HKB,HKBO,aad,XHKB,QKB,QKBO, &
581 XMB,XPWAV,XPWEV,PWAV,PWEV,PWAVO,PWEVO,BU,BUO,cap_max,xland1, &
582 cap_max_increment,closure_n
583 integer, dimension (its:ite) :: &
584 kzdown,KDET,K22,KB,JMIN,kstabi,kstabm,K22x, & !-lxz
585 KBCONx,KBx,KTOPx,ierr,ierr2,ierr3,KBMAX
588 nall,iedt,nens,nens3,ki,I,K,KK,iresult
590 day,dz,mbdt,entr_rate,radius,entrd_rate,mentr_rate,mentrd_rate, &
591 zcutdown,edtmax,edtmin,depth_min,zkbmax,z_detr,zktop, &
594 integer :: itf,jtf,ktf
596 logical :: keep_going
607 if(xland(i,j).gt.1.5)xland1(i)=0.
608 cap_max_increment(i)=25.
611 !--- specify entrainmentrate and detrainmentrate
614 radius=14000.-float(iens)*2000.
619 !--- gross entrainment rate (these may be changed later on in the
620 !--- program, depending what your detrainment is!!)
624 !--- entrainment of mass
629 !--- initial detrainmentrates
634 cd(i,k)=0.1*entr_rate
639 !--- max/min allowed value for epsilon (ratio downdraft base mass flux/updraft
645 !--- minimum depth (m), clouds must have
649 !--- maximum depth (mb) of capping
650 !--- inversion (larger cap = no convection)
653 !sms$to_local(grid_dh: <1, mix :size>, <2, mjx :size>) begin
664 if(aaeq(i).lt.-1.)then
669 !--- first check for upstream convection
673 ! if(tkmax(i,j).lt.2.)cap_max(i)=25.
674 if(gsw(i,j).lt.1.)cap_max(i)=25.
678 ! call cup_direction2(i,j,direction,iact, &
679 ! cu_mfx,iresult,0,massfld, &
680 ! ids,ide, jds,jde, kds,kde, &
681 ! ims,ime, jms,jme, kms,kme, &
682 ! its,ite, jts,jte, kts,kte)
683 ! cap_max(i)=cap_maxs
685 cap_max(i)=cap_maxs+20.
690 !--- max height(m) above ground where updraft air can originate
694 !--- height(m) above which no downdrafts are allowed to originate
698 !--- depth(m) over which downdraft detrains all its mass
703 mbdt_ens(nens)=(float(nens)-3.)*dtime*1.e-3+dtime*5.E-03
706 edt_ens(nens)=.95-float(nens)*.01
709 ! print *,'radius ensemble ',iens,radius
714 !--- environmental conditions, FIRST HEIGHTS
717 if(ierr(i).ne.20)then
718 do k=1,maxens*maxens2*maxens3
719 xf_ens(i,j,(iens-1)*maxens*maxens2*maxens3+k)=0.
720 pr_ens(i,j,(iens-1)*maxens*maxens2*maxens3+k)=0.
725 !--- calculate moist static energy, heights, qes
727 call cup_env(z,qes,he,hes,t,q,p,z1, &
728 psur,ierr,tcrit,0,xl,cp, &
729 ids,ide, jds,jde, kds,kde, &
730 ims,ime, jms,jme, kms,kme, &
731 its,ite, jts,jte, kts,kte)
732 call cup_env(zo,qeso,heo,heso,tn,qo,po,z1, &
733 psur,ierr,tcrit,0,xl,cp, &
734 ids,ide, jds,jde, kds,kde, &
735 ims,ime, jms,jme, kms,kme, &
736 its,ite, jts,jte, kts,kte)
738 !--- environmental values on cloud levels
740 call cup_env_clev(t,qes,q,he,hes,z,p,qes_cup,q_cup,he_cup, &
741 hes_cup,z_cup,p_cup,gamma_cup,t_cup,psur, &
743 ids,ide, jds,jde, kds,kde, &
744 ims,ime, jms,jme, kms,kme, &
745 its,ite, jts,jte, kts,kte)
746 call cup_env_clev(tn,qeso,qo,heo,heso,zo,po,qeso_cup,qo_cup, &
747 heo_cup,heso_cup,zo_cup,po_cup,gammao_cup,tn_cup,psur, &
749 ids,ide, jds,jde, kds,kde, &
750 ims,ime, jms,jme, kms,kme, &
751 its,ite, jts,jte, kts,kte)
756 if(zo_cup(i,k).gt.zkbmax+z1(i))then
764 !--- level where detrainment for downdraft starts
767 if(zo_cup(i,k).gt.z_detr+z1(i))then
779 !------- DETERMINE LEVEL WITH HIGHEST MOIST STATIC ENERGY CONTENT - K22
781 CALL cup_MAXIMI(HEO_CUP,3,KBMAX,K22,ierr, &
782 ids,ide, jds,jde, kds,kde, &
783 ims,ime, jms,jme, kms,kme, &
784 its,ite, jts,jte, kts,kte)
786 IF(ierr(I).eq.0.)THEN
787 IF(K22(I).GE.KBMAX(i))ierr(i)=2
791 !--- DETERMINE THE LEVEL OF CONVECTIVE CLOUD BASE - KBCON
793 call cup_kbcon(cap_max_increment,1,k22,kbcon,heo_cup,heso_cup, &
794 ierr,kbmax,po_cup,cap_max, &
795 ids,ide, jds,jde, kds,kde, &
796 ims,ime, jms,jme, kms,kme, &
797 its,ite, jts,jte, kts,kte)
798 ! call cup_kbcon_cin(1,k22,kbcon,heo_cup,heso_cup,z,tn_cup, &
799 ! qeso_cup,ierr,kbmax,po_cup,cap_max,xl,cp,&
800 ! ids,ide, jds,jde, kds,kde, &
801 ! ims,ime, jms,jme, kms,kme, &
802 ! its,ite, jts,jte, kts,kte)
804 !--- increase detrainment in stable layers
806 CALL cup_minimi(HEso_cup,Kbcon,kstabm,kstabi,ierr, &
807 ids,ide, jds,jde, kds,kde, &
808 ims,ime, jms,jme, kms,kme, &
809 its,ite, jts,jte, kts,kte)
811 IF(ierr(I).eq.0.)THEN
812 if(kstabm(i)-1.gt.kstabi(i))then
813 do k=kstabi(i),kstabm(i)-1
814 cd(i,k)=cd(i,k-1)+1.5*entr_rate
815 if(cd(i,k).gt.10.0*entr_rate)cd(i,k)=10.0*entr_rate
821 !--- calculate incloud moist static energy
823 call cup_up_he(k22,hkb,z_cup,cd,mentr_rate,he_cup,hc, &
824 kbcon,ierr,dby,he,hes_cup, &
825 ids,ide, jds,jde, kds,kde, &
826 ims,ime, jms,jme, kms,kme, &
827 its,ite, jts,jte, kts,kte)
828 call cup_up_he(k22,hkbo,zo_cup,cd,mentr_rate,heo_cup,hco, &
829 kbcon,ierr,dbyo,heo,heso_cup, &
830 ids,ide, jds,jde, kds,kde, &
831 ims,ime, jms,jme, kms,kme, &
832 its,ite, jts,jte, kts,kte)
834 !--- DETERMINE CLOUD TOP - KTOP
836 call cup_ktop(1,dbyo,kbcon,ktop,ierr, &
837 ids,ide, jds,jde, kds,kde, &
838 ims,ime, jms,jme, kms,kme, &
839 its,ite, jts,jte, kts,kte)
843 zktop=(zo_cup(i,ktop(i))-z1(i))*.6
844 zktop=min(zktop+z1(i),zcutdown+z1(i))
846 if(zo_cup(i,k).gt.zktop)then
854 !--- DOWNDRAFT ORIGINATING LEVEL - JMIN
856 call cup_minimi(HEso_cup,K22,kzdown,JMIN,ierr, &
857 ids,ide, jds,jde, kds,kde, &
858 ims,ime, jms,jme, kms,kme, &
859 its,ite, jts,jte, kts,kte)
861 IF(ierr(I).eq.0.)THEN
863 !--- check whether it would have buoyancy, if there where
864 !--- no entrainment/detrainment
866 !jm begin 20061212: the following code replaces code that
867 ! was too complex and causing problem for optimization.
868 ! Done in consultation with G. Grell.
871 DO WHILE ( keep_going )
873 if ( jmini - 1 .lt. kdet(i) ) kdet(i) = jmini-1
874 if ( jmini .ge. ktop(i)-1 ) jmini = ktop(i) - 2
876 hcdo(i,ki)=heso_cup(i,ki)
877 DZ=Zo_cup(i,Ki+1)-Zo_cup(i,Ki)
880 hcdo(i,k)=heso_cup(i,jmini)
881 DZ=Zo_cup(i,K+1)-Zo_cup(i,K)
882 dh=dh+dz*(HCDo(i,K)-heso_cup(i,k))
885 IF ( jmini .gt. 3 ) THEN
895 IF ( jmini .le. 3 ) THEN
902 ! - Must have at least depth_min m between cloud convective base
906 IF(ierr(I).eq.0.)THEN
907 IF(-zo_cup(I,KBCON(I))+zo_cup(I,KTOP(I)).LT.depth_min)then
914 !c--- normalized updraft mass flux profile
916 call cup_up_nms(zu,z_cup,mentr_rate,cd,kbcon,ktop,ierr,k22, &
917 ids,ide, jds,jde, kds,kde, &
918 ims,ime, jms,jme, kms,kme, &
919 its,ite, jts,jte, kts,kte)
920 call cup_up_nms(zuo,zo_cup,mentr_rate,cd,kbcon,ktop,ierr,k22, &
921 ids,ide, jds,jde, kds,kde, &
922 ims,ime, jms,jme, kms,kme, &
923 its,ite, jts,jte, kts,kte)
925 !c--- normalized downdraft mass flux profile,also work on bottom detrainment
928 call cup_dd_nms(zd,z_cup,cdd,mentrd_rate,jmin,ierr, &
930 ids,ide, jds,jde, kds,kde, &
931 ims,ime, jms,jme, kms,kme, &
932 its,ite, jts,jte, kts,kte)
933 call cup_dd_nms(zdo,zo_cup,cdd,mentrd_rate,jmin,ierr, &
935 ids,ide, jds,jde, kds,kde, &
936 ims,ime, jms,jme, kms,kme, &
937 its,ite, jts,jte, kts,kte)
939 !--- downdraft moist static energy
941 call cup_dd_he(hes_cup,zd,hcd,z_cup,cdd,mentrd_rate, &
942 jmin,ierr,he,dbyd,he_cup, &
943 ids,ide, jds,jde, kds,kde, &
944 ims,ime, jms,jme, kms,kme, &
945 its,ite, jts,jte, kts,kte)
946 call cup_dd_he(heso_cup,zdo,hcdo,zo_cup,cdd,mentrd_rate, &
947 jmin,ierr,heo,dbydo,he_cup,&
948 ids,ide, jds,jde, kds,kde, &
949 ims,ime, jms,jme, kms,kme, &
950 its,ite, jts,jte, kts,kte)
952 !--- calculate moisture properties of downdraft
954 call cup_dd_moisture(zd,hcd,hes_cup,qcd,qes_cup, &
955 pwd,q_cup,z_cup,cdd,mentrd_rate,jmin,ierr,gamma_cup, &
956 pwev,bu,qrcd,q,he,t_cup,2,xl, &
957 ids,ide, jds,jde, kds,kde, &
958 ims,ime, jms,jme, kms,kme, &
959 its,ite, jts,jte, kts,kte)
960 call cup_dd_moisture(zdo,hcdo,heso_cup,qcdo,qeso_cup, &
961 pwdo,qo_cup,zo_cup,cdd,mentrd_rate,jmin,ierr,gammao_cup, &
962 pwevo,bu,qrcdo,qo,heo,tn_cup,1,xl, &
963 ids,ide, jds,jde, kds,kde, &
964 ims,ime, jms,jme, kms,kme, &
965 its,ite, jts,jte, kts,kte)
967 !--- calculate moisture properties of updraft
969 call cup_up_moisture(ierr,z_cup,qc,qrc,pw,pwav, &
970 kbcon,ktop,cd,dby,mentr_rate,clw_all, &
971 q,GAMMA_cup,zu,qes_cup,k22,q_cup,xl, &
972 ids,ide, jds,jde, kds,kde, &
973 ims,ime, jms,jme, kms,kme, &
974 its,ite, jts,jte, kts,kte)
980 call cup_up_moisture(ierr,zo_cup,qco,qrco,pwo,pwavo, &
981 kbcon,ktop,cd,dbyo,mentr_rate,clw_all, &
982 qo,GAMMAo_cup,zuo,qeso_cup,k22,qo_cup,xl,&
983 ids,ide, jds,jde, kds,kde, &
984 ims,ime, jms,jme, kms,kme, &
985 its,ite, jts,jte, kts,kte)
987 !--- calculate workfunctions for updrafts
989 call cup_up_aa0(aa0,z,zu,dby,GAMMA_CUP,t_cup, &
991 ids,ide, jds,jde, kds,kde, &
992 ims,ime, jms,jme, kms,kme, &
993 its,ite, jts,jte, kts,kte)
994 call cup_up_aa0(aa1,zo,zuo,dbyo,GAMMAo_CUP,tn_cup, &
996 ids,ide, jds,jde, kds,kde, &
997 ims,ime, jms,jme, kms,kme, &
998 its,ite, jts,jte, kts,kte)
1000 if(ierr(i).eq.0)then
1001 if(aa1(i).eq.0.)then
1007 !--- DETERMINE DOWNDRAFT STRENGTH IN TERMS OF WINDSHEAR
1009 call cup_dd_edt(ierr,us,vs,zo,ktop,kbcon,edt,po,pwavo, &
1010 pwevo,edtmax,edtmin,maxens2,edtc, &
1011 ids,ide, jds,jde, kds,kde, &
1012 ims,ime, jms,jme, kms,kme, &
1013 its,ite, jts,jte, kts,kte)
1014 do 250 iedt=1,maxens2
1016 if(ierr(i).eq.0)then
1018 edto(i)=edtc(i,iedt)
1019 edtx(i)=edtc(i,iedt)
1024 dellat_ens(i,k,iedt)=0.
1025 dellaq_ens(i,k,iedt)=0.
1026 dellaqc_ens(i,k,iedt)=0.
1027 pwo_ens(i,k,iedt)=0.
1033 cfu1_ens(i,k,iedt)=0.
1034 cfd1_ens(i,k,iedt)=0.
1035 dfu1_ens(i,k,iedt)=0.
1036 efu1_ens(i,k,iedt)=0.
1037 dfd1_ens(i,k,iedt)=0.
1038 efd1_ens(i,k,iedt)=0.
1047 ! if(ierr(i).eq.0)then
1055 !---downdraft workfunctions
1057 ! call cup_dd_aa0(edt,ierr,aa0,jmin,gamma_cup,t_cup, &
1058 ! hcd,hes_cup,z,zd, &
1059 ! ids,ide, jds,jde, kds,kde, &
1060 ! ims,ime, jms,jme, kms,kme, &
1061 ! its,ite, jts,jte, kts,kte)
1062 ! call cup_dd_aa0(edto,ierr,aad,jmin,gammao_cup,tn_cup, &
1063 ! hcdo,heso_cup,zo,zdo, &
1064 ! ids,ide, jds,jde, kds,kde, &
1065 ! ims,ime, jms,jme, kms,kme, &
1066 ! its,ite, jts,jte, kts,kte)
1068 !--- change per unit mass that a model cloud would modify the environment
1070 !--- 1. in bottom layer
1072 call cup_dellabot(ipr,jpr,heo_cup,ierr,zo_cup,po,hcdo,edto, &
1073 zuo,zdo,cdd,heo,dellah,j,mentrd_rate,zo,g, &
1074 CFU1,CFD1,DFU1,EFU1,DFD1,EFD1,l_flux, &
1075 ids,ide, jds,jde, kds,kde, &
1076 ims,ime, jms,jme, kms,kme, &
1077 its,ite, jts,jte, kts,kte)
1078 call cup_dellabot(ipr,jpr,qo_cup,ierr,zo_cup,po,qrcdo,edto, &
1079 zuo,zdo,cdd,qo,dellaq,j,mentrd_rate,zo,g,&
1080 CFU1,CFD1,DFU1,EFU1,DFD1,EFD1,.FALSE., &
1081 ids,ide, jds,jde, kds,kde, &
1082 ims,ime, jms,jme, kms,kme, &
1083 its,ite, jts,jte, kts,kte)
1085 !--- 2. everywhere else
1087 call cup_dellas(ierr,zo_cup,po_cup,hcdo,edto,zdo,cdd, &
1088 heo,dellah,j,mentrd_rate,zuo,g, &
1089 cd,hco,ktop,k22,kbcon,mentr_rate,jmin,heo_cup,kdet, &
1090 k22,ipr,jpr,'deep', &
1091 CFU1,CFD1,DFU1,EFU1,DFD1,EFD1,l_flux, &
1092 ids,ide, jds,jde, kds,kde, &
1093 ims,ime, jms,jme, kms,kme, &
1094 its,ite, jts,jte, kts,kte)
1096 !-- take out cloud liquid water for detrainment
1103 if(ierr(i).eq.0)then
1104 ! print *,'in vupnewg, after della ',ierr(i),aa0(i),i,j
1105 scr1(i,k)=qco(i,k)-qrco(i,k)
1106 if(k.eq.ktop(i)-0)dellaqc(i,k)= &
1107 .01*zuo(i,ktop(i))*qrco(i,ktop(i))* &
1108 9.81/(po_cup(i,k)-po_cup(i,k+1))
1109 if(k.lt.ktop(i).and.k.gt.kbcon(i))then
1110 dz=zo_cup(i,k+1)-zo_cup(i,k)
1111 dellaqc(i,k)=.01*9.81*cd(i,k)*dz*zuo(i,k) &
1112 *.5*(qrco(i,k)+qrco(i,k+1))/ &
1113 (po_cup(i,k)-po_cup(i,k+1))
1118 call cup_dellas(ierr,zo_cup,po_cup,qrcdo,edto,zdo,cdd, &
1119 qo,dellaq,j,mentrd_rate,zuo,g, &
1120 cd,scr1,ktop,k22,kbcon,mentr_rate,jmin,qo_cup,kdet, &
1121 k22,ipr,jpr,'deep', &
1122 CFU1,CFD1,DFU1,EFU1,DFD1,EFD1,.FALSE., &
1123 ids,ide, jds,jde, kds,kde, &
1124 ims,ime, jms,jme, kms,kme, &
1125 its,ite, jts,jte, kts,kte )
1127 !--- using dellas, calculate changed environmental profiles
1129 ! do 200 nens=1,maxens
1137 ! mbdt=mbdt_ens(nens)
1139 ! xaa0_ens(i,nens)=0.
1144 if(ierr(i).eq.0)then
1145 XHE(I,K)=DELLAH(I,K)*MBDT+HEO(I,K)
1146 XQ(I,K)=DELLAQ(I,K)*MBDT+QO(I,K)
1147 DELLAT(I,K)=(1./cp)*(DELLAH(I,K)-xl*DELLAQ(I,K))
1148 XT(I,K)= DELLAT(I,K)*MBDT+TN(I,K)
1149 IF(XQ(I,K).LE.0.)XQ(I,K)=1.E-08
1150 ! if(i.eq.ipr.and.j.eq.jpr)then
1151 ! print *,k,DELLAH(I,K),DELLAQ(I,K),DELLAT(I,K)
1157 if(ierr(i).eq.0)then
1158 XHE(I,ktf)=HEO(I,ktf)
1161 IF(XQ(I,ktf).LE.0.)XQ(I,ktf)=1.E-08
1165 !--- calculate moist static energy, heights, qes
1167 call cup_env(xz,xqes,xhe,xhes,xt,xq,po,z1, &
1168 psur,ierr,tcrit,2,xl,cp, &
1169 ids,ide, jds,jde, kds,kde, &
1170 ims,ime, jms,jme, kms,kme, &
1171 its,ite, jts,jte, kts,kte)
1173 !--- environmental values on cloud levels
1175 call cup_env_clev(xt,xqes,xq,xhe,xhes,xz,po,xqes_cup,xq_cup, &
1176 xhe_cup,xhes_cup,xz_cup,po_cup,gamma_cup,xt_cup,psur, &
1178 ids,ide, jds,jde, kds,kde, &
1179 ims,ime, jms,jme, kms,kme, &
1180 its,ite, jts,jte, kts,kte)
1183 !**************************** static control
1185 !--- moist static energy inside cloud
1188 if(ierr(i).eq.0)then
1189 xhkb(i)=xhe(i,k22(i))
1192 call cup_up_he(k22,xhkb,xz_cup,cd,mentr_rate,xhe_cup,xhc, &
1193 kbcon,ierr,xdby,xhe,xhes_cup, &
1194 ids,ide, jds,jde, kds,kde, &
1195 ims,ime, jms,jme, kms,kme, &
1196 its,ite, jts,jte, kts,kte)
1198 !c--- normalized mass flux profile
1200 call cup_up_nms(xzu,xz_cup,mentr_rate,cd,kbcon,ktop,ierr,k22, &
1201 ids,ide, jds,jde, kds,kde, &
1202 ims,ime, jms,jme, kms,kme, &
1203 its,ite, jts,jte, kts,kte)
1205 !--- moisture downdraft
1207 call cup_dd_nms(xzd,xz_cup,cdd,mentrd_rate,jmin,ierr, &
1209 ids,ide, jds,jde, kds,kde, &
1210 ims,ime, jms,jme, kms,kme, &
1211 its,ite, jts,jte, kts,kte)
1212 call cup_dd_he(xhes_cup,xzd,xhcd,xz_cup,cdd,mentrd_rate, &
1213 jmin,ierr,xhe,dbyd,xhe_cup,&
1214 ids,ide, jds,jde, kds,kde, &
1215 ims,ime, jms,jme, kms,kme, &
1216 its,ite, jts,jte, kts,kte)
1217 call cup_dd_moisture(xzd,xhcd,xhes_cup,xqcd,xqes_cup, &
1218 xpwd,xq_cup,xz_cup,cdd,mentrd_rate,jmin,ierr,gamma_cup, &
1219 xpwev,bu,xqrcd,xq,xhe,xt_cup,3,xl, &
1220 ids,ide, jds,jde, kds,kde, &
1221 ims,ime, jms,jme, kms,kme, &
1222 its,ite, jts,jte, kts,kte)
1225 !------- MOISTURE updraft
1227 call cup_up_moisture(ierr,xz_cup,xqc,xqrc,xpw,xpwav, &
1228 kbcon,ktop,cd,xdby,mentr_rate,clw_all, &
1229 xq,GAMMA_cup,xzu,xqes_cup,k22,xq_cup,xl, &
1230 ids,ide, jds,jde, kds,kde, &
1231 ims,ime, jms,jme, kms,kme, &
1232 its,ite, jts,jte, kts,kte)
1234 !--- workfunctions for updraft
1236 call cup_up_aa0(xaa0,xz,xzu,xdby,GAMMA_CUP,xt_cup, &
1238 ids,ide, jds,jde, kds,kde, &
1239 ims,ime, jms,jme, kms,kme, &
1240 its,ite, jts,jte, kts,kte)
1242 !--- workfunctions for downdraft
1245 ! call cup_dd_aa0(edtx,ierr,xaa0,jmin,gamma_cup,xt_cup, &
1246 ! xhcd,xhes_cup,xz,xzd, &
1247 ! ids,ide, jds,jde, kds,kde, &
1248 ! ims,ime, jms,jme, kms,kme, &
1249 ! its,ite, jts,jte, kts,kte)
1250 do 200 nens=1,maxens
1252 if(ierr(i).eq.0)then
1253 xaa0_ens(i,nens)=xaa0(i)
1254 nall=(iens-1)*maxens3*maxens*maxens2 &
1255 +(iedt-1)*maxens*maxens3 &
1258 if(k.le.ktop(i))then
1262 pr_ens(i,j,nall+nens3)=pr_ens(i,j,nall+nens3)+ &
1264 ! +edto(i)*pwdo(i,k)
1266 else if(nens3.eq.8)then
1267 pr_ens(i,j,nall+nens3)=pr_ens(i,j,nall+nens3)+ &
1270 else if(nens3.eq.9)then
1271 pr_ens(i,j,nall+nens3)=pr_ens(i,j,nall+nens3)+ &
1273 ! +.5*edto(i)*pwdo(i,k)
1275 pr_ens(i,j,nall+nens3)=pr_ens(i,j,nall+nens3)+ &
1276 pwo(i,k)+edto(i)*pwdo(i,k)
1281 if(pr_ens(i,j,nall+7).lt.1.e-6)then
1284 pr_ens(i,j,nall+nens3)=0.
1288 if(pr_ens(i,j,nall+nens3).lt.1.e-4)then
1289 pr_ens(i,j,nall+nens3)=0.
1296 !--- LARGE SCALE FORCING
1299 !------- CHECK wether aa0 should have been zero
1302 CALL cup_MAXIMI(HEO_CUP,3,KBMAX,K22x,ierr, &
1303 ids,ide, jds,jde, kds,kde, &
1304 ims,ime, jms,jme, kms,kme, &
1305 its,ite, jts,jte, kts,kte)
1310 call cup_kbcon(cap_max_increment,2,k22x,kbconx,heo_cup, &
1311 heso_cup,ierr2,kbmax,po_cup,cap_max, &
1312 ids,ide, jds,jde, kds,kde, &
1313 ims,ime, jms,jme, kms,kme, &
1314 its,ite, jts,jte, kts,kte)
1315 call cup_kbcon(cap_max_increment,3,k22x,kbconx,heo_cup, &
1316 heso_cup,ierr3,kbmax,po_cup,cap_max, &
1317 ids,ide, jds,jde, kds,kde, &
1318 ims,ime, jms,jme, kms,kme, &
1319 its,ite, jts,jte, kts,kte)
1321 !--- DETERMINE THE LEVEL OF CONVECTIVE CLOUD BASE - KBCON
1323 call cup_forcing_ens(closure_n,xland1,aa0,aa1,xaa0_ens,mbdt_ens,dtime, &
1324 ierr,ierr2,ierr3,xf_ens,j,'deeps', &
1325 maxens,iens,iedt,maxens2,maxens3,mconv, &
1326 po_cup,ktop,omeg,zdo,k22,zuo,pr_ens,edto,kbcon, &
1327 massflx,iact,direction,ensdim,massfln,ichoice, &
1328 ids,ide, jds,jde, kds,kde, &
1329 ims,ime, jms,jme, kms,kme, &
1330 its,ite, jts,jte, kts,kte)
1334 if(ierr(i).eq.0)then
1335 dellat_ens(i,k,iedt)=dellat(i,k)
1336 dellaq_ens(i,k,iedt)=dellaq(i,k)
1337 dellaqc_ens(i,k,iedt)=dellaqc(i,k)
1338 pwo_ens(i,k,iedt)=pwo(i,k)+edt(i)*pwdo(i,k)
1340 dellat_ens(i,k,iedt)=0.
1341 dellaq_ens(i,k,iedt)=0.
1342 dellaqc_ens(i,k,iedt)=0.
1343 pwo_ens(i,k,iedt)=0.
1345 ! if(i.eq.ipr.and.j.eq.jpr)then
1346 ! print *,iens,iedt,dellat(i,k),dellat_ens(i,k,iedt), &
1347 ! dellaq(i,k), dellaqc(i,k)
1354 if(ierr(i).eq.0)then
1355 cfu1_ens(i,k,iedt)=cfu1(i,k)
1356 cfd1_ens(i,k,iedt)=cfd1(i,k)
1357 dfu1_ens(i,k,iedt)=dfu1(i,k)
1358 efu1_ens(i,k,iedt)=efu1(i,k)
1359 dfd1_ens(i,k,iedt)=dfd1(i,k)
1360 efd1_ens(i,k,iedt)=efd1(i,k)
1362 cfu1_ens(i,k,iedt)=0.
1363 cfd1_ens(i,k,iedt)=0.
1364 dfu1_ens(i,k,iedt)=0.
1365 efu1_ens(i,k,iedt)=0.
1366 dfd1_ens(i,k,iedt)=0.
1367 efd1_ens(i,k,iedt)=0.
1377 call cup_output_ens(xf_ens,ierr,dellat_ens,dellaq_ens, &
1378 dellaqc_ens,outt,outq,outqc,pre,pwo_ens,xmb,ktop, &
1379 j,'deep',maxens2,maxens,iens,ierr2,ierr3, &
1380 pr_ens,maxens3,ensdim,massfln, &
1381 APR_GR,APR_W,APR_MC,APR_ST,APR_AS, &
1382 APR_CAPMA,APR_CAPME,APR_CAPMI,closure_n,xland1, &
1383 outCFU1,outCFD1,outDFU1,outEFU1,outDFD1,outEFD1, &
1384 CFU1_ens,CFD1_ens,DFU1_ens,EFU1_ens,DFD1_ens,EFD1_ens, &
1386 ids,ide, jds,jde, kds,kde, &
1387 ims,ime, jms,jme, kms,kme, &
1388 its,ite, jts,jte, kts,kte)
1390 PRE(I)=MAX(PRE(I),0.)
1393 !---------------------------done------------------------------
1396 END SUBROUTINE CUP_enss
1399 SUBROUTINE cup_dd_aa0(edt,ierr,aa0,jmin,gamma_cup,t_cup, &
1401 ids,ide, jds,jde, kds,kde, &
1402 ims,ime, jms,jme, kms,kme, &
1403 its,ite, jts,jte, kts,kte )
1410 ! only local wrf dimensions are need as of now in this routine
1414 ids,ide, jds,jde, kds,kde, &
1415 ims,ime, jms,jme, kms,kme, &
1416 its,ite, jts,jte, kts,kte
1417 ! aa0 cloud work function for downdraft
1418 ! gamma_cup = gamma on model cloud levels
1419 ! t_cup = temperature (Kelvin) on model cloud levels
1420 ! hes_cup = saturation moist static energy on model cloud levels
1421 ! hcd = moist static energy in downdraft
1423 ! zd normalized downdraft mass flux
1424 ! z = heights of model levels
1425 ! ierr error value, maybe modified in this routine
1427 real, dimension (its:ite,kts:kte) &
1429 z,zd,gamma_cup,t_cup,hes_cup,hcd
1430 real, dimension (its:ite) &
1433 integer, dimension (its:ite) &
1441 integer, dimension (its:ite) &
1442 ,intent (inout) :: &
1444 real, dimension (its:ite) &
1448 ! local variables in this routine
1464 IF(ierr(I).eq.0.and.k.lt.jmin(i))then
1469 DZ=(Z(I,KK)-Z(I,KK+1))
1470 AA0(I)=AA0(I)+zd(i,kk)*EDT(I)*DZ*(9.81/(1004.*T_cup(I,KK))) &
1471 *((hcd(i,kk)-hes_cup(i,kk))/(1.+GAMMA_cup(i,kk)))
1476 END SUBROUTINE CUP_dd_aa0
1479 SUBROUTINE cup_dd_edt(ierr,us,vs,z,ktop,kbcon,edt,p,pwav, &
1480 pwev,edtmax,edtmin,maxens2,edtc, &
1481 ids,ide, jds,jde, kds,kde, &
1482 ims,ime, jms,jme, kms,kme, &
1483 its,ite, jts,jte, kts,kte )
1489 ids,ide, jds,jde, kds,kde, &
1490 ims,ime, jms,jme, kms,kme, &
1491 its,ite, jts,jte, kts,kte
1492 integer, intent (in ) :: &
1495 ! ierr error value, maybe modified in this routine
1497 real, dimension (its:ite,kts:kte) &
1500 real, dimension (its:ite,1:maxens2) &
1503 real, dimension (its:ite) &
1506 real, dimension (its:ite) &
1512 integer, dimension (its:ite) &
1515 integer, dimension (its:ite) &
1516 ,intent (inout) :: &
1519 ! local variables in this routine
1523 real einc,pef,pefb,prezk,zkbc
1524 real, dimension (its:ite) :: &
1532 !--- DETERMINE DOWNDRAFT STRENGTH IN TERMS OF WINDSHEAR
1534 ! */ calculate an average wind shear over the depth of the cloud
1544 IF(ierr(i).ne.0)GO TO 62
1545 if (kk .le. min0(ktop(i),ktf) .and. kk .ge. kbcon(i)) then
1547 (abs((us(i,kk+1)-us(i,kk))/(z(i,kk+1)-z(i,kk))) &
1548 + abs((vs(i,kk+1)-vs(i,kk))/(z(i,kk+1)-z(i,kk)))) * &
1549 (p(i,kk) - p(i,kk+1))
1550 sdp(i) = sdp(i) + p(i,kk) - p(i,kk+1)
1552 if (kk .eq. ktf-1)vshear(i) = 1.e3 * vws(i) / sdp(i)
1556 IF(ierr(i).eq.0)then
1557 pef=(1.591-.639*VSHEAR(I)+.0953*(VSHEAR(I)**2) &
1558 -.00496*(VSHEAR(I)**3))
1559 if(pef.gt.edtmax)pef=edtmax
1560 if(pef.lt.edtmin)pef=edtmin
1562 !--- cloud base precip efficiency
1564 zkbc=z(i,kbcon(i))*3.281e-3
1567 prezk=.96729352+zkbc*(-.70034167+zkbc*(.162179896+zkbc &
1568 *(- 1.2569798E-2+zkbc*(4.2772E-4-zkbc*5.44E-6))))
1574 if(pefb.gt.edtmax)pefb=edtmax
1575 if(pefb.lt.edtmin)pefb=edtmin
1576 EDT(I)=1.-.5*(pefb+pef)
1577 !--- edt here is 1-precipeff!
1578 ! einc=(1.-edt(i))/float(maxens2)
1579 ! einc=edt(i)/float(maxens2+1)
1583 edtc(i,k)=edt(i)+float(k-2)*einc
1588 IF(ierr(i).eq.0)then
1590 EDTC(I,K)=-EDTC(I,K)*PWAV(I)/PWEV(I)
1591 IF(EDTC(I,K).GT.edtmax)EDTC(I,K)=edtmax
1592 IF(EDTC(I,K).LT.edtmin)EDTC(I,K)=edtmin
1597 END SUBROUTINE cup_dd_edt
1600 SUBROUTINE cup_dd_he(hes_cup,zd,hcd,z_cup,cdd,entr, &
1601 jmin,ierr,he,dby,he_cup, &
1602 ids,ide, jds,jde, kds,kde, &
1603 ims,ime, jms,jme, kms,kme, &
1604 its,ite, jts,jte, kts,kte )
1611 ! only local wrf dimensions are need as of now in this routine
1615 ids,ide, jds,jde, kds,kde, &
1616 ims,ime, jms,jme, kms,kme, &
1617 its,ite, jts,jte, kts,kte
1618 ! hcd = downdraft moist static energy
1619 ! he = moist static energy on model levels
1620 ! he_cup = moist static energy on model cloud levels
1621 ! hes_cup = saturation moist static energy on model cloud levels
1622 ! dby = buoancy term
1623 ! cdd= detrainment function
1624 ! z_cup = heights of model cloud levels
1625 ! entr = entrainment rate
1626 ! zd = downdraft normalized mass flux
1628 real, dimension (its:ite,kts:kte) &
1630 he,he_cup,hes_cup,z_cup,cdd,zd
1631 ! entr= entrainment rate
1635 integer, dimension (its:ite) &
1642 ! ierr error value, maybe modified in this routine
1644 integer, dimension (its:ite) &
1645 ,intent (inout) :: &
1648 real, dimension (its:ite,kts:kte) &
1652 ! local variables in this routine
1668 IF(ierr(I).eq.0)then
1669 hcd(i,k)=hes_cup(i,k)
1675 IF(ierr(I).eq.0)then
1677 hcd(i,k)=hes_cup(i,k)
1678 dby(i,k)=hcd(i,jmin(i))-hes_cup(i,k)
1680 do ki=jmin(i)-1,1,-1
1681 DZ=Z_cup(i,Ki+1)-Z_cup(i,Ki)
1682 HCD(i,Ki)=(HCD(i,Ki+1)*(1.-.5*CDD(i,Ki)*DZ) &
1684 )/(1.+entr*DZ-.5*CDD(i,Ki)*DZ)
1685 dby(i,ki)=HCD(i,Ki)-hes_cup(i,ki)
1689 !--- end loop over i
1693 END SUBROUTINE cup_dd_he
1696 SUBROUTINE cup_dd_moisture(zd,hcd,hes_cup,qcd,qes_cup, &
1697 pwd,q_cup,z_cup,cdd,entr,jmin,ierr, &
1698 gamma_cup,pwev,bu,qrcd, &
1699 q,he,t_cup,iloop,xl, &
1700 ids,ide, jds,jde, kds,kde, &
1701 ims,ime, jms,jme, kms,kme, &
1702 its,ite, jts,jte, kts,kte )
1708 ids,ide, jds,jde, kds,kde, &
1709 ims,ime, jms,jme, kms,kme, &
1710 its,ite, jts,jte, kts,kte
1711 ! cdd= detrainment function
1712 ! q = environmental q on model levels
1713 ! q_cup = environmental q on model cloud levels
1714 ! qes_cup = saturation q on model cloud levels
1715 ! hes_cup = saturation h on model cloud levels
1716 ! hcd = h in model cloud
1718 ! zd = normalized downdraft mass flux
1719 ! gamma_cup = gamma on model cloud levels
1720 ! mentr_rate = entrainment rate
1721 ! qcd = cloud q (including liquid water) after entrainment
1722 ! qrch = saturation q in cloud
1723 ! pwd = evaporate at that level
1724 ! pwev = total normalized integrated evaoprate (I2)
1725 ! entr= entrainment rate
1727 real, dimension (its:ite,kts:kte) &
1729 zd,t_cup,hes_cup,hcd,qes_cup,q_cup,z_cup,cdd,gamma_cup,q,he
1736 integer, dimension (its:ite) &
1739 integer, dimension (its:ite) &
1740 ,intent (inout) :: &
1742 real, dimension (its:ite,kts:kte) &
1745 real, dimension (its:ite) &
1749 ! local variables in this routine
1777 IF(ierr(I).eq.0)then
1779 DZ=Z_cup(i,K+1)-Z_cup(i,K)
1781 ! qcd(i,k)=.5*(qes_cup(i,k)+q_cup(i,k))
1782 qrcd(i,k)=qes_cup(i,k)
1783 pwd(i,jmin(i))=min(0.,qcd(i,k)-qrcd(i,k))
1784 pwev(i)=pwev(i)+pwd(i,jmin(i))
1785 qcd(i,k)=qes_cup(i,k)
1787 DH=HCD(I,k)-HES_cup(I,K)
1789 do ki=jmin(i)-1,1,-1
1790 DZ=Z_cup(i,Ki+1)-Z_cup(i,Ki)
1791 QCD(i,Ki)=(qCD(i,Ki+1)*(1.-.5*CDD(i,Ki)*DZ) &
1793 )/(1.+entr*DZ-.5*CDD(i,Ki)*DZ)
1795 !--- to be negatively buoyant, hcd should be smaller than hes!
1797 DH=HCD(I,ki)-HES_cup(I,Ki)
1799 QRCD(I,Ki)=qes_cup(i,ki)+(1./XL)*(GAMMA_cup(i,ki) &
1800 /(1.+GAMMA_cup(i,ki)))*DH
1801 dqeva=qcd(i,ki)-qrcd(i,ki)
1802 if(dqeva.gt.0.)dqeva=0.
1803 pwd(i,ki)=zd(i,ki)*dqeva
1804 qcd(i,ki)=qrcd(i,ki)
1805 pwev(i)=pwev(i)+pwd(i,ki)
1806 ! if(iloop.eq.1.and.i.eq.102.and.j.eq.62)then
1807 ! print *,'in cup_dd_moi ', hcd(i,ki),HES_cup(I,Ki),dh,dqeva
1811 !--- end loop over i
1812 if(pwev(I).eq.0.and.iloop.eq.1)then
1813 ! print *,'problem with buoy in cup_dd_moisture',i
1816 if(BU(I).GE.0.and.iloop.eq.1)then
1817 ! print *,'problem with buoy in cup_dd_moisture',i
1823 END SUBROUTINE cup_dd_moisture
1826 SUBROUTINE cup_dd_nms(zd,z_cup,cdd,entr,jmin,ierr, &
1828 ids,ide, jds,jde, kds,kde, &
1829 ims,ime, jms,jme, kms,kme, &
1830 its,ite, jts,jte, kts,kte )
1837 ! only local wrf dimensions are need as of now in this routine
1841 ids,ide, jds,jde, kds,kde, &
1842 ims,ime, jms,jme, kms,kme, &
1843 its,ite, jts,jte, kts,kte
1844 ! z_cup = height of cloud model level
1845 ! z1 = terrain elevation
1846 ! entr = downdraft entrainment rate
1847 ! jmin = downdraft originating level
1848 ! kdet = level above ground where downdraft start detraining
1849 ! itest = flag to whether to calculate cdd
1851 real, dimension (its:ite,kts:kte) &
1854 real, dimension (its:ite) &
1860 integer, dimension (its:ite) &
1870 ! ierr error value, maybe modified in this routine
1872 integer, dimension (its:ite) &
1873 ,intent (inout) :: &
1875 ! zd is the normalized downdraft mass flux
1876 ! cdd is the downdraft detrainmen function
1878 real, dimension (its:ite,kts:kte) &
1881 real, dimension (its:ite,kts:kte) &
1882 ,intent (inout) :: &
1885 ! local variables in this routine
1898 !--- perc is the percentage of mass left when hitting the ground
1905 if(itest.eq.0)cdd(i,k)=0.
1913 IF(ierr(I).eq.0)then
1916 !--- integrate downward, specify detrainment(cdd)!
1918 do ki=jmin(i)-1,1,-1
1919 DZ=Z_cup(i,Ki+1)-Z_cup(i,Ki)
1920 if(ki.le.kdet(i).and.itest.eq.0)then
1921 cdd(i,ki)=entr+(1.- (a*(z_cup(i,ki)-z1(i)) &
1922 +perc*(z_cup(i,kdet(i))-z1(i)) ) &
1923 /(a*(z_cup(i,ki+1)-z1(i)) &
1924 +perc*(z_cup(i,kdet(i))-z1(i))))/dz
1926 zd(i,ki)=zd(i,ki+1)*(1.+(entr-cdd(i,ki))*dz)
1930 !--- end loop over i
1933 END SUBROUTINE cup_dd_nms
1936 SUBROUTINE cup_dellabot(ipr,jpr,he_cup,ierr,z_cup,p_cup, &
1937 hcd,edt,zu,zd,cdd,he,della,j,mentrd_rate,z,g, &
1938 CFU1,CFD1,DFU1,EFU1,DFD1,EFD1,l_flux, &
1939 ids,ide, jds,jde, kds,kde, &
1940 ims,ime, jms,jme, kms,kme, &
1941 its,ite, jts,jte, kts,kte )
1947 ids,ide, jds,jde, kds,kde, &
1948 ims,ime, jms,jme, kms,kme, &
1949 its,ite, jts,jte, kts,kte
1950 integer, intent (in ) :: &
1953 ! ierr error value, maybe modified in this routine
1955 real, dimension (its:ite,kts:kte) &
1958 real, dimension (its:ite,kts:kte) &
1960 z_cup,p_cup,hcd,zu,zd,cdd,he,z,he_cup
1961 real, dimension (its:ite) &
1967 integer, dimension (its:ite) &
1968 ,intent (inout) :: &
1970 real, dimension (its:ite,kts:kte) &
1971 ,intent (inout ) :: &
1972 CFU1,CFD1,DFU1,EFU1,DFD1,EFD1
1973 logical, intent(in) :: l_flux
1975 ! local variables in this routine
1979 real detdo,detdo1,detdo2,entdo,dp,dz,subin, &
1988 ! if(j.eq.jpr)print *,'in cup dellabot '
2001 if(ierr(i).ne.0)go to 100
2002 dz=z_cup(i,2)-z_cup(i,1)
2003 DP=100.*(p_cup(i,1)-P_cup(i,2))
2004 detdo1=edt(i)*zd(i,2)*CDD(i,1)*DZ
2005 detdo2=edt(i)*zd(i,1)
2006 entdo=edt(i)*zd(i,2)*mentrd_rate*dz
2007 subin=-EDT(I)*zd(i,2)
2008 detdo=detdo1+detdo2-entdo+subin
2009 DELLA(I,1)=(detdo1*.5*(HCD(i,1)+HCD(i,2)) &
2011 +subin*he_cup(i,2) &
2012 -entdo*he(i,1))*g/dp
2014 cfd1(i,2) = -edt(i)*zd(i,2) !only contribution to subin, subdown=0
2015 dfd1(i,1) = detdo1+detdo2
2020 END SUBROUTINE cup_dellabot
2023 SUBROUTINE cup_dellas(ierr,z_cup,p_cup,hcd,edt,zd,cdd, &
2024 he,della,j,mentrd_rate,zu,g, &
2025 cd,hc,ktop,k22,kbcon,mentr_rate,jmin,he_cup,kdet,kpbl, &
2027 CFU1,CFD1,DFU1,EFU1,DFD1,EFD1,l_flux, &
2028 ids,ide, jds,jde, kds,kde, &
2029 ims,ime, jms,jme, kms,kme, &
2030 its,ite, jts,jte, kts,kte )
2036 ids,ide, jds,jde, kds,kde, &
2037 ims,ime, jms,jme, kms,kme, &
2038 its,ite, jts,jte, kts,kte
2039 integer, intent (in ) :: &
2042 ! ierr error value, maybe modified in this routine
2044 real, dimension (its:ite,kts:kte) &
2047 real, dimension (its:ite,kts:kte) &
2049 z_cup,p_cup,hcd,zd,cdd,he,hc,cd,zu,he_cup
2050 real, dimension (its:ite) &
2055 g,mentrd_rate,mentr_rate
2056 integer, dimension (its:ite) &
2058 kbcon,ktop,k22,jmin,kdet,kpbl
2059 integer, dimension (its:ite) &
2060 ,intent (inout) :: &
2062 character *(*), intent (in) :: &
2064 real, dimension (its:ite,kts:kte) &
2065 ,intent (inout ) :: &
2066 CFU1,CFD1,DFU1,EFU1,DFD1,EFD1
2067 logical, intent(in) :: l_flux
2069 ! local variables in this routine
2073 real detdo1,detdo2,entdo,dp,dz,subin,detdo,entup, &
2074 detup,subdown,entdoj,entupk,detupk,totmas
2084 ! print *,'in dellas kpbl(i),k22(i),kbcon(i),ktop(i),jmin(i)'
2085 ! print *,kpbl(i),k22(i),kbcon(i),ktop(i),jmin(i)
2109 DO 100 k=kts+1,ktf-1
2111 IF(ierr(i).ne.0)GO TO 100
2112 IF(K.Gt.KTOP(I))GO TO 100
2114 !--- SPECIFY DETRAINMENT OF DOWNDRAFT, HAS TO BE CONSISTENT
2115 !--- WITH ZD CALCULATIONS IN SOUNDD.
2117 DZ=Z_cup(I,K+1)-Z_cup(I,K)
2118 detdo=edt(i)*CDD(i,K)*DZ*ZD(i,k+1)
2119 entdo=edt(i)*mentrd_rate*dz*zd(i,k+1)
2120 subin=zu(i,k+1)-zd(i,k+1)*edt(i)
2123 if(k.ge.kbcon(i).and.k.lt.ktop(i))then
2124 entup=mentr_rate*dz*zu(i,k)
2125 detup=CD(i,K+1)*DZ*ZU(i,k)
2127 subdown=(zu(i,k)-zd(i,k)*edt(i))
2132 if(k.eq.jmin(i))then
2133 entdoj=edt(i)*zd(i,k)
2136 if(k.eq.k22(i)-1)then
2137 entupk=zu(i,kpbl(i))
2140 if(k.gt.kdet(i))then
2144 if(k.eq.ktop(i)-0)then
2145 detupk=zu(i,ktop(i))
2148 if(k.lt.kbcon(i))then
2152 ! z_cup(k+1): zu(k+1), -zd(k+1) ==> subin ==> cf[du]1 (k+1) (full-eta level k+1)
2154 ! z(k) : detup, detdo, entup, entdo ==> [de]f[du]1 (k) (half-eta level k )
2156 ! z_cup(k) : zu(k), -zd(k) ==> subdown ==> cf[du]1 (k) (full-eta level k )
2158 ! Store downdraft/updraft mass fluxes at full eta level k (z_cup(k)) in cf[ud]1(k):
2159 cfu1(i,k+1) = zu(i,k+1)
2160 cfd1(i,k+1) = -edt(i)*zd(i,k+1)
2161 ! Store detrainment/entrainment mass fluxes at half eta level k (z(k)) in [de]f[du]1(k):
2162 dfu1(i,k) = detup+detupk
2163 efu1(i,k) = -(entup+entupk)
2165 efd1(i,k) = -(entdo+entdoj)
2168 !C--- CHANGED DUE TO SUBSIDENCE AND ENTRAINMENT
2170 totmas=subin-subdown+detup-entup-entdo+ &
2171 detdo-entupk-entdoj+detupk
2172 ! if(j.eq.jpr.and.i.eq.ipr)print *,'k,totmas,sui,sud = ',k,
2173 ! 1 totmas,subin,subdown
2174 ! if(j.eq.jpr.and.i.eq.ipr)print *,'updr stuff = ',detup,
2175 ! 1 entup,entupk,detupk
2176 ! if(j.eq.jpr.and.i.eq.ipr)print *,'dddr stuff = ',entdo,
2178 if(abs(totmas).gt.1.e-6)then
2179 ! print *,'*********************',i,j,k,totmas,name
2180 ! print *,kpbl(i),k22(i),kbcon(i),ktop(i)
2181 !c print *,'updr stuff = ',subin,
2182 !c 1 subdown,detup,entup,entupk,detupk
2183 !c print *,'dddr stuff = ',entdo,
2185 ! call wrf_error_fatal ( 'totmas .gt.1.e-6' )
2187 dp=100.*(p_cup(i,k-1)-p_cup(i,k))
2188 della(i,k)=(subin*he_cup(i,k+1) &
2189 -subdown*he_cup(i,k) &
2190 +detup*.5*(HC(i,K+1)+HC(i,K)) &
2191 +detdo*.5*(HCD(i,K+1)+HCD(i,K)) &
2194 -entupk*he_cup(i,k22(i)) &
2195 -entdoj*he_cup(i,jmin(i)) &
2196 +detupk*hc(i,ktop(i)) &
2198 ! if(i.eq.ipr.and.j.eq.jpr)then
2199 ! print *,k,della(i,k),subin*he_cup(i,k+1),subdown*he_cup(i,k),
2200 ! 1 detdo*.5*(HCD(i,K+1)+HCD(i,K))
2201 ! print *,k,detup*.5*(HC(i,K+1)+HC(i,K)),detupk*hc(i,ktop(i)),
2202 ! 1 entup*he(i,k),entdo*he(i,k)
2203 ! print *,k,he_cup(i,k+1),he_cup(i,k),entupk*he_cup(i,k)
2208 END SUBROUTINE cup_dellas
2211 SUBROUTINE cup_direction2(i,j,dir,id,massflx, &
2212 iresult,imass,massfld, &
2213 ids,ide, jds,jde, kds,kde, &
2214 ims,ime, jms,jme, kms,kme, &
2215 its,ite, jts,jte, kts,kte )
2221 ids,ide, jds,jde, kds,kde, &
2222 ims,ime, jms,jme, kms,kme, &
2223 its,ite, jts,jte, kts,kte
2224 integer, intent (in ) :: &
2226 integer, intent (out ) :: &
2229 ! ierr error value, maybe modified in this routine
2231 integer, dimension (ims:ime,jms:jme) &
2234 real, dimension (ims:ime,jms:jme) &
2237 real, dimension (its:ite) &
2238 ,intent (inout) :: &
2244 ! local variables in this routine
2247 integer k,ia,ja,ib,jb
2253 massfld=massflx(i,j)
2258 if(dir(i).lt.22.5)dir(i)=360.+dir(i)
2259 if(id(i,j).eq.1)iresult=1
2268 if(dir(i).gt.90.-diff.and.dir(i).le.90.+diff)then
2269 !--- steering flow from the east
2270 if(id(ib,j).eq.1)then
2273 massfld=max(massflx(ib,j),massflx(i,j))
2277 else if(dir(i).gt.135.-diff.and.dir(i).le.135.+diff)then
2278 !--- steering flow from the south-east
2279 if(id(ib,ja).eq.1)then
2282 massfld=max(massflx(ib,ja),massflx(i,j))
2286 !--- steering flow from the south
2287 else if(dir(i).gt.180.-diff.and.dir(i).le.180.+diff)then
2288 if(id(i,ja).eq.1)then
2291 massfld=max(massflx(i,ja),massflx(i,j))
2295 !--- steering flow from the south west
2296 else if(dir(i).gt.225.-diff.and.dir(i).le.225.+diff)then
2297 if(id(ia,ja).eq.1)then
2300 massfld=max(massflx(ia,ja),massflx(i,j))
2304 !--- steering flow from the west
2305 else if(dir(i).gt.270.-diff.and.dir(i).le.270.+diff)then
2306 if(id(ia,j).eq.1)then
2309 massfld=max(massflx(ia,j),massflx(i,j))
2313 !--- steering flow from the north-west
2314 else if(dir(i).gt.305.-diff.and.dir(i).le.305.+diff)then
2315 if(id(ia,jb).eq.1)then
2318 massfld=max(massflx(ia,jb),massflx(i,j))
2322 !--- steering flow from the north
2323 else if(dir(i).gt.360.-diff.and.dir(i).le.360.+diff)then
2324 if(id(i,jb).eq.1)then
2327 massfld=max(massflx(i,jb),massflx(i,j))
2331 !--- steering flow from the north-east
2332 else if(dir(i).gt.45.-diff.and.dir(i).le.45.+diff)then
2333 if(id(ib,jb).eq.1)then
2336 massfld=max(massflx(ib,jb),massflx(i,j))
2342 END SUBROUTINE cup_direction2
2345 SUBROUTINE cup_env(z,qes,he,hes,t,q,p,z1, &
2346 psur,ierr,tcrit,itest,xl,cp, &
2347 ids,ide, jds,jde, kds,kde, &
2348 ims,ime, jms,jme, kms,kme, &
2349 its,ite, jts,jte, kts,kte )
2355 ids,ide, jds,jde, kds,kde, &
2356 ims,ime, jms,jme, kms,kme, &
2357 its,ite, jts,jte, kts,kte
2359 ! ierr error value, maybe modified in this routine
2360 ! q = environmental mixing ratio
2361 ! qes = environmental saturation mixing ratio
2362 ! t = environmental temp
2363 ! tv = environmental virtual temp
2364 ! p = environmental pressure
2365 ! z = environmental heights
2366 ! he = environmental moist static energy
2367 ! hes = environmental saturation moist static energy
2368 ! psur = surface pressure
2369 ! z1 = terrain elevation
2372 real, dimension (its:ite,kts:kte) &
2375 real, dimension (its:ite,kts:kte) &
2378 real, dimension (its:ite,kts:kte) &
2379 ,intent (inout) :: &
2381 real, dimension (its:ite) &
2387 integer, dimension (its:ite) &
2388 ,intent (inout) :: &
2394 ! local variables in this routine
2399 real, dimension (1:2) :: AE,BE,HT
2400 real, dimension (its:ite,kts:kte) :: tv
2401 real :: tcrit,e,tvbar
2410 BE(1)=.622*HT(1)/.286
2411 AE(1)=BE(1)/273.+ALOG(610.71)
2412 BE(2)=.622*HT(2)/.286
2413 AE(2)=BE(2)/273.+ALOG(610.71)
2414 ! print *, 'TCRIT = ', tcrit,its,ite
2417 if(ierr(i).eq.0)then
2418 !Csgb - IPH is for phase, dependent on TCRIT (water or ice)
2420 IF(T(I,K).LE.TCRIT)IPH=2
2421 ! print *, 'AE(IPH),BE(IPH) = ',AE(IPH),BE(IPH),AE(IPH)-BE(IPH),T(i,k),i,k
2422 E=EXP(AE(IPH)-BE(IPH)/T(I,K))
2423 ! print *, 'P, E = ', P(I,K), E
2424 QES(I,K)=.622*E/(100.*P(I,K)-E)
2425 IF(QES(I,K).LE.1.E-08)QES(I,K)=1.E-08
2426 IF(Q(I,K).GT.QES(I,K))Q(I,K)=QES(I,K)
2427 TV(I,K)=T(I,K)+.608*Q(I,K)*T(I,K)
2432 !--- z's are calculated with changed h's and q's and t's
2437 if(ierr(i).eq.0)then
2438 Z(I,1)=max(0.,Z1(I))-(ALOG(P(I,1))- &
2439 ALOG(PSUR(I)))*287.*TV(I,1)/9.81
2443 ! --- calculate heights
2446 if(ierr(i).eq.0)then
2447 TVBAR=.5*TV(I,K)+.5*TV(I,K-1)
2448 Z(I,K)=Z(I,K-1)-(ALOG(P(I,K))- &
2449 ALOG(P(I,K-1)))*287.*TVBAR/9.81
2456 if(ierr(i).eq.0)then
2457 z(i,k)=(he(i,k)-1004.*t(i,k)-2.5e6*q(i,k))/9.81
2458 z(i,k)=max(1.e-3,z(i,k))
2464 !--- calculate moist static energy - HE
2465 ! saturated moist static energy - HES
2469 if(ierr(i).eq.0)then
2470 if(itest.eq.0)HE(I,K)=9.81*Z(I,K)+1004.*T(I,K)+2.5E06*Q(I,K)
2471 HES(I,K)=9.81*Z(I,K)+1004.*T(I,K)+2.5E06*QES(I,K)
2472 IF(HE(I,K).GE.HES(I,K))HE(I,K)=HES(I,K)
2474 ! print *,k,z(i,k),t(i,k),p(i,k),he(i,k),hes(i,k)
2480 END SUBROUTINE cup_env
2483 SUBROUTINE cup_env_clev(t,qes,q,he,hes,z,p,qes_cup,q_cup, &
2484 he_cup,hes_cup,z_cup,p_cup,gamma_cup,t_cup,psur, &
2486 ids,ide, jds,jde, kds,kde, &
2487 ims,ime, jms,jme, kms,kme, &
2488 its,ite, jts,jte, kts,kte )
2494 ids,ide, jds,jde, kds,kde, &
2495 ims,ime, jms,jme, kms,kme, &
2496 its,ite, jts,jte, kts,kte
2498 ! ierr error value, maybe modified in this routine
2499 ! q = environmental mixing ratio
2500 ! q_cup = environmental mixing ratio on cloud levels
2501 ! qes = environmental saturation mixing ratio
2502 ! qes_cup = environmental saturation mixing ratio on cloud levels
2503 ! t = environmental temp
2504 ! t_cup = environmental temp on cloud levels
2505 ! p = environmental pressure
2506 ! p_cup = environmental pressure on cloud levels
2507 ! z = environmental heights
2508 ! z_cup = environmental heights on cloud levels
2509 ! he = environmental moist static energy
2510 ! he_cup = environmental moist static energy on cloud levels
2511 ! hes = environmental saturation moist static energy
2512 ! hes_cup = environmental saturation moist static energy on cloud levels
2513 ! gamma_cup = gamma on cloud levels
2514 ! psur = surface pressure
2515 ! z1 = terrain elevation
2518 real, dimension (its:ite,kts:kte) &
2521 real, dimension (its:ite,kts:kte) &
2523 qes_cup,q_cup,he_cup,hes_cup,z_cup,p_cup,gamma_cup,t_cup
2524 real, dimension (its:ite) &
2530 integer, dimension (its:ite) &
2531 ,intent (inout) :: &
2534 ! local variables in this routine
2547 if(ierr(i).eq.0)then
2548 qes_cup(i,k)=.5*(qes(i,k-1)+qes(i,k))
2549 q_cup(i,k)=.5*(q(i,k-1)+q(i,k))
2550 hes_cup(i,k)=.5*(hes(i,k-1)+hes(i,k))
2551 he_cup(i,k)=.5*(he(i,k-1)+he(i,k))
2552 if(he_cup(i,k).gt.hes_cup(i,k))he_cup(i,k)=hes_cup(i,k)
2553 z_cup(i,k)=.5*(z(i,k-1)+z(i,k))
2554 p_cup(i,k)=.5*(p(i,k-1)+p(i,k))
2555 t_cup(i,k)=.5*(t(i,k-1)+t(i,k))
2556 gamma_cup(i,k)=(xl/cp)*(xl/(rv*t_cup(i,k) &
2557 *t_cup(i,k)))*qes_cup(i,k)
2562 if(ierr(i).eq.0)then
2563 qes_cup(i,1)=qes(i,1)
2565 hes_cup(i,1)=hes(i,1)
2567 z_cup(i,1)=.5*(z(i,1)+z1(i))
2568 p_cup(i,1)=.5*(p(i,1)+psur(i))
2570 gamma_cup(i,1)=xl/cp*(xl/(rv*t_cup(i,1) &
2571 *t_cup(i,1)))*qes_cup(i,1)
2575 END SUBROUTINE cup_env_clev
2578 SUBROUTINE cup_forcing_ens(closure_n,xland,aa0,aa1,xaa0,mbdt,dtime,ierr,ierr2,ierr3,&
2579 xf_ens,j,name,maxens,iens,iedt,maxens2,maxens3,mconv, &
2580 p_cup,ktop,omeg,zd,k22,zu,pr_ens,edt,kbcon,massflx, &
2581 iact_old_gr,dir,ensdim,massfln,icoic, &
2582 ids,ide, jds,jde, kds,kde, &
2583 ims,ime, jms,jme, kms,kme, &
2584 its,ite, jts,jte, kts,kte )
2590 ids,ide, jds,jde, kds,kde, &
2591 ims,ime, jms,jme, kms,kme, &
2592 its,ite, jts,jte, kts,kte
2593 integer, intent (in ) :: &
2594 j,ensdim,maxens,iens,iedt,maxens2,maxens3
2596 ! ierr error value, maybe modified in this routine
2597 ! pr_ens = precipitation ensemble
2598 ! xf_ens = mass flux ensembles
2599 ! massfln = downdraft mass flux ensembles used in next timestep
2600 ! omeg = omega from large scale model
2601 ! mconv = moisture convergence from large scale model
2602 ! zd = downdraft normalized mass flux
2603 ! zu = updraft normalized mass flux
2604 ! aa0 = cloud work function without forcing effects
2605 ! aa1 = cloud work function with forcing effects
2606 ! xaa0 = cloud work function with cloud effects (ensemble dependent)
2608 ! dir = "storm motion"
2609 ! mbdt = arbitrary numerical parameter
2610 ! dtime = dt over which forcing is applied
2611 ! iact_gr_old = flag to tell where convection was active
2612 ! kbcon = LFC of parcel from k22
2613 ! k22 = updraft originating level
2614 ! icoic = flag if only want one closure (usually set to zero!)
2615 ! name = deep or shallow convection flag
2617 real, dimension (ims:ime,jms:jme,1:ensdim) &
2618 ,intent (inout) :: &
2620 real, dimension (ims:ime,jms:jme,1:ensdim) &
2623 real, dimension (ims:ime,jms:jme) &
2626 real, dimension (its:ite,kts:kte) &
2629 real, dimension (its:ite,1:maxens) &
2632 real, dimension (its:ite) &
2634 aa1,edt,dir,mconv,xland
2635 real, dimension (its:ite) &
2636 ,intent (inout) :: &
2638 real, dimension (1:maxens) &
2644 integer, dimension (its:ite,jts:jte) &
2647 integer, dimension (its:ite) &
2650 integer, dimension (its:ite) &
2651 ,intent (inout) :: &
2656 character *(*), intent (in) :: &
2659 ! local variables in this routine
2662 real, dimension (1:maxens3) :: &
2664 real, dimension (1:maxens) :: &
2667 i,k,nall,n,ne,nens,nens3,iresult,iresultd,iresulte,mkxcrt,kclim
2668 parameter (mkxcrt=15)
2670 a1,massfld,xff0,xomg,aclim1,aclim2,aclim3,aclim4
2671 real, dimension(1:mkxcrt) :: &
2674 integer :: itf,nall2
2678 DATA PCRIT/850.,800.,750.,700.,650.,600.,550.,500.,450.,400., &
2679 350.,300.,250.,200.,150./
2680 DATA ACRIT/.0633,.0445,.0553,.0664,.075,.1082,.1521,.2216, &
2681 .3151,.3677,.41,.5255,.7663,1.1686,1.6851/
2682 ! GDAS DERIVED ACRIT
2683 DATA ACRITT/.203,.515,.521,.566,.625,.665,.659,.688, &
2684 .743,.813,.886,.947,1.138,1.377,1.896/
2688 !--- LARGE SCALE FORCING
2691 ! if(i.eq.ipr.and.j.eq.jpr)print *,'ierr = ',ierr(i)
2692 if(name.eq.'deeps'.and.ierr(i).gt.995)then
2693 ! print *,i,j,ierr(i),aa0(i)
2697 IF(ierr(i).eq.0)then
2700 if(p_cup(i,ktop(i)).lt.pcrit(k))then
2705 if(p_cup(i,ktop(i)).ge.pcrit(1))kclim=1
2709 aclim1=acrit(kclim)*1.e3
2710 aclim2=acrit(k)*1.e3
2711 aclim3=acritt(kclim)*1.e3
2712 aclim4=acritt(k)*1.e3
2713 ! print *,'p_cup(ktop(i)),kclim,pcrit(kclim)'
2714 ! print *,p_cup(i,ktop(i)),kclim,pcrit(kclim)
2715 ! print *,'aclim1,aclim2,aclim3,aclim4'
2716 ! print *,aclim1,aclim2,aclim3,aclim4
2717 ! print *,dtime,name,ierr(i),aa1(i),aa0(i)
2718 ! print *,dtime,name,ierr(i),aa1(i),aa0(i)
2720 !--- treatment different for this closure
2722 if(name.eq.'deeps')then
2724 xff0= (AA1(I)-AA0(I))/DTIME
2725 xff_ens3(1)=(AA1(I)-AA0(I))/dtime
2726 xff_ens3(2)=.9*xff_ens3(1)
2727 xff_ens3(3)=1.1*xff_ens3(1)
2729 !--- more original Arakawa-Schubert (climatologic value of aa0)
2732 !--- omeg is in bar/s, mconv done with omeg in Pa/s
2733 ! more like Brown (1979), or Frank-Cohen (199?)
2735 xff_ens3(4)=-omeg(i,k22(i))/9.81
2736 xff_ens3(5)=-omeg(i,kbcon(i))/9.81
2737 xff_ens3(6)=-omeg(i,1)/9.81
2739 xomg=-omeg(i,k)/9.81
2740 if(xomg.gt.xff_ens3(6))xff_ens3(6)=xomg
2743 !--- more like Krishnamurti et al.
2745 xff_ens3(7)=mconv(i)
2746 xff_ens3(8)=mconv(i)
2747 xff_ens3(9)=mconv(i)
2749 !--- more like Fritsch Chappel or Kain Fritsch (plus triggers)
2751 xff_ens3(10)=AA1(I)/(60.*20.)
2752 xff_ens3(11)=AA1(I)/(60.*30.)
2753 xff_ens3(12)=AA1(I)/(60.*40.)
2755 !--- more original Arakawa-Schubert (climatologic value of aa0)
2757 xff_ens3(13)=max(0.,(AA1(I)-aclim1)/dtime)
2758 xff_ens3(14)=max(0.,(AA1(I)-aclim2)/dtime)
2759 xff_ens3(15)=max(0.,(AA1(I)-aclim3)/dtime)
2760 xff_ens3(16)=max(0.,(AA1(I)-aclim4)/dtime)
2761 ! if(ierr2(i).gt.0.or.ierr3(i).gt.0)then
2772 XK(nens)=(XAA0(I,nens)-AA1(I))/MBDT(2)
2773 if(xk(nens).le.0.and.xk(nens).gt.-1.e-6) &
2775 if(xk(nens).gt.0.and.xk(nens).lt.1.e-6) &
2779 !--- add up all ensembles
2783 !--- for every xk, we have maxens3 xffs
2784 !--- iens is from outermost ensemble (most expensive!
2786 !--- iedt (maxens2 belongs to it)
2787 !--- is from second, next outermost, not so expensive
2789 !--- so, for every outermost loop, we have maxens*maxens2*3
2790 !--- ensembles!!! nall would be 0, if everything is on first
2791 !--- loop index, then ne would start counting, then iedt, then iens....
2796 nall=(iens-1)*maxens3*maxens*maxens2 &
2797 +(iedt-1)*maxens*maxens3 &
2800 ! over water, enfor!e small cap for some of the closures
2802 if(xland(i).lt.0.1)then
2803 if(ierr2(i).gt.0.or.ierr3(i).gt.0)then
2804 ! - ierr2 - 75 mb cap thickness, ierr3 - 125 cap thickness
2806 ! - for larger cap, set Grell closure to zero
2808 massfln(i,j,nall+1)=0.
2810 massfln(i,j,nall+2)=0.
2812 massfln(i,j,nall+3)=0.
2813 closure_n(i)=closure_n(i)-1.
2816 massfln(i,j,nall+7)=0.
2818 massfln(i,j,nall+8)=0.
2820 ! massfln(i,j,nall+9)=0.
2821 closure_n(i)=closure_n(i)-1.
2824 ! also take out some closures in general
2827 massfln(i,j,nall+4)=0.
2829 massfln(i,j,nall+5)=0.
2831 massfln(i,j,nall+6)=0.
2832 closure_n(i)=closure_n(i)-3.
2835 massfln(i,j,nall+10)=0.
2837 massfln(i,j,nall+11)=0.
2839 massfln(i,j,nall+12)=0.
2840 if(ne.eq.1)closure_n(i)=closure_n(i)-3
2842 massfln(i,j,nall+13)=0.
2844 massfln(i,j,nall+14)=0.
2846 massfln(i,j,nall+15)=0.
2847 massfln(i,j,nall+16)=0.
2848 if(ne.eq.1)closure_n(i)=closure_n(i)-4
2852 ! end water treatment
2854 !--- check for upwind convection
2858 ! call cup_direction2(i,j,dir,iact_old_gr, &
2859 ! massflx,iresult,1, &
2861 ! ids,ide, jds,jde, kds,kde, &
2862 ! ims,ime, jms,jme, kms,kme, &
2863 ! its,ite, jts,jte, kts,kte )
2864 ! if(i.eq.ipr.and.j.eq.jpr.and.iedt.eq.1.and.ne.eq.1)then
2865 ! if(iedt.eq.1.and.ne.eq.1)then
2866 ! print *,massfld,ne,iedt,iens
2867 ! print *,xk(ne),xff_ens3(1),xff_ens3(2),xff_ens3(3)
2869 ! print *,i,j,massfld,aa0(i),aa1(i)
2870 IF(XK(ne).lt.0.and.xff0.gt.0.)iresultd=1
2871 iresulte=max(iresult,iresultd)
2873 if(iresulte.eq.1)then
2875 !--- special treatment for stability closures
2879 xf_ens(i,j,nall+1)=max(0.,-xff_ens3(1)/xk(ne)) &
2881 xf_ens(i,j,nall+2)=max(0.,-xff_ens3(2)/xk(ne)) &
2883 xf_ens(i,j,nall+3)=max(0.,-xff_ens3(3)/xk(ne)) &
2885 xf_ens(i,j,nall+13)=max(0.,-xff_ens3(13)/xk(ne)) &
2887 xf_ens(i,j,nall+14)=max(0.,-xff_ens3(14)/xk(ne)) &
2889 xf_ens(i,j,nall+15)=max(0.,-xff_ens3(15)/xk(ne)) &
2891 xf_ens(i,j,nall+16)=max(0.,-xff_ens3(16)/xk(ne)) &
2894 xf_ens(i,j,nall+1)=massfld
2895 xf_ens(i,j,nall+2)=massfld
2896 xf_ens(i,j,nall+3)=massfld
2897 xf_ens(i,j,nall+13)=massfld
2898 xf_ens(i,j,nall+14)=massfld
2899 xf_ens(i,j,nall+15)=massfld
2900 xf_ens(i,j,nall+16)=massfld
2903 !--- if iresult.eq.1, following independent of xff0
2905 xf_ens(i,j,nall+4)=max(0.,xff_ens3(4) &
2907 xf_ens(i,j,nall+5)=max(0.,xff_ens3(5) &
2909 xf_ens(i,j,nall+6)=max(0.,xff_ens3(6) &
2911 a1=max(1.e-3,pr_ens(i,j,nall+7))
2912 xf_ens(i,j,nall+7)=max(0.,xff_ens3(7) &
2914 a1=max(1.e-3,pr_ens(i,j,nall+8))
2915 xf_ens(i,j,nall+8)=max(0.,xff_ens3(8) &
2917 a1=max(1.e-3,pr_ens(i,j,nall+9))
2918 xf_ens(i,j,nall+9)=max(0.,xff_ens3(9) &
2920 if(XK(ne).lt.0.)then
2921 xf_ens(i,j,nall+10)=max(0., &
2922 -xff_ens3(10)/xk(ne)) &
2924 xf_ens(i,j,nall+11)=max(0., &
2925 -xff_ens3(11)/xk(ne)) &
2927 xf_ens(i,j,nall+12)=max(0., &
2928 -xff_ens3(12)/xk(ne)) &
2931 xf_ens(i,j,nall+10)=massfld
2932 xf_ens(i,j,nall+11)=massfld
2933 xf_ens(i,j,nall+12)=massfld
2937 xf_ens(i,j,nall+1)=xf_ens(i,j,nall+icoic)
2938 xf_ens(i,j,nall+2)=xf_ens(i,j,nall+icoic)
2939 xf_ens(i,j,nall+3)=xf_ens(i,j,nall+icoic)
2940 xf_ens(i,j,nall+4)=xf_ens(i,j,nall+icoic)
2941 xf_ens(i,j,nall+5)=xf_ens(i,j,nall+icoic)
2942 xf_ens(i,j,nall+6)=xf_ens(i,j,nall+icoic)
2943 xf_ens(i,j,nall+7)=xf_ens(i,j,nall+icoic)
2944 xf_ens(i,j,nall+8)=xf_ens(i,j,nall+icoic)
2945 xf_ens(i,j,nall+9)=xf_ens(i,j,nall+icoic)
2946 xf_ens(i,j,nall+10)=xf_ens(i,j,nall+icoic)
2947 xf_ens(i,j,nall+11)=xf_ens(i,j,nall+icoic)
2948 xf_ens(i,j,nall+12)=xf_ens(i,j,nall+icoic)
2949 xf_ens(i,j,nall+13)=xf_ens(i,j,nall+icoic)
2950 xf_ens(i,j,nall+14)=xf_ens(i,j,nall+icoic)
2951 xf_ens(i,j,nall+15)=xf_ens(i,j,nall+icoic)
2952 xf_ens(i,j,nall+16)=xf_ens(i,j,nall+icoic)
2955 ! replace 13-16 for now with other stab closures
2956 ! (13 gave problems for mass model)
2958 ! xf_ens(i,j,nall+13)=xf_ens(i,j,nall+1)
2959 if(icoic.eq.0)xf_ens(i,j,nall+14)=xf_ens(i,j,nall+13)
2960 ! xf_ens(i,j,nall+15)=xf_ens(i,j,nall+11)
2961 ! xf_ens(i,j,nall+16)=xf_ens(i,j,nall+11)
2962 ! xf_ens(i,j,nall+7)=xf_ens(i,j,nall+4)
2963 ! xf_ens(i,j,nall+8)=xf_ens(i,j,nall+5)
2964 ! xf_ens(i,j,nall+9)=xf_ens(i,j,nall+6)
2966 !--- store new for next time step
2969 massfln(i,j,nall+nens3)=edt(i) &
2970 *xf_ens(i,j,nall+nens3)
2971 massfln(i,j,nall+nens3)=max(0., &
2972 massfln(i,j,nall+nens3))
2976 !--- do some more on the caps!!! ne=1 for 175, ne=2 for 100,....
2978 ! do not care for caps here for closure groups 1 and 5,
2979 ! they are fine, do not turn them off here
2982 if(ne.eq.2.and.ierr2(i).gt.0)then
2983 xf_ens(i,j,nall+1) =0.
2984 xf_ens(i,j,nall+2) =0.
2985 xf_ens(i,j,nall+3) =0.
2986 xf_ens(i,j,nall+4) =0.
2987 xf_ens(i,j,nall+5) =0.
2988 xf_ens(i,j,nall+6) =0.
2989 xf_ens(i,j,nall+7) =0.
2990 xf_ens(i,j,nall+8) =0.
2991 xf_ens(i,j,nall+9) =0.
2992 xf_ens(i,j,nall+10)=0.
2993 xf_ens(i,j,nall+11)=0.
2994 xf_ens(i,j,nall+12)=0.
2995 xf_ens(i,j,nall+13)=0.
2996 xf_ens(i,j,nall+14)=0.
2997 xf_ens(i,j,nall+15)=0.
2998 xf_ens(i,j,nall+16)=0.
2999 massfln(i,j,nall+1)=0.
3000 massfln(i,j,nall+2)=0.
3001 massfln(i,j,nall+3)=0.
3002 massfln(i,j,nall+4)=0.
3003 massfln(i,j,nall+5)=0.
3004 massfln(i,j,nall+6)=0.
3005 massfln(i,j,nall+7)=0.
3006 massfln(i,j,nall+8)=0.
3007 massfln(i,j,nall+9)=0.
3008 massfln(i,j,nall+10)=0.
3009 massfln(i,j,nall+11)=0.
3010 massfln(i,j,nall+12)=0.
3011 massfln(i,j,nall+13)=0.
3012 massfln(i,j,nall+14)=0.
3013 massfln(i,j,nall+15)=0.
3014 massfln(i,j,nall+16)=0.
3016 if(ne.eq.3.and.ierr3(i).gt.0)then
3017 xf_ens(i,j,nall+1) =0.
3018 xf_ens(i,j,nall+2) =0.
3019 xf_ens(i,j,nall+3) =0.
3020 xf_ens(i,j,nall+4) =0.
3021 xf_ens(i,j,nall+5) =0.
3022 xf_ens(i,j,nall+6) =0.
3023 xf_ens(i,j,nall+7) =0.
3024 xf_ens(i,j,nall+8) =0.
3025 xf_ens(i,j,nall+9) =0.
3026 xf_ens(i,j,nall+10)=0.
3027 xf_ens(i,j,nall+11)=0.
3028 xf_ens(i,j,nall+12)=0.
3029 xf_ens(i,j,nall+13)=0.
3030 xf_ens(i,j,nall+14)=0.
3031 xf_ens(i,j,nall+15)=0.
3032 xf_ens(i,j,nall+16)=0.
3033 massfln(i,j,nall+1)=0.
3034 massfln(i,j,nall+2)=0.
3035 massfln(i,j,nall+3)=0.
3036 massfln(i,j,nall+4)=0.
3037 massfln(i,j,nall+5)=0.
3038 massfln(i,j,nall+6)=0.
3039 massfln(i,j,nall+7)=0.
3040 massfln(i,j,nall+8)=0.
3041 massfln(i,j,nall+9)=0.
3042 massfln(i,j,nall+10)=0.
3043 massfln(i,j,nall+11)=0.
3044 massfln(i,j,nall+12)=0.
3045 massfln(i,j,nall+13)=0.
3046 massfln(i,j,nall+14)=0.
3047 massfln(i,j,nall+15)=0.
3048 massfln(i,j,nall+16)=0.
3055 nall=(iens-1)*maxens3*maxens*maxens2 &
3056 +(iedt-1)*maxens*maxens3
3059 nall2=(iens-1)*maxens3*maxens*maxens2 &
3060 +(iedt-1)*maxens*maxens3 &
3062 xf_ens(i,j,nall+4) = xf_ens(i,j,nall2+4)
3063 xf_ens(i,j,nall+5) =xf_ens(i,j,nall2+5)
3064 xf_ens(i,j,nall+6) =xf_ens(i,j,nall2+6)
3065 xf_ens(i,j,nall+7) =xf_ens(i,j,nall2+7)
3066 xf_ens(i,j,nall+8) =xf_ens(i,j,nall2+8)
3067 xf_ens(i,j,nall+9) =xf_ens(i,j,nall2+9)
3068 xf_ens(i,j,nall+10)=xf_ens(i,j,nall2+10)
3069 xf_ens(i,j,nall+11)=xf_ens(i,j,nall2+11)
3070 xf_ens(i,j,nall+12)=xf_ens(i,j,nall2+12)
3073 elseif(ierr(i).ne.20.and.ierr(i).ne.0)then
3081 END SUBROUTINE cup_forcing_ens
3084 SUBROUTINE cup_kbcon(cap_inc,iloop,k22,kbcon,he_cup,hes_cup, &
3085 ierr,kbmax,p_cup,cap_max, &
3086 ids,ide, jds,jde, kds,kde, &
3087 ims,ime, jms,jme, kms,kme, &
3088 its,ite, jts,jte, kts,kte )
3093 ! only local wrf dimensions are need as of now in this routine
3097 ids,ide, jds,jde, kds,kde, &
3098 ims,ime, jms,jme, kms,kme, &
3099 its,ite, jts,jte, kts,kte
3103 ! ierr error value, maybe modified in this routine
3105 real, dimension (its:ite,kts:kte) &
3107 he_cup,hes_cup,p_cup
3108 real, dimension (its:ite) &
3111 integer, dimension (its:ite) &
3114 integer, dimension (its:ite) &
3115 ,intent (inout) :: &
3121 ! local variables in this routine
3132 !--- DETERMINE THE LEVEL OF CONVECTIVE CLOUD BASE - KBCON
3136 IF(ierr(I).ne.0)GO TO 27
3141 IF(KBCON(I).GT.KBMAX(i)+2)THEN
3142 if(iloop.lt.4)ierr(i)=3
3143 ! if(iloop.lt.4)ierr(i)=997
3147 IF(HE_cup(I,K22(I)).LT.HES_cup(I,KBCON(I)))GO TO 31
3149 ! cloud base pressure and max moist static energy pressure
3150 ! i.e., the depth (in mb) of the layer of negative buoyancy
3151 if(KBCON(I)-K22(I).eq.1)go to 27
3152 PBCDIF=-P_cup(I,KBCON(I))+P_cup(I,K22(I))
3153 plus=max(25.,cap_max(i)-float(iloop-1)*cap_inc(i))
3154 if(iloop.eq.4)plus=cap_max(i)
3155 IF(PBCDIF.GT.plus)THEN
3162 END SUBROUTINE cup_kbcon
3165 SUBROUTINE cup_kbcon_cin(iloop,k22,kbcon,he_cup,hes_cup, &
3166 z,tmean,qes,ierr,kbmax,p_cup,cap_max,xl,cp, &
3167 ids,ide, jds,jde, kds,kde, &
3168 ims,ime, jms,jme, kms,kme, &
3169 its,ite, jts,jte, kts,kte )
3174 ! only local wrf dimensions are need as of now in this routine
3178 ids,ide, jds,jde, kds,kde, &
3179 ims,ime, jms,jme, kms,kme, &
3180 its,ite, jts,jte, kts,kte
3184 ! ierr error value, maybe modified in this routine
3186 real, dimension (its:ite,kts:kte) &
3188 he_cup,hes_cup,p_cup,z,tmean,qes
3189 real, dimension (its:ite) &
3195 integer, dimension (its:ite) &
3198 integer, dimension (its:ite) &
3199 ,intent (inout) :: &
3205 ! local variables in this routine
3211 cin,cin_max,dh,tprim,gamma
3220 !--- DETERMINE THE LEVEL OF CONVECTIVE CLOUD BASE - KBCON
3226 IF(ierr(I).ne.0)GO TO 27
3231 IF(KBCON(I).GT.KBMAX(i)+2)THEN
3232 if(iloop.eq.1)ierr(i)=3
3233 ! if(iloop.eq.2)ierr(i)=997
3237 dh = HE_cup(I,K22(I)) - HES_cup(I,KBCON(I))
3239 GAMMA=(xl/cp)*(xl/(461.525*(Tmean(I,K22(i))**2)))*QES(I,K22(i))
3240 tprim = dh/(cp*(1.+gamma))
3242 cin = cin + 9.8066 * tprim &
3243 *(z(i,k22(i))-z(i,k22(i)-1)) / tmean(i,k22(i))
3248 ! If negative energy in negatively buoyant layer
3249 ! exceeds convective inhibition (CIN) threshold,
3250 ! then set K22 level one level up and see if that
3253 IF(cin.lT.cin_max)THEN
3254 ! print *,i,cin,cin_max,k22(i),kbcon(i)
3261 END SUBROUTINE cup_kbcon_cin
3264 SUBROUTINE cup_ktop(ilo,dby,kbcon,ktop,ierr, &
3265 ids,ide, jds,jde, kds,kde, &
3266 ims,ime, jms,jme, kms,kme, &
3267 its,ite, jts,jte, kts,kte )
3274 ! only local wrf dimensions are need as of now in this routine
3278 ids,ide, jds,jde, kds,kde, &
3279 ims,ime, jms,jme, kms,kme, &
3280 its,ite, jts,jte, kts,kte
3281 ! dby = buoancy term
3282 ! ktop = cloud top (output)
3284 ! ierr error value, maybe modified in this routine
3286 real, dimension (its:ite,kts:kte) &
3287 ,intent (inout) :: &
3289 integer, dimension (its:ite) &
3295 integer, dimension (its:ite) &
3298 integer, dimension (its:ite) &
3299 ,intent (inout) :: &
3302 ! local variables in this routine
3316 IF(ierr(I).EQ.0)then
3317 DO 40 K=KBCON(I)+1,ktf-1
3318 IF(DBY(I,K).LE.0.)THEN
3323 if(ilo.eq.1)ierr(i)=5
3324 ! if(ilo.eq.2)ierr(i)=998
3333 END SUBROUTINE cup_ktop
3336 SUBROUTINE cup_MAXIMI(ARRAY,KS,KE,MAXX,ierr, &
3337 ids,ide, jds,jde, kds,kde, &
3338 ims,ime, jms,jme, kms,kme, &
3339 its,ite, jts,jte, kts,kte )
3346 ! only local wrf dimensions are need as of now in this routine
3350 ids,ide, jds,jde, kds,kde, &
3351 ims,ime, jms,jme, kms,kme, &
3352 its,ite, jts,jte, kts,kte
3354 ! x output array with return values
3355 ! kt output array of levels
3356 ! ks,kend check-range
3357 real, dimension (its:ite,kts:kte) &
3360 integer, dimension (its:ite) &
3366 integer, dimension (its:ite) &
3369 real, dimension (its:ite) :: &
3381 if(ierr(i).eq.0)then
3386 IF(XAR.GE.X(I)) THEN
3394 END SUBROUTINE cup_MAXIMI
3397 SUBROUTINE cup_minimi(ARRAY,KS,KEND,KT,ierr, &
3398 ids,ide, jds,jde, kds,kde, &
3399 ims,ime, jms,jme, kms,kme, &
3400 its,ite, jts,jte, kts,kte )
3407 ! only local wrf dimensions are need as of now in this routine
3411 ids,ide, jds,jde, kds,kde, &
3412 ims,ime, jms,jme, kms,kme, &
3413 its,ite, jts,jte, kts,kte
3415 ! x output array with return values
3416 ! kt output array of levels
3417 ! ks,kend check-range
3418 real, dimension (its:ite,kts:kte) &
3421 integer, dimension (its:ite) &
3424 integer, dimension (its:ite) &
3427 real, dimension (its:ite) :: &
3438 if(ierr(i).eq.0)then
3440 KSTOP=MAX(KS(I)+1,KEND(I))
3442 DO 100 K=KS(I)+1,KSTOP
3443 IF(ARRAY(I,K).LT.X(I)) THEN
3451 END SUBROUTINE cup_MINIMI
3454 SUBROUTINE cup_output_ens(xf_ens,ierr,dellat,dellaq,dellaqc, &
3455 outtem,outq,outqc,pre,pw,xmb,ktop, &
3456 j,name,nx,nx2,iens,ierr2,ierr3,pr_ens, &
3457 maxens3,ensdim,massfln, &
3458 APR_GR,APR_W,APR_MC,APR_ST,APR_AS, &
3459 APR_CAPMA,APR_CAPME,APR_CAPMI,closure_n,xland1, &
3460 outCFU1,outCFD1,outDFU1,outEFU1,outDFD1,outEFD1, &
3461 CFU1_ens,CFD1_ens,DFU1_ens,EFU1_ens,DFD1_ens,EFD1_ens, &
3463 ids,ide, jds,jde, kds,kde, &
3464 ims,ime, jms,jme, kms,kme, &
3465 its,ite, jts,jte, kts,kte)
3472 ! only local wrf dimensions are need as of now in this routine
3476 ids,ide, jds,jde, kds,kde, &
3477 ims,ime, jms,jme, kms,kme, &
3478 its,ite, jts,jte, kts,kte
3479 integer, intent (in ) :: &
3480 j,ensdim,nx,nx2,iens,maxens3
3481 ! xf_ens = ensemble mass fluxes
3482 ! pr_ens = precipitation ensembles
3483 ! dellat = change of temperature per unit mass flux of cloud ensemble
3484 ! dellaq = change of q per unit mass flux of cloud ensemble
3485 ! dellaqc = change of qc per unit mass flux of cloud ensemble
3486 ! outtem = output temp tendency (per s)
3487 ! outq = output q tendency (per s)
3488 ! outqc = output qc tendency (per s)
3489 ! pre = output precip
3490 ! xmb = total base mass flux
3491 ! xfac1 = correction factor
3492 ! pw = pw -epsilon*pd (ensemble dependent)
3493 ! ierr error value, maybe modified in this routine
3495 real, dimension (ims:ime,jms:jme,1:ensdim) &
3496 ,intent (inout) :: &
3497 xf_ens,pr_ens,massfln
3498 real, dimension (ims:ime,jms:jme) &
3499 ,intent (inout) :: &
3500 APR_GR,APR_W,APR_MC,APR_ST,APR_AS,APR_CAPMA, &
3503 real, dimension (its:ite,kts:kte) &
3506 real, dimension (its:ite) &
3509 real, dimension (its:ite) &
3510 ,intent (inout ) :: &
3512 real, dimension (its:ite,kts:kte,1:nx) &
3514 dellat,dellaqc,dellaq,pw
3515 integer, dimension (its:ite) &
3518 integer, dimension (its:ite) &
3519 ,intent (inout) :: &
3521 real, dimension (its:ite,kts:kte,1:ensdim) &
3523 CFU1_ens,CFD1_ens,DFU1_ens,EFU1_ens,DFD1_ens,EFD1_ens
3524 real, dimension (its:ite,kts:kte) &
3526 outCFU1,outCFD1,outDFU1,outEFU1,outDFD1,outEFD1
3527 logical, intent(in) :: l_flux
3530 ! local variables in this routine
3536 outtes,ddtes,dtt,dtq,dtqc,dtpw,tuning,prerate,clos_wei
3537 real, dimension (its:ite) :: &
3539 real, dimension (its:ite):: &
3540 xmb_ske,xmb_ave,xmb_std,xmb_cur,xmbweight
3541 real, dimension (its:ite):: &
3542 pr_ske,pr_ave,pr_std,pr_cur
3543 real, dimension (its:ite,jts:jte):: &
3544 pr_gr,pr_w,pr_mc,pr_st,pr_as,pr_capma, &
3549 character *(*), intent (in) :: &
3573 IF(ierr(i).eq.0)then
3574 do n=(iens-1)*nx*nx2*maxens3+1,iens*nx*nx2*maxens3
3575 if(pr_ens(i,j,n).le.0.)then
3582 !--- calculate ensemble average mass fluxes
3584 call massflx_stats(xf_ens,ensdim,nx2,nx,maxens3, &
3585 xmb_ave,xmb_std,xmb_cur,xmb_ske,j,ierr,1, &
3586 APR_GR,APR_W,APR_MC,APR_ST,APR_AS, &
3587 APR_CAPMA,APR_CAPME,APR_CAPMI, &
3588 pr_gr,pr_w,pr_mc,pr_st,pr_as, &
3589 pr_capma,pr_capme,pr_capmi, &
3590 ids,ide, jds,jde, kds,kde, &
3591 ims,ime, jms,jme, kms,kme, &
3592 its,ite, jts,jte, kts,kte )
3593 call massflx_stats(pr_ens,ensdim,nx2,nx,maxens3, &
3594 pr_ave,pr_std,pr_cur,pr_ske,j,ierr,2, &
3595 APR_GR,APR_W,APR_MC,APR_ST,APR_AS, &
3596 APR_CAPMA,APR_CAPME,APR_CAPMI, &
3597 pr_gr,pr_w,pr_mc,pr_st,pr_as, &
3598 pr_capma,pr_capme,pr_capmi, &
3599 ids,ide, jds,jde, kds,kde, &
3600 ims,ime, jms,jme, kms,kme, &
3601 its,ite, jts,jte, kts,kte )
3606 ! if(name.eq.'shal')ddtes=200.
3608 if(ierr(i).eq.0)then
3609 if(xmb_ave(i).le.0.)then
3613 ! xmb(i)=max(0.,xmb_ave(i))
3614 xmb(i)=max(.1*xmb_ave(i),xmb_ave(i)-tuning*xmb_std(i))
3615 ! --- Now use proper count of how many closures were actually
3616 ! used in cup_forcing_ens (including screening of some
3617 ! closures over water) to properly normalize xmb
3618 clos_wei=16./max(1.,closure_n(i))
3619 if (xland1(i).lt.0.5)xmb(i)=xmb(i)*clos_wei
3620 if(xmb(i).eq.0.)then
3623 if(xmb(i).gt.100.)then
3637 IF(ierr(i).eq.0.and.k.le.ktop(i))then
3639 dtt=dtt+dellat(i,k,n)
3640 dtq=dtq+dellaq(i,k,n)
3641 dtqc=dtqc+dellaqc(i,k,n)
3644 outtes=dtt*XMB(I)*86400./float(nx)
3645 IF((OUTTES.GT.2.*ddtes.and.k.gt.2))THEN
3646 XMB(I)= 2.*ddtes/outtes * xmb(i)
3649 if (outtes .lt. -ddtes) then
3650 XMB(I)= -ddtes/outtes * xmb(i)
3653 if (outtes .gt. .5*ddtes.and.k.le.2) then
3654 XMB(I)= ddtes/outtes * xmb(i)
3657 OUTTEM(I,K)=XMB(I)*dtt/float(nx)
3658 OUTQ(I,K)=XMB(I)*dtq/float(nx)
3659 OUTQC(I,K)=XMB(I)*dtqc/float(nx)
3660 PRE(I)=PRE(I)+XMB(I)*dtpw/float(nx)
3665 if(ierr(i).eq.0)then
3666 prerate=pre(i)*3600.
3667 if(prerate.lt.0.1)then
3668 if(ierr2(i).gt.0.or.ierr3(i).gt.0)then
3676 do k=(iens-1)*nx*nx2*maxens3+1,iens*nx*nx2*maxens3
3687 if(ierr(i).eq.0)then
3688 xfac1(i)=xmb(i)/xfac1(i)
3689 do k=(iens-1)*nx*nx2*maxens3+1,iens*nx*nx2*maxens3
3690 massfln(i,j,k)=massfln(i,j,k)*xfac1(i)
3691 xf_ens(i,j,k)=xf_ens(i,j,k)*xfac1(i)
3696 if (iens .eq. 1) then ! Only do deep convection mass fluxes
3705 if (ierr(i) .eq. 0) then
3708 n=(iens-1)*nx*nx2*maxens3 + &
3709 (iedt-1)*nx2*maxens3 + kk
3710 outcfu1(i,k)=outcfu1(i,k)+cfu1_ens(i,k,iedt)*xf_ens(i,j,n)
3711 outcfd1(i,k)=outcfd1(i,k)+cfd1_ens(i,k,iedt)*xf_ens(i,j,n)
3712 outdfu1(i,k)=outdfu1(i,k)+dfu1_ens(i,k,iedt)*xf_ens(i,j,n)
3713 outefu1(i,k)=outefu1(i,k)+efu1_ens(i,k,iedt)*xf_ens(i,j,n)
3714 outdfd1(i,k)=outdfd1(i,k)+dfd1_ens(i,k,iedt)*xf_ens(i,j,n)
3715 outefd1(i,k)=outefd1(i,k)+efd1_ens(i,k,iedt)*xf_ens(i,j,n)
3718 outcfu1(i,k)=outcfu1(i,k)/ensdim
3719 outcfd1(i,k)=outcfd1(i,k)/ensdim
3720 outdfu1(i,k)=outdfu1(i,k)/ensdim
3721 outefu1(i,k)=outefu1(i,k)/ensdim
3722 outdfd1(i,k)=outdfd1(i,k)/ensdim
3723 outefd1(i,k)=outefd1(i,k)/ensdim
3730 END SUBROUTINE cup_output_ens
3733 SUBROUTINE cup_up_aa0(aa0,z,zu,dby,GAMMA_CUP,t_cup, &
3735 ids,ide, jds,jde, kds,kde, &
3736 ims,ime, jms,jme, kms,kme, &
3737 its,ite, jts,jte, kts,kte )
3744 ! only local wrf dimensions are need as of now in this routine
3748 ids,ide, jds,jde, kds,kde, &
3749 ims,ime, jms,jme, kms,kme, &
3750 its,ite, jts,jte, kts,kte
3751 ! aa0 cloud work function
3752 ! gamma_cup = gamma on model cloud levels
3753 ! t_cup = temperature (Kelvin) on model cloud levels
3754 ! dby = buoancy term
3755 ! zu= normalized updraft mass flux
3756 ! z = heights of model levels
3757 ! ierr error value, maybe modified in this routine
3759 real, dimension (its:ite,kts:kte) &
3761 z,zu,gamma_cup,t_cup,dby
3762 integer, dimension (its:ite) &
3770 integer, dimension (its:ite) &
3771 ,intent (inout) :: &
3773 real, dimension (its:ite) &
3777 ! local variables in this routine
3787 itf = MIN(ite,ide-1)
3788 ktf = MIN(kte,kde-1)
3795 IF(ierr(i).ne.0)GO TO 100
3796 IF(K.LE.KBCON(I))GO TO 100
3797 IF(K.Gt.KTOP(I))GO TO 100
3799 da=zu(i,k)*DZ*(9.81/(1004.*( &
3800 (T_cup(I,K)))))*DBY(I,K-1)/ &
3802 IF(K.eq.KTOP(I).and.da.le.0.)go to 100
3804 if(aa0(i).lt.0.)aa0(i)=0.
3807 END SUBROUTINE cup_up_aa0
3810 SUBROUTINE cup_up_he(k22,hkb,z_cup,cd,entr,he_cup,hc, &
3811 kbcon,ierr,dby,he,hes_cup, &
3812 ids,ide, jds,jde, kds,kde, &
3813 ims,ime, jms,jme, kms,kme, &
3814 its,ite, jts,jte, kts,kte )
3821 ! only local wrf dimensions are need as of now in this routine
3825 ids,ide, jds,jde, kds,kde, &
3826 ims,ime, jms,jme, kms,kme, &
3827 its,ite, jts,jte, kts,kte
3828 ! hc = cloud moist static energy
3829 ! hkb = moist static energy at originating level
3830 ! he = moist static energy on model levels
3831 ! he_cup = moist static energy on model cloud levels
3832 ! hes_cup = saturation moist static energy on model cloud levels
3833 ! dby = buoancy term
3834 ! cd= detrainment function
3835 ! z_cup = heights of model cloud levels
3836 ! entr = entrainment rate
3838 real, dimension (its:ite,kts:kte) &
3840 he,he_cup,hes_cup,z_cup,cd
3841 ! entr= entrainment rate
3845 integer, dimension (its:ite) &
3852 ! ierr error value, maybe modified in this routine
3854 integer, dimension (its:ite) &
3855 ,intent (inout) :: &
3858 real, dimension (its:ite,kts:kte) &
3861 real, dimension (its:ite) &
3865 ! local variables in this routine
3875 itf = MIN(ite,ide-1)
3876 ktf = MIN(kte,kde-1)
3878 !--- moist static energy inside cloud
3881 if(ierr(i).eq.0.)then
3882 hkb(i)=he_cup(i,k22(i))
3887 do k=k22(i),kbcon(i)-1
3893 DBY(I,Kbcon(i))=Hkb(I)-HES_cup(I,K)
3898 if(k.gt.kbcon(i).and.ierr(i).eq.0.)then
3899 DZ=Z_cup(i,K)-Z_cup(i,K-1)
3900 HC(i,K)=(HC(i,K-1)*(1.-.5*CD(i,K)*DZ)+entr* &
3901 DZ*HE(i,K-1))/(1.+entr*DZ-.5*cd(i,k)*dz)
3902 DBY(I,K)=HC(I,K)-HES_cup(I,K)
3908 END SUBROUTINE cup_up_he
3911 SUBROUTINE cup_up_moisture(ierr,z_cup,qc,qrc,pw,pwav, &
3912 kbcon,ktop,cd,dby,mentr_rate,clw_all, &
3913 q,GAMMA_cup,zu,qes_cup,k22,qe_cup,xl, &
3914 ids,ide, jds,jde, kds,kde, &
3915 ims,ime, jms,jme, kms,kme, &
3916 its,ite, jts,jte, kts,kte )
3923 ! only local wrf dimensions are need as of now in this routine
3927 ids,ide, jds,jde, kds,kde, &
3928 ims,ime, jms,jme, kms,kme, &
3929 its,ite, jts,jte, kts,kte
3930 ! cd= detrainment function
3931 ! q = environmental q on model levels
3932 ! qe_cup = environmental q on model cloud levels
3933 ! qes_cup = saturation q on model cloud levels
3934 ! dby = buoancy term
3935 ! cd= detrainment function
3936 ! zu = normalized updraft mass flux
3937 ! gamma_cup = gamma on model cloud levels
3938 ! mentr_rate = entrainment rate
3940 real, dimension (its:ite,kts:kte) &
3942 q,zu,gamma_cup,qe_cup,dby,qes_cup,z_cup,cd
3943 ! entr= entrainment rate
3947 integer, dimension (its:ite) &
3954 ! ierr error value, maybe modified in this routine
3956 integer, dimension (its:ite) &
3957 ,intent (inout) :: &
3959 ! qc = cloud q (including liquid water) after entrainment
3960 ! qrch = saturation q in cloud
3961 ! qrc = liquid water content in cloud after rainout
3962 ! pw = condensate that will fall out at that level
3963 ! pwav = totan normalized integrated condensate (I1)
3964 ! c0 = conversion rate (cloud to rain)
3966 real, dimension (its:ite,kts:kte) &
3969 real, dimension (its:ite) &
3973 ! local variables in this routine
3979 dh,qrch,c0,dz,radius
3983 itf = MIN(ite,ide-1)
3984 ktf = MIN(kte,kde-1)
3989 !--- no precip for small clouds
3991 if(mentr_rate.gt.0.)then
3992 radius=.2/mentr_rate
3993 if(radius.lt.900.)c0=0.
3994 ! if(radius.lt.900.)iall=0
4002 if(ierr(i).eq.0)qc(i,k)=qes_cup(i,k)
4008 if(ierr(i).eq.0.)then
4009 do k=k22(i),kbcon(i)-1
4010 qc(i,k)=qe_cup(i,k22(i))
4017 IF(ierr(i).ne.0)GO TO 100
4018 IF(K.Lt.KBCON(I))GO TO 100
4019 IF(K.Gt.KTOP(I))GO TO 100
4020 DZ=Z_cup(i,K)-Z_cup(i,K-1)
4022 !------ 1. steady state plume equation, for what could
4023 !------ be in cloud without condensation
4026 QC(i,K)=(QC(i,K-1)*(1.-.5*CD(i,K)*DZ)+mentr_rate* &
4027 DZ*Q(i,K-1))/(1.+mentr_rate*DZ-.5*cd(i,k)*dz)
4029 !--- saturation in cloud, this is what is allowed to be in it
4031 QRCH=QES_cup(I,K)+(1./XL)*(GAMMA_cup(i,k) &
4032 /(1.+GAMMA_cup(i,k)))*DBY(I,K)
4034 !------- LIQUID WATER CONTENT IN cloud after rainout
4036 clw_all(i,k)=QC(I,K)-QRCH
4037 QRC(I,K)=(QC(I,K)-QRCH)/(1.+C0*DZ*zu(i,k))
4038 if(qrc(i,k).lt.0.)then
4042 !------- 3.Condensation
4044 PW(i,k)=c0*dz*QRC(I,K)*zu(i,k)
4047 pw(i,k)=(QC(I,K)-QRCH)*zu(i,k)
4048 if(pw(i,k).lt.0.)pw(i,k)=0.
4051 !----- set next level
4053 QC(I,K)=QRC(I,K)+qrch
4055 !--- integrated normalized ondensate
4057 PWAV(I)=PWAV(I)+PW(I,K)
4060 END SUBROUTINE cup_up_moisture
4063 SUBROUTINE cup_up_nms(zu,z_cup,entr,cd,kbcon,ktop,ierr,k22, &
4064 ids,ide, jds,jde, kds,kde, &
4065 ims,ime, jms,jme, kms,kme, &
4066 its,ite, jts,jte, kts,kte )
4074 ! only local wrf dimensions are need as of now in this routine
4078 ids,ide, jds,jde, kds,kde, &
4079 ims,ime, jms,jme, kms,kme, &
4080 its,ite, jts,jte, kts,kte
4081 ! cd= detrainment function
4082 real, dimension (its:ite,kts:kte) &
4085 ! entr= entrainment rate
4089 integer, dimension (its:ite) &
4096 ! ierr error value, maybe modified in this routine
4098 integer, dimension (its:ite) &
4099 ,intent (inout) :: &
4101 ! zu is the normalized mass flux
4103 real, dimension (its:ite,kts:kte) &
4107 ! local variables in this routine
4116 itf = MIN(ite,ide-1)
4117 ktf = MIN(kte,kde-1)
4119 ! initialize for this go around
4127 ! do normalized mass budget
4130 IF(ierr(I).eq.0)then
4131 do k=k22(i),kbcon(i)
4134 DO K=KBcon(i)+1,KTOP(i)
4135 DZ=Z_cup(i,K)-Z_cup(i,K-1)
4136 ZU(i,K)=ZU(i,K-1)*(1.+(entr-cd(i,k))*DZ)
4141 END SUBROUTINE cup_up_nms
4143 !====================================================================
4144 SUBROUTINE gdinit(RTHCUTEN,RQVCUTEN,RQCCUTEN,RQICUTEN, &
4145 MASS_FLUX,cp,restart, &
4146 P_QC,P_QI,P_FIRST_SCALAR, &
4148 APR_GR,APR_W,APR_MC,APR_ST,APR_AS, &
4149 APR_CAPMA,APR_CAPME,APR_CAPMI, &
4151 ids, ide, jds, jde, kds, kde, &
4152 ims, ime, jms, jme, kms, kme, &
4153 its, ite, jts, jte, kts, kte )
4154 !--------------------------------------------------------------------
4156 !--------------------------------------------------------------------
4157 LOGICAL , INTENT(IN) :: restart,allowed_to_read
4158 INTEGER , INTENT(IN) :: ids, ide, jds, jde, kds, kde, &
4159 ims, ime, jms, jme, kms, kme, &
4160 its, ite, jts, jte, kts, kte
4161 INTEGER , INTENT(IN) :: P_FIRST_SCALAR, P_QI, P_QC
4162 REAL, INTENT(IN) :: cp
4164 REAL, DIMENSION( ims:ime , kms:kme , jms:jme ) , INTENT(OUT) :: &
4170 REAL, DIMENSION( ims:ime , kms:kme , jms:jme ) , INTENT(OUT) :: &
4174 REAL, DIMENSION( ims:ime , jms:jme ) , INTENT(OUT) :: &
4175 APR_GR,APR_W,APR_MC,APR_ST,APR_AS, &
4176 APR_CAPMA,APR_CAPME,APR_CAPMI, &
4179 INTEGER :: i, j, k, itf, jtf, ktf
4185 IF(.not.restart)THEN
4204 IF (P_QC .ge. P_FIRST_SCALAR) THEN
4214 IF (P_QI .ge. P_FIRST_SCALAR) THEN
4244 END SUBROUTINE gdinit
4247 SUBROUTINE massflx_stats(xf_ens,ensdim,maxens,maxens2,maxens3, &
4248 xt_ave,xt_std,xt_cur,xt_ske,j,ierr,itest, &
4249 APR_GR,APR_W,APR_MC,APR_ST,APR_AS, &
4250 APR_CAPMA,APR_CAPME,APR_CAPMI, &
4251 pr_gr,pr_w,pr_mc,pr_st,pr_as, &
4252 pr_capma,pr_capme,pr_capmi, &
4253 ids,ide, jds,jde, kds,kde, &
4254 ims,ime, jms,jme, kms,kme, &
4255 its,ite, jts,jte, kts,kte)
4259 integer, intent (in ) :: &
4260 j,ensdim,maxens3,maxens,maxens2,itest
4261 INTEGER, INTENT(IN ) :: &
4262 ids,ide, jds,jde, kds,kde, &
4263 ims,ime, jms,jme, kms,kme, &
4264 its,ite, jts,jte, kts,kte
4267 real, dimension (its:ite) &
4268 , intent(inout) :: &
4269 xt_ave,xt_cur,xt_std,xt_ske
4270 integer, dimension (its:ite), intent (in) :: &
4272 real, dimension (ims:ime,jms:jme,1:ensdim) &
4275 real, dimension (ims:ime,jms:jme) &
4276 , intent(inout) :: &
4277 APR_GR,APR_W,APR_MC,APR_ST,APR_AS, &
4278 APR_CAPMA,APR_CAPME,APR_CAPMI
4279 real, dimension (its:ite,jts:jte) &
4280 , intent(inout) :: &
4281 pr_gr,pr_w,pr_mc,pr_st,pr_as, &
4282 pr_capma,pr_capme,pr_capmi
4287 real, dimension (its:ite , 1:maxens3 ) :: &
4288 x_ave,x_cur,x_std,x_ske
4289 real, dimension (its:ite , 1:maxens ) :: &
4293 integer, dimension (1:maxens3) :: nc1
4295 integer :: num,kk,num2,iedt
4335 if(ierr(i).eq.0)then
4336 x_ave(i,k)=x_ave(i,k)+xf_ens(i,j,maxens3*(kk-1)+k)
4345 if(ierr(i).eq.0)then
4346 x_ave_cap(i,k)=x_ave_cap(i,k) &
4347 +xf_ens(i,j,maxens3*(k-1)+(iedt-1)*maxens*maxens3+kk)
4355 if(ierr(i).eq.0)then
4356 x_ave_cap(i,k)=x_ave_cap(i,k)/float(num2)
4363 if(ierr(i).eq.0)then
4364 x_ave(i,k)=x_ave(i,k)/float(num)
4370 if(ierr(i).eq.0)then
4371 xt_ave(i)=xt_ave(i)+x_ave(i,k)
4376 if(ierr(i).eq.0)then
4377 xt_ave(i)=xt_ave(i)/float(maxens3)
4381 !--- now do std, skewness,curtosis
4386 if(ierr(i).eq.0.and.x_ave(i,k).gt.0.)then
4387 ! print *,i,j,k,kk,x_std(i,k),xf_ens(i,j,maxens3*(kk-1)+k),x_ave(i,k)
4388 x_std(i,k)=x_std(i,k)+(xf_ens(i,j,maxens3*(kk-1)+k)-x_ave(i,k))**2
4389 x_ske(i,k)=x_ske(i,k)+(xf_ens(i,j,maxens3*(kk-1)+k)-x_ave(i,k))**3
4390 x_cur(i,k)=x_cur(i,k)+(xf_ens(i,j,maxens3*(kk-1)+k)-x_ave(i,k))**4
4397 if(ierr(i).eq.0.and.xt_ave(i).gt.0.)then
4398 xt_std(i)=xt_std(i)+(x_ave(i,k)-xt_ave(i))**2
4399 xt_ske(i)=xt_ske(i)+(x_ave(i,k)-xt_ave(i))**3
4400 xt_cur(i)=xt_cur(i)+(x_ave(i,k)-xt_ave(i))**4
4406 if(ierr(i).eq.0.and.x_std(i,k).gt.0.)then
4407 x_std(i,k)=x_std(i,k)/float(num)
4408 a3=max(1.e-6,x_std(i,k))
4410 a3=max(1.e-6,x_std(i,k)**3)
4411 a4=max(1.e-6,x_std(i,k)**4)
4412 x_ske(i,k)=x_ske(i,k)/float(num)/a3
4413 x_cur(i,k)=x_cur(i,k)/float(num)/a4
4416 ! print*,'Some statistics at gridpoint i,j, ierr',i,j,ierr(i)
4417 ! print*,'statistics for closure number ',k
4418 ! print*,'Average= ',x_ave(i,k),' Std= ',x_std(i,k)
4419 ! print*,'Skewness= ',x_ske(i,k),' Curtosis= ',x_cur(i,k)
4425 if(ierr(i).eq.0.and.xt_std(i).gt.0.)then
4426 xt_std(i)=xt_std(i)/float(maxens3)
4427 a3=max(1.e-6,xt_std(i))
4429 a3=max(1.e-6,xt_std(i)**3)
4430 a4=max(1.e-6,xt_std(i)**4)
4431 xt_ske(i)=xt_ske(i)/float(maxens3)/a3
4432 xt_cur(i)=xt_cur(i)/float(maxens3)/a4
4434 ! print*,'Total ensemble independent statistics at i =',i
4435 ! print*,'Average= ',xt_ave(i),' Std= ',xt_std(i)
4436 ! print*,'Skewness= ',xt_ske(i),' Curtosis= ',xt_cur(i)
4439 ! first go around: store massflx for different closures/caps
4442 pr_gr(i,j) = .333*(x_ave(i,1)+x_ave(i,2)+x_ave(i,3))
4443 pr_w(i,j) = .333*(x_ave(i,4)+x_ave(i,5)+x_ave(i,6))
4444 pr_mc(i,j) = .333*(x_ave(i,7)+x_ave(i,8)+x_ave(i,9))
4445 pr_st(i,j) = .333*(x_ave(i,10)+x_ave(i,11)+x_ave(i,12))
4446 pr_as(i,j) = .25*(x_ave(i,13)+x_ave(i,14)+x_ave(i,15) &
4448 pr_capma(i,j) = x_ave_cap(i,1)
4449 pr_capme(i,j) = x_ave_cap(i,2)
4450 pr_capmi(i,j) = x_ave_cap(i,3)
4452 ! second go around: store preciprates (mm/hour) for different closures/caps
4454 else if (itest.eq.2)then
4455 APR_GR(i,j)=.333*(x_ave(i,1)+x_ave(i,2)+x_ave(i,3))* &
4456 3600.*pr_gr(i,j) +APR_GR(i,j)
4457 APR_W(i,j)=.333*(x_ave(i,4)+x_ave(i,5)+x_ave(i,6))* &
4458 3600.*pr_w(i,j) +APR_W(i,j)
4459 APR_MC(i,j)=.333*(x_ave(i,7)+x_ave(i,8)+x_ave(i,9))* &
4460 3600.*pr_mc(i,j) +APR_MC(i,j)
4461 APR_ST(i,j)=.333*(x_ave(i,10)+x_ave(i,11)+x_ave(i,12))* &
4462 3600.*pr_st(i,j) +APR_ST(i,j)
4463 APR_AS(i,j)=.25*(x_ave(i,13)+x_ave(i,14)+x_ave(i,15) &
4465 3600.*pr_as(i,j) +APR_AS(i,j)
4466 APR_CAPMA(i,j) = x_ave_cap(i,1)* &
4467 3600.*pr_capma(i,j) +APR_CAPMA(i,j)
4468 APR_CAPME(i,j) = x_ave_cap(i,2)* &
4469 3600.*pr_capme(i,j) +APR_CAPME(i,j)
4470 APR_CAPMI(i,j) = x_ave_cap(i,3)* &
4471 3600.*pr_capmi(i,j) +APR_CAPMI(i,j)
4476 END SUBROUTINE massflx_stats
4479 SUBROUTINE neg_check(dt,q,outq,outt,outqc,pret,its,ite,kts,kte,itf,ktf)
4481 INTEGER, INTENT(IN ) :: its,ite,kts,kte,itf,ktf
4483 real, dimension (its:ite,kts:kte ) , &
4486 real, dimension (its:ite ) , &
4492 real :: thresh,qmem,qmemf,qmem2,qtest,qmem1
4494 ! first do check on vertical heating rate
4501 qmem=outt(i,k)*86400.
4502 if(qmem.gt.2.*thresh)then
4503 qmem2=2.*thresh/qmem
4504 qmemf=min(qmemf,qmem2)
4507 ! print *,'1',' adjusted massflux by factor ',i,k,qmem,qmem2,qmemf
4509 if(qmem.lt.-thresh)then
4511 qmemf=min(qmemf,qmem2)
4514 ! print *,'2',' adjusted massflux by factor ',i,k,qmem,qmem2,qmemf
4518 outq(i,k)=outq(i,k)*qmemf
4519 outt(i,k)=outt(i,k)*qmemf
4520 outqc(i,k)=outqc(i,k)*qmemf
4522 pret(i)=pret(i)*qmemf
4525 ! check whether routine produces negative q's. This can happen, since
4526 ! tendencies are calculated based on forced q's. This should have no
4527 ! influence on conservation properties, it scales linear through all
4535 if(abs(qmem).gt.0.)then
4536 qtest=q(i,k)+outq(i,k)*dt
4537 if(qtest.lt.thresh)then
4539 ! qmem2 would be the maximum allowable tendency
4542 qmem2=(thresh-q(i,k))/dt
4543 qmemf=min(qmemf,qmem2/qmem1)
4544 ! qmemf=max(0.,qmemf)
4545 ! print *,'4 adjusted tendencies ',i,k,qmem,qmem2,qmemf
4550 outq(i,k)=outq(i,k)*qmemf
4551 outt(i,k)=outt(i,k)*qmemf
4552 outqc(i,k)=outqc(i,k)*qmemf
4554 pret(i)=pret(i)*qmemf
4557 END SUBROUTINE neg_check
4560 !-------------------------------------------------------
4561 END MODULE module_cu_gd