16 SUBROUTINE calwxt_ramer_post(T,Q,PMID,PINT,LMH,PREC,PTYP)
27 use params_mod,
only: pq0, a2, a3, a4
28 use ctlblk_mod,
only: me, im, jsta_2l, jend_2u, lm, lp1, jsta, jend, pthresh,&
29 ista, iend, ista_2l, iend_2u
33 LOGICAL,
parameter :: trace = .false.
35 real,
PARAMETER :: twice=266.55,rhprcp=0.80,deltag=1.02,prcpmin=0.3, &
36 & emelt=0.045,rlim=0.04,slim=0.85
37 real,
PARAMETER :: twmelt=273.15,tz=273.15,efac=1.0
39 INTEGER*4 i, k1, lll, k2, toodry, iflag, nq
41 REAL xxx ,mye, icefrac,flg,flag
42 real,
DIMENSION(ista_2l:iend_2u,jsta_2l:jend_2u,LM),
intent(in) :: T,Q,PMID
43 real,
DIMENSION(ista_2l:iend_2u,jsta_2l:jend_2u,LP1),
intent(in) :: PINT
44 real,
DIMENSION(ista_2l:iend_2u,jsta_2l:jend_2u),
intent(in) :: LMH,PREC
45 integer,
DIMENSION(ista:iend,jsta:jend),
intent(inout) :: PTYP
47 real,
DIMENSION(ista_2l:iend_2u,jsta_2l:jend_2u,LM) :: P,TQ,PQ,RHQ
48 real,
DIMENSION(ista:iend,jsta:jend,LM) :: TWQ
51 integer J,L,LEV,LNQ,LMHK,ii
52 real RHMAX,TWMAX,PTOP,dpdrh,twtop,rhtop,wgt1,wgt2, &
53 rhavg,dtavg,dpk,ptw,rate,pbot,qc, b
54 real,
external :: xmytw_post,esat,tdofesat
59 IF (trace)
WRITE (20,*)
'******* NEW STATION ******'
60 IF (trace)
WRITE (20,*)
'Twmelt,Twice,rhprcp,Emelt'
61 IF (trace)
WRITE (20,*) twmelt, twice, rhprcp, emelt
71 p(i,j,l) = pmid(i,j,l)
72 qc = pq0/p(i,j,l) * exp(a2*(t(i,j,l)-a3)/(t(i,j,l)-a4))
73 tq(i,j,lev) = t(i,j,l)
74 pq(i,j,lev) = p(i,j,l)/100.
75 rhq(i,j,lev) = max(0.0, q(i,j,l)/qc)
86 IF (prec(i,j)<=pthresh) cycle
99 IF (trace)
WRITE (20,*)
'rhq(1)', rhq(i,j,1),
'me=',me
100 IF (rhq(i,j,1)<rhprcp)
THEN
111 xxx = max(0.0,min(pq(i,j,l),esat(tq(i,j,l),flag,flg))*rhq(i,j,l))
112 xxx = tdofesat(xxx,flag,flg)
113 twq(i,j,l) = xmytw_post(tq(i,j,l),xxx,pq(i,j,l))
118 IF (trace)
WRITE (*,*)
'Twq(I,J,L),L ', twq(i,j,l), l,
'me=',me
119 twmax = max(twq(i,j,l),twmax)
120 IF (trace)
WRITE (*,*)
'Tw,Rh,P ', twq(i,j,l) - 273.15, &
121 rhq(i,j,l), pq(i,j,l),
'me=',me
122 IF (pq(i,j,l)>=400.0)
THEN
123 IF (rhq(i,j,l)>rhmax)
THEN
126 IF (trace)
WRITE (*,*)
'rhmax,k2,L', rhmax, k2, l
130 IF (trace)
WRITE (*,*)
'ME: toodry,L', toodry, l
131 IF (rhq(i,j,l)>=rhprcp.or.toodry==0)
THEN
133 dpdrh = alog(pq(i,j,l)/pq(i,j,l-1)) / &
134 (rhq(i,j,l)-rhq(i,j,l-1))
135 pbot = exp(alog(pq(i,j,l))+(rhprcp-rhq(i,j,l))*dpdrh)
142 IF (trace)
WRITE (*,*) &
143 'dpdrh,pbot,rhprcp-rhq(I,J,L),L,ptw,toodry', &
144 dpdrh, pbot, rhprcp - rhq(i,j,l), &
146 ELSE IF (rhq(i,j,l)>=rhprcp)
THEN
148 IF (trace)
WRITE (*,*)
'HERE1: ptw,toodry',ptw, toodry
151 dpdrh = alog(pq(i,j,l)/pq(i,j,l-1)) / &
152 (rhq(i,j,l)-rhq(i,j,l-1))
153 ptw = exp(alog(pq(i,j,l))+(rhprcp-rhq(i,j,l))*dpdrh)
154 IF (trace)
WRITE (*,*)
'HERE2:dpdrh,pbot,L,ptw,toodry', &
155 dpdrh, pbot, l, ptw, toodry
161 IF (trace)
WRITE (*,*)
'HERE3:pbot,ptw,deltag', &
163 IF (pbot/ptw>=deltag)
THEN
177 IF (twq(i,j,1)>=273.15+2.0)
THEN
179 IF (trace) print *,
'liquid',i,j,
'me=',me
184 IF (twmax<=twice)
THEN
192 IF (trace)
WRITE (*,*)
'HERE6: k1,ptyp', k1, ptyp(i,j),
'me=',me
198 IF (ptop==pq(i,j,k1))
THEN
206 wgt1 = alog(ptop/pq(i,j,k2)) / alog(pq(i,j,k1)/pq(i,j,k2))
209 twtop = twq(i,j,k1) * wgt1 + twq(i,j,k2) * wgt2
210 rhtop = rhq(i,j,k1) * wgt1 + rhq(i,j,k2) * wgt2
216 twmax = amax1(twq(i,j,l),twmax)
220 IF (i==1.and.j==1)
WRITE (*,*)
'twmax=',twmax,twice,
'twtop=',twtop
221 IF (twtop<=twice)
THEN
223 IF (twmax<=twmelt)
THEN
224 IF (trace) print *,
'solid'
237 IF (trace) print *, ptop, twtop - 273.15, icefrac,
'me=',me
238 IF (trace)
WRITE (*,*)
'P,Tw,frac,twq(I,J,k1)', ptop, &
239 & twtop - 273.15, icefrac, twq(i,j,k1),
'me=',me
240 IF (icefrac>=1.0)
THEN
241 IF (trace)
WRITE (*,*)
'ICEFRAC=1', icefrac
243 IF (twq(i,j,k1)<twmelt)
GO TO 40
244 IF (twq(i,j,k1)==twtop)
GO TO 40
245 wgt1 = (twmelt-twq(i,j,k1)) / (twtop-twq(i,j,k1))
246 rhavg = rhq(i,j,k1) + wgt1 * (rhtop-rhq(i,j,k1)) / 2
247 dtavg = (twmelt-twq(i,j,k1)) / 2
248 dpk = wgt1 * alog(pq(i,j,k1)/ptop)
250 mye = emelt * rhavg ** efac
251 icefrac = icefrac + dpk * dtavg / mye
252 IF (trace)
WRITE (*,*) &
253 &
'HERE8: wgt1,rhavg,dtavg,dpk,mye,icefrac', wgt1, rhavg, &
254 & dtavg, dpk, mye, icefrac,
'me=',me
255 ELSE IF (icefrac<=0.0)
THEN
256 IF (trace)
WRITE (*,*)
'HERE9: twtop,twq(I,J,k1),k1,lll' &
257 & , twtop, twq(i,j,k1), k1, lll
261 IF (twq(i,j,k1)>twice)
GO TO 40
262 IF (twq(i,j,k1)==twtop)
THEN
265 wgt1 = (twice-twq(i,j,k1)) / (twtop-twq(i,j,k1))
267 rhavg = rhq(i,j,k1) + wgt1 * (rhtop-rhq(i,j,k1)) / 2
268 dtavg = twmelt - (twq(i,j,k1)+twice) / 2
269 dpk = wgt1 * alog(pq(i,j,k1)/ptop)
271 mye = emelt * rhavg ** efac
272 icefrac = icefrac + dpk * dtavg / mye
273 IF (trace)
WRITE (*,*)
'HERE10: wgt1,rhtop,rhq(I,J,k1),dtavg', &
274 wgt1, rhtop, rhq(i,j,k1), dtavg,
'me=',me
275 ELSE IF ((twq(i,j,k1)<=twmelt).and.(twq(i,j,k1)<twmelt))
THEN
276 rhavg = (rhq(i,j,k1)+rhtop) / 2
277 dtavg = twmelt - (twq(i,j,k1)+twtop) / 2
278 dpk = alog(pq(i,j,k1)/ptop)
280 mye = emelt * rhavg ** efac
281 icefrac = icefrac + dpk * dtavg / mye
283 IF (trace)
WRITE (*,*)
'HERE11: twq(i,j,K1),twtop', &
284 twq(i,j,k1),twtop,
'me=',me
286 IF (twq(i,j,k1)==twtop)
GO TO 40
287 wgt1 = (twmelt-twq(i,j,k1)) / (twtop-twq(i,j,k1))
289 rhavg = rhtop + wgt2 * (rhq(i,j,k1)-rhtop) / 2
290 dtavg = (twmelt-twtop) / 2
291 dpk = wgt2 * alog(pq(i,j,k1)/ptop)
293 mye = emelt * rhavg ** efac
294 icefrac = icefrac + dpk * dtavg / mye
295 icefrac = amin1(1.0,amax1(icefrac,0.0))
296 IF (trace)
WRITE (*,*)
'HERE12: twq(I,J,k1),twtop,icefrac,wgt1,wg'// &
297 't2,rhavg,rhtop,rhq(I,J,k1),dtavg,k1', &
298 twq(i,j,k1), twtop, &
299 icefrac,wgt1,wgt2, rhavg, rhtop, rhq(i,j,k1), dtavg, k1 ,
'me=',me
300 IF (icefrac<=0.0)
THEN
303 IF (twq(i,j,k1)>twice)
GO TO 40
304 wgt1 = (twice-twq(i,j,k1)) / (twtop-twq(i,j,k1))
305 dtavg = twmelt - (twq(i,j,k1)+twice) / 2
306 IF (trace)
WRITE (*,*)
'IN IF',
'me=',me
308 dtavg = (twmelt-twq(i,j,k1)) / 2
309 IF (trace)
WRITE (*,*)
'IN ELSE',
'me=',me
311 IF (trace)
WRITE (*,*)
'NEW ICE FRAC CALC',
'me=',me
312 rhavg = rhq(i,j,k1) + wgt1 * (rhtop-rhq(i,j,k1)) / 2
313 dpk = wgt1 * alog(pq(i,j,k1)/ptop)
315 mye = emelt * rhavg ** efac
316 icefrac = icefrac + dpk * dtavg / mye
317 IF (trace)
WRITE (*,*)
'HERE13: icefrac,k1,dtavg,rhavg', &
318 icefrac, k1, dtavg, rhavg,
'me=',me
321 icefrac = amin1(1.0,amax1(icefrac,0.0))
322 IF (i==1.and.j==1)
WRITE (*,*)
'NEW ICEFRAC:', icefrac, icefrac,
'me=',me
326 IF (trace)
WRITE (*,*)
'LOOPING BACK',
'me=',me
337 IF (trace)
WRITE (*,*)
'P,Tw,frac,lll', pq(i,j,k1), &
338 twq(i,j,k2) - 273.15, icefrac, lll,
'me=',me
340 IF (icefrac>=slim)
THEN
343 IF (trace)
WRITE (*,*)
'frozen',i,j,
'me=',me
346 IF (trace)
WRITE (*,*)
'snow',i,j,
'me=',me
348 ELSE IF (icefrac<=rlim)
THEN
349 IF (twq(i,j,1)<tz)
THEN
351 IF (trace)
WRITE (*,*)
'freezing',i,j,
'me=',me
354 IF (trace)
WRITE (*,*)
'liquid',i,j,
'me=',me
357 IF (trace)
WRITE (*,*)
'Mix',i,j
358 IF (twq(i,j,1)<tz)
THEN
359 IF (trace)
WRITE (*,*)
'freezing',i,j
374 IF (trace)
WRITE (*,*)
"Returned ptyp is:ptyp,lll ", ptyp, lll,
'me=',me
375 IF (trace)
WRITE (*,*)
"Returned icefrac is: ", icefrac,
'me=',me
383 REAL*4 FUNCTION esat(t,flag,flg)
396 IF (k<100.) k = k + 273.15
399 IF (k<0.0.or.k>373.15)
THEN
411 esat = exp(26.660820-0.0091379024*k-6106.3960/k)
416 REAL*4 FUNCTION tdofesat(es,flag,flg)
423 real*4 es, lim1, lim2, b
425 DATA lim1, lim2 /3.777647e-05, 980.5386/
431 IF (es<0.0.or.es>lim2)
THEN
443 b = 26.66082 - alog(es)
444 tdofesat = (b-sqrt(b*b-223.1986)) / 0.0182758048
451 FUNCTION xmytw_post(t,td,p)
455 INTEGER*4 cflag, l,i,j
456 real*4 f, c0, c1, c2, k, kd, kw, ew, t, td, p, ed, fp, s, &
458 DATA f, c0, c1, c2 /0.0006355, 26.66082, 0.0091379024, 6106.3960/
461 xmytw_post= (t+td) / 2
474 if (kd == 0.0)
write(*,*)
' kd=',kd,
' t=',t,
' p=',p,
' td=',td
476 ed = c0 - c1 * kd - c2 / kd
477 IF (ed<-14.0.or.ed>7.0)
RETURN
479 ew = c0 - c1 * k - c2 / k
480 IF (ew<-14.0.or.ew>7.0)
RETURN
484 kw = (k*fp+kd*s) / (fp+s)
487 ew = c0 - c1 * kw - c2 / kw
488 IF (ew<-14.0.or.ew>7.0)
RETURN
490 de = fp * (k-kw) + ed - ew
491 IF (abs(de/ew)<1e-5)
exit
492 s = ew * (c1-c2/(kw*kw)) - fp
498 xmytw_post= kw - 273.15