15 SUBROUTINE calwxt_ramer_post(T,Q,PMID,PINT,LMH,PREC,PTYP)
27 use ctlblk_mod
, only: me, im, jsta_2l, jend_2u, lm, lp1, jsta, jend, pthresh
31 LOGICAL,
parameter :: trace = .false.
33 real,
PARAMETER :: twice=266.55,rhprcp=0.80,deltag=1.02,prcpmin=0.3, &
34 & emelt=0.045,rlim=0.04,slim=0.85
35 real,
PARAMETER :: twmelt=273.15,tz=273.15,efac=1.0
37 INTEGER*4 i, k1, lll, k2, toodry, iflag, nq
39 REAL xxx ,mye, icefrac,flg,flag
40 real,
DIMENSION(IM,jsta_2l:jend_2u,LM),
intent(in) :: t,q,pmid
41 real,
DIMENSION(IM,jsta_2l:jend_2u,LP1),
intent(in) :: pint
42 real,
DIMENSION(IM,jsta_2l:jend_2u),
intent(in) :: lmh,prec
43 integer,
DIMENSION(IM,jsta:jend),
intent(inout) :: ptyp
45 real,
DIMENSION(IM,jsta_2l:jend_2u,LM) :: p,tq,pq,rhq
46 real,
DIMENSION(IM,jsta:jend,LM) :: twq
49 integer j,l,lev,lnq,lmhk,ii
50 real rhmax,twmax,ptop,dpdrh,twtop,rhtop,wgt1,wgt2, &
51 rhavg,dtavg,dpk,ptw,rate,pbot,qc, b
52 real,
external :: xmytw_post,esat,tdofesat
57 IF (trace)
WRITE (20,*)
'******* NEW STATION ******'
58 IF (trace)
WRITE (20,*)
'Twmelt,Twice,rhprcp,Emelt'
59 IF (trace)
WRITE (20,*) twmelt, twice, rhprcp, emelt
69 p(i,j,l) = pmid(i,j,l)
70 qc = pq0/p(i,j,l) * exp(a2*(t(i,j,l)-a3)/(t(i,j,l)-a4))
71 tq(i,j,lev) = t(i,j,l)
72 pq(i,j,lev) = p(i,j,l)/100.
73 rhq(i,j,lev) = max(0.0, q(i,j,l)/qc)
84 IF (prec(i,j)<=pthresh) cycle
97 IF (trace)
WRITE (20,*)
'rhq(1)', rhq(i,j,1),
'me=',me
98 IF (rhq(i,j,1)<rhprcp)
THEN
109 xxx = max(0.0,min(pq(i,j,l),esat(tq(i,j,l),flag,flg))*rhq(i,j,l))
110 xxx = tdofesat(xxx,flag,flg)
111 twq(i,j,l) = xmytw_post(tq(i,j,l),xxx,pq(i,j,l))
116 IF (trace)
WRITE (*,*)
'Twq(I,J,L),L ', twq(i,j,l), l,
'me=',me
117 twmax = max(twq(i,j,l),twmax)
118 IF (trace)
WRITE (*,*)
'Tw,Rh,P ', twq(i,j,l) - 273.15, &
119 rhq(i,j,l), pq(i,j,l),
'me=',me
120 IF (pq(i,j,l)>=400.0)
THEN
121 IF (rhq(i,j,l)>rhmax)
THEN
124 IF (trace)
WRITE (*,*)
'rhmax,k2,L', rhmax, k2, l
128 IF (trace)
WRITE (*,*)
'ME: toodry,L', toodry, l
129 IF (rhq(i,j,l)>=rhprcp.or.toodry==0)
THEN
131 dpdrh = alog(pq(i,j,l)/pq(i,j,l-1)) / &
132 (rhq(i,j,l)-rhq(i,j,l-1))
133 pbot = exp(alog(pq(i,j,l))+(rhprcp-rhq(i,j,l))*dpdrh)
140 IF (trace)
WRITE (*,*) &
141 'dpdrh,pbot,rhprcp-rhq(I,J,L),L,ptw,toodry', &
142 dpdrh, pbot, rhprcp - rhq(i,j,l), &
144 ELSE IF (rhq(i,j,l)>=rhprcp)
THEN
146 IF (trace)
WRITE (*,*)
'HERE1: ptw,toodry',ptw, toodry
149 dpdrh = alog(pq(i,j,l)/pq(i,j,l-1)) / &
150 (rhq(i,j,l)-rhq(i,j,l-1))
151 ptw = exp(alog(pq(i,j,l))+(rhprcp-rhq(i,j,l))*dpdrh)
152 IF (trace)
WRITE (*,*)
'HERE2:dpdrh,pbot,L,ptw,toodry', &
153 dpdrh, pbot, l, ptw, toodry
159 IF (trace)
WRITE (*,*)
'HERE3:pbot,ptw,deltag', &
161 IF (pbot/ptw>=deltag)
THEN
175 IF (twq(i,j,1)>=273.15+2.0)
THEN
177 IF (trace) print *,
'liquid',i,j,
'me=',me
182 IF (twmax<=twice)
THEN
190 IF (trace)
WRITE (*,*)
'HERE6: k1,ptyp', k1, ptyp(i,j),
'me=',me
196 IF (ptop==pq(i,j,k1))
THEN
204 wgt1 = alog(ptop/pq(i,j,k2)) / alog(pq(i,j,k1)/pq(i,j,k2))
207 twtop = twq(i,j,k1) * wgt1 + twq(i,j,k2) * wgt2
208 rhtop = rhq(i,j,k1) * wgt1 + rhq(i,j,k2) * wgt2
214 twmax = amax1(twq(i,j,l),twmax)
218 IF (i==1.and.j==1)
WRITE (*,*)
'twmax=',twmax,twice,
'twtop=',twtop
219 IF (twtop<=twice)
THEN
221 IF (twmax<=twmelt)
THEN
222 IF (trace) print *,
'solid'
235 IF (trace) print *, ptop, twtop - 273.15, icefrac,
'me=',me
236 IF (trace)
WRITE (*,*)
'P,Tw,frac,twq(I,J,k1)', ptop, &
237 & twtop - 273.15, icefrac, twq(i,j,k1),
'me=',me
238 IF (icefrac>=1.0)
THEN
239 IF (trace)
WRITE (*,*)
'ICEFRAC=1', icefrac
241 IF (twq(i,j,k1)<twmelt) go to 40
242 IF (twq(i,j,k1)==twtop) go to 40
243 wgt1 = (twmelt-twq(i,j,k1)) / (twtop-twq(i,j,k1))
244 rhavg = rhq(i,j,k1) + wgt1 * (rhtop-rhq(i,j,k1)) / 2
245 dtavg = (twmelt-twq(i,j,k1)) / 2
246 dpk = wgt1 * alog(pq(i,j,k1)/ptop)
248 mye = emelt * rhavg ** efac
249 icefrac = icefrac + dpk * dtavg / mye
250 IF (trace)
WRITE (*,*) &
251 &
'HERE8: wgt1,rhavg,dtavg,dpk,mye,icefrac', wgt1, rhavg, &
252 & dtavg, dpk, mye, icefrac,
'me=',me
253 ELSE IF (icefrac<=0.0)
THEN
254 IF (trace)
WRITE (*,*)
'HERE9: twtop,twq(I,J,k1),k1,lll' &
255 & , twtop, twq(i,j,k1), k1, lll
259 IF (twq(i,j,k1)>twice) go to 40
260 IF (twq(i,j,k1)==twtop)
THEN
263 wgt1 = (twice-twq(i,j,k1)) / (twtop-twq(i,j,k1))
265 rhavg = rhq(i,j,k1) + wgt1 * (rhtop-rhq(i,j,k1)) / 2
266 dtavg = twmelt - (twq(i,j,k1)+twice) / 2
267 dpk = wgt1 * alog(pq(i,j,k1)/ptop)
269 mye = emelt * rhavg ** efac
270 icefrac = icefrac + dpk * dtavg / mye
271 IF (trace)
WRITE (*,*)
'HERE10: wgt1,rhtop,rhq(I,J,k1),dtavg', &
272 wgt1, rhtop, rhq(i,j,k1), dtavg,
'me=',me
273 ELSE IF ((twq(i,j,k1)<=twmelt).and.(twq(i,j,k1)<twmelt))
THEN
274 rhavg = (rhq(i,j,k1)+rhtop) / 2
275 dtavg = twmelt - (twq(i,j,k1)+twtop) / 2
276 dpk = alog(pq(i,j,k1)/ptop)
278 mye = emelt * rhavg ** efac
279 icefrac = icefrac + dpk * dtavg / mye
281 IF (trace)
WRITE (*,*)
'HERE11: twq(i,j,K1),twtop', &
282 twq(i,j,k1),twtop,
'me=',me
284 IF (twq(i,j,k1)==twtop) go to 40
285 wgt1 = (twmelt-twq(i,j,k1)) / (twtop-twq(i,j,k1))
287 rhavg = rhtop + wgt2 * (rhq(i,j,k1)-rhtop) / 2
288 dtavg = (twmelt-twtop) / 2
289 dpk = wgt2 * alog(pq(i,j,k1)/ptop)
291 mye = emelt * rhavg ** efac
292 icefrac = icefrac + dpk * dtavg / mye
293 icefrac = amin1(1.0,amax1(icefrac,0.0))
294 IF (trace)
WRITE (*,*)
'HERE12: twq(I,J,k1),twtop,icefrac,wgt1,wg'// &
295 't2,rhavg,rhtop,rhq(I,J,k1),dtavg,k1', &
296 twq(i,j,k1), twtop, &
297 icefrac,wgt1,wgt2, rhavg, rhtop, rhq(i,j,k1), dtavg, k1 ,
'me=',me
298 IF (icefrac<=0.0)
THEN
301 IF (twq(i,j,k1)>twice) go to 40
302 wgt1 = (twice-twq(i,j,k1)) / (twtop-twq(i,j,k1))
303 dtavg = twmelt - (twq(i,j,k1)+twice) / 2
304 IF (trace)
WRITE (*,*)
'IN IF',
'me=',me
306 dtavg = (twmelt-twq(i,j,k1)) / 2
307 IF (trace)
WRITE (*,*)
'IN ELSE',
'me=',me
309 IF (trace)
WRITE (*,*)
'NEW ICE FRAC CALC',
'me=',me
310 rhavg = rhq(i,j,k1) + wgt1 * (rhtop-rhq(i,j,k1)) / 2
311 dpk = wgt1 * alog(pq(i,j,k1)/ptop)
313 mye = emelt * rhavg ** efac
314 icefrac = icefrac + dpk * dtavg / mye
315 IF (trace)
WRITE (*,*)
'HERE13: icefrac,k1,dtavg,rhavg', &
316 icefrac, k1, dtavg, rhavg,
'me=',me
319 icefrac = amin1(1.0,amax1(icefrac,0.0))
320 IF (i==1.and.j==1)
WRITE (*,*)
'NEW ICEFRAC:', icefrac, icefrac,
'me=',me
324 IF (trace)
WRITE (*,*)
'LOOPING BACK',
'me=',me
335 IF (trace)
WRITE (*,*)
'P,Tw,frac,lll', pq(i,j,k1), &
336 twq(i,j,k2) - 273.15, icefrac, lll,
'me=',me
338 IF (icefrac>=slim)
THEN
341 IF (trace)
WRITE (*,*)
'frozen',i,j,
'me=',me
344 IF (trace)
WRITE (*,*)
'snow',i,j,
'me=',me
346 ELSE IF (icefrac<=rlim)
THEN
347 IF (twq(i,j,1)<tz)
THEN
349 IF (trace)
WRITE (*,*)
'freezing',i,j,
'me=',me
352 IF (trace)
WRITE (*,*)
'liquid',i,j,
'me=',me
355 IF (trace)
WRITE (*,*)
'Mix',i,j
356 IF (twq(i,j,1)<tz)
THEN
357 IF (trace)
WRITE (*,*)
'freezing',i,j
372 IF (trace)
WRITE (*,*)
"Returned ptyp is:ptyp,lll ", ptyp, lll,
'me=',me
373 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(0,*)
' 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