GFS Operational Physics Documentation  Revision: 81451
gwdps.f
Go to the documentation of this file.
1 
4 
123 
134 
183  SUBROUTINE gwdps(IM,IX,IY,KM,A,B,C,U1,V1,T1,Q1,KPBL,
184  & prsi,del,prsl,prslk,phii, phil,deltim,kdt,
185  & hprime,oc,oa4,clx4,theta,sigma,gamma,elvmax,
186  & dusfc,dvsfc,g, cp, rd, rv, imx,
187  & nmtvr, cdmbgwd, me, lprnt, ipr)
188 !
189 ! ********************************************************************
190 ! -----> I M P L E M E N T A T I O N V E R S I O N <----------
191 !
192 ! --- Not in this code -- History of GWDP at NCEP----
193 ! ---------------- -----------------------
194 ! VERSION 3 MODIFIED FOR GRAVITY WAVES, LOCATION: .FR30(V3GWD) *J*
195 !--- 3.1 INCLUDES VARIABLE SATURATION FLUX PROFILE CF ISIGST
196 !--- 3.G INCLUDES PS COMBINED W/ PH (GLAS AND GFDL)
197 !----- ALSO INCLUDED IS RI SMOOTH OVER A THICK LOWER LAYER
198 !----- ALSO INCLUDED IS DECREASE IN DE-ACC AT TOP BY 1/2
199 !----- THE NMC GWD INCORPORATING BOTH GLAS(P&S) AND GFDL(MIGWD)
200 !----- MOUNTAIN INDUCED GRAVITY WAVE DRAG
201 !----- CODE FROM .FR30(V3MONNX) FOR MONIN3
202 !----- THIS VERSION (06 MAR 1987)
203 !----- THIS VERSION (26 APR 1987) 3.G
204 !----- THIS VERSION (01 MAY 1987) 3.9
205 !----- CHANGE TO FORTRAN 77 (FEB 1989) --- HANN-MING HENRY JUANG
206 !----- 20070601 ELVMAX bug fix (*j*)
207 !
208 ! VERSION 4
209 ! ----- This code -----
210 !
211 !----- MODIFIED TO IMPLEMENT THE ENHANCED LOW TROPOSPHERIC GRAVITY
212 !----- WAVE DRAG DEVELOPED BY KIM AND ARAKAWA(JAS, 1995).
213 ! Orographic Std Dev (hprime), Convexity (OC), Asymmetry (OA4)
214 ! and Lx (CLX4) are input topographic statistics needed.
215 !
216 !----- PROGRAMMED AND DEBUGGED BY HONG, ALPERT AND KIM --- JAN 1996.
217 !----- debugged again - moorthi and iredell --- may 1998.
218 !-----
219 ! Further Cleanup, optimization and modification
220 ! - S. Moorthi May 98, March 99.
221 !----- modified for usgs orography data (ncep office note 424)
222 ! and with several bugs fixed - moorthi and hong --- july 1999.
223 !
224 !----- Modified & implemented into NRL NOGAPS
225 ! - Young-Joon Kim, July 2000
226 !-----
227 ! VERSION lm MB (6): oz fix 8/2003
228 ! ----- This code -----
229 !
230 !------ Changed to include the Lott and Miller Mtn Blocking
231 ! with some modifications by (*j*) 4/02
232 ! From a Principal Coordinate calculation using the
233 ! Hi Res 8 minute orography, the Angle of the
234 ! mtn with that to the East (x) axis is THETA, the slope
235 ! parameter SIGMA. The anisotropy is in GAMMA - all are input
236 ! topographic statistics needed. These are calculated off-line
237 ! as a function of model resolution in the fortran code ml01rg2.f,
238 ! with script mlb2.sh. (*j*)
239 !----- gwdps_mb.f version (following lmi) elvmax < hncrit (*j*)
240 ! MB3a expt to enhance elvmax mtn hgt see sigfac & hncrit
241 ! gwdps_GWDFIX_v6.f FIXGWD GF6.0 20070608 sigfac=4.
242 !-----
243 !----------------------------------------------------------------------C
244 ! USE
245 ! ROUTINE IS CALLED FROM GBPHYS (AFTER CALL TO MONNIN)
246 !
247 ! PURPOSE
248 ! USING THE GWD PARAMETERIZATIONS OF PS-GLAS AND PH-
249 ! GFDL TECHNIQUE. THE TIME TENDENCIES OF U V
250 ! ARE ALTERED TO INCLUDE THE EFFECT OF MOUNTAIN INDUCED
251 ! GRAVITY WAVE DRAG FROM SUB-GRID SCALE OROGRAPHY INCLUDING
252 ! CONVECTIVE BREAKING, SHEAR BREAKING AND THE PRESENCE OF
253 ! CRITICAL LEVELS
254 !
255 ! INPUT
256 ! A(IY,KM) NON-LIN TENDENCY FOR V WIND COMPONENT
257 ! B(IY,KM) NON-LIN TENDENCY FOR U WIND COMPONENT
258 ! C(IY,KM) NON-LIN TENDENCY FOR TEMPERATURE
259 ! U1(IX,KM) ZONAL WIND M/SEC AT T0-DT
260 ! V1(IX,KM) MERIDIONAL WIND M/SEC AT T0-DT
261 ! T1(IX,KM) TEMPERATURE DEG K AT T0-DT
262 ! Q1(IX,KM) SPECIFIC HUMIDITY AT T0-DT
263 !
264 ! DELTIM TIME STEP SECS
265 ! SI(N) P/PSFC AT BASE OF LAYER N
266 ! SL(N) P/PSFC AT MIDDLE OF LAYER N
267 ! DEL(N) POSITIVE INCREMENT OF P/PSFC ACROSS LAYER N
268 ! KPBL(IM) is the index of the top layer of the PBL
269 ! ipr & lprnt for diagnostics
270 !
271 ! OUTPUT
272 ! A, B AS AUGMENTED BY TENDENCY DUE TO GWDPS
273 ! OTHER INPUT VARIABLES UNMODIFIED.
274 ! revision log:
275 ! May 2013 J. Wang change cleff back to opn setting
276 ! Jan 2014 J. Wang merge Henry and Fangin's dissipation heat in gfs to nems
277 !
278 !
279 ! ********************************************************************
280  USE machine , ONLY : kind_phys
281  implicit none
282  integer im, iy, ix, km, imx, kdt, ipr, me
283  integer KPBL(im) ! Index for the PBL top layer!
284  real(kind=kind_phys) deltim, G, CP, RD, RV, cdmbgwd(2)
285  real(kind=kind_phys) A(iy,km), B(iy,km), C(iy,km),
286  & u1(ix,km), v1(ix,km), t1(ix,km),
287  & q1(ix,km), prsi(ix,km+1), del(ix,km),
288  & prsl(ix,km), prslk(ix,km), phil(ix,km),
289  & phii(ix,km+1)
290  real(kind=kind_phys) OC(im), OA4(iy,4), CLX4(iy,4)
291  &, hprime(im)
292 ! for lm mtn blocking
293  real(kind=kind_phys) ELVMAX(im),THETA(im),SIGMA(im),GAMMA(im)
294  real(kind=kind_phys) wk(im)
295  real(kind=kind_phys) bnv2lm(im,km),PE(im),EK(im),ZBK(im),UP(im)
296  real(kind=kind_phys) DB(im,km),ANG(im,km),UDS(im,km)
297  real(kind=kind_phys) ZLEN, DBTMP, R, PHIANG, CDmb, DBIM
298  real(kind=kind_phys) ENG0, ENG1
299 !
300 ! Some constants
301 !
302  real(kind=kind_phys) pi, dw2min, rimin, ric, bnv2min, efmin
303  &, efmax,hpmax,hpmin, rad_to_deg, deg_to_rad
304  parameter(pi=3.1415926535897931)
305  parameter(rad_to_deg=180.0/pi, deg_to_rad=pi/180.0)
306  parameter(dw2min=1., rimin=-100., ric=0.25, bnv2min=1.0e-5)
307 ! PARAMETER (EFMIN=0.0, EFMAX=10.0, hpmax=200.0)
308  parameter(efmin=0.0, efmax=10.0, hpmax=2400.0, hpmin=1.0)
309 !
310  real(kind=kind_phys) FRC, CE, CEOFRC, frmax, CG, GMAX
311  &, veleps, factop, rlolev, rdi
312 ! &, CRITAC, VELEPS, FACTOP, RLOLEV, RDI
313  parameter(frc=1.0, ce=0.8, ceofrc=ce/frc, frmax=100., cg=0.5)
314  parameter(gmax=1.0, veleps=1.0, factop=0.5)
315 ! parameter (GMAX=1.0, CRITAC=5.0E-4, VELEPS=1.0, FACTOP=0.5)
316  parameter(rlolev=50000.0)
317 ! parameter (RLOLEV=500.0)
318 ! parameter (RLOLEV=0.5)
319 !
320  real(kind=kind_phys) dpmin,hminmt,hncrit,minwnd,sigfac
321 ! --- for lm mtn blocking
322 ! parameter (cdmb = 1.0) ! non-dim sub grid mtn drag Amp (*j*)
323  parameter(hncrit=8000.) ! Max value in meters for ELVMAX (*j*)
324 ! hncrit set to 8000m and sigfac added to enhance elvmax mtn hgt
325  parameter(sigfac=4.0) ! MB3a expt test for ELVMAX factor (*j*)
326  parameter(hminmt=50.) ! min mtn height (*j*)
327  parameter(minwnd=0.1) ! min wind component (*j*)
328 
329 ! parameter (dpmin=00.0) ! Minimum thickness of the reference layer
330 !! parameter (dpmin=05.0) ! Minimum thickness of the reference layer
331 ! parameter (dpmin=20.0) ! Minimum thickness of the reference layer
332  ! in centibars
333  parameter(dpmin=5000.0) ! Minimum thickness of the reference layer
334  ! in Pa
335 !
336  real(kind=kind_phys) FDIR
337  integer mdir
338  parameter(mdir=8, fdir=mdir/(pi+pi))
339  integer nwdir(mdir)
340  data nwdir/6,7,5,8,2,3,1,4/
341  save nwdir
342 !
343  LOGICAL ICRILV(im)
344 !
345 !---- MOUNTAIN INDUCED GRAVITY WAVE DRAG
346 !
347  real(kind=kind_phys) TAUB(im), XN(im), YN(im), UBAR(im)
348  &, vbar(im), ulow(im), oa(im), clx(im)
349  &, roll(im), uloi(im), dusfc(im), dvsfc(im)
350  &, dtfac(im), xlinv(im), delks(im), delks1(im)
351 !
352  real(kind=kind_phys) BNV2(im,km), TAUP(im,km+1), ri_n(im,km)
353  &, taud(im,km), ro(im,km), vtk(im,km)
354  &, vtj(im,km), scor(im), velco(im,km-1)
355  &, bnv2bar(im)
356 !
357 ! real(kind=kind_phys) VELKO(KM-1)
358  Integer kref(im), kint(im), iwk(im), ipt(im)
359 ! for lm mtn blocking
360  Integer kreflm(im), iwklm(im)
361  Integer idxzb(im), ktrial, klevm1, nmtvr
362 !
363  real(kind=kind_phys) gor, gocp, fv, gr2, bnv, fr
364  &, brvf, cleff, tem, tem1, tem2, temc, temv
365  &, wdir, ti, rdz, dw2, shr2, bvf2
366  &, rdelks, efact, coefm, gfobnv
367  &, scork, rscor, hd, fro, rim, sira
368  &, dtaux, dtauy, pkp1log, pklog
369  integer kmm1, kmm2, lcap, lcapp1, kbps, kbpsp1,kbpsm1
370  &, kmps, idir, nwd, i, j, k, klcap, kp1, kmpbl, npt, npr
371  &, kmll
372 ! &, kmll,kmds,ihit,jhit
373  logical lprnt
374 !
375 ! parameter (cdmb = 1.0) ! non-dim sub grid mtn drag Amp (*j*)
376 ! non-dim sub grid mtn drag Amp (*j*)
377 ! cdmb = 1.0/float(IMX/192)
378 ! cdmb = 192.0/float(IMX)
379  cdmb = 4.0 * 192.0/float(imx)
380  if (cdmbgwd(1) >= 0.0) cdmb = cdmb * cdmbgwd(1)
381 !
382  npr = 0
383  DO i = 1, im
384  dusfc(i) = 0.
385  dvsfc(i) = 0.
386  ENDDO
387 !
388  DO k = 1, km
389  DO i = 1, im
390  db(i,k) = 0.
391  ang(i,k) = 0.
392  uds(i,k) = 0.
393  ENDDO
394  ENDDO
395 !
396  rdi = 1.0 / rd
397  gor = g/rd
398  gr2 = g*gor
399  gocp = g/cp
400  fv = rv/rd - 1
401 !
402 ! NCNT = 0
403  kmm1 = km - 1
404  kmm2 = km - 2
405  lcap = km
406  lcapp1 = lcap + 1
407 !
408 !
409  IF ( nmtvr .eq. 14) then
410 ! ---- for lm and gwd calculation points
411  ipt = 0
412  npt = 0
413  DO i = 1,im
414  IF ( (elvmax(i) .GT. hminmt)
415  & .and. (hprime(i) .GT. hpmin) ) then
416  npt = npt + 1
417  ipt(npt) = i
418  if (ipr .eq. i) npr = npt
419  ENDIF
420  ENDDO
421  IF (npt .eq. 0) RETURN ! No gwd/mb calculation done!
422 !
423 ! if (lprnt) print *,' npt=',npt,' npr=',npr,' ipr=',ipr,' im=',im
424 ! &,' ipt(npt)=',ipt(npt)
425 !
426 ! --- iwklm is the level above the height of the of the mountain.
427 ! --- idxzb is the level of the dividing streamline.
428 ! INITIALIZE DIVIDING STREAMLINE (DS) CONTROL VECTOR
429 !
430  do i=1,npt
431  iwklm(i) = 2
432  idxzb(i) = 0
433  kreflm(i) = 0
434  enddo
435 ! if (lprnt)
436 ! & print *,' in gwdps_lm.f npt,IM,IX,IY,km,me=',npt,IM,IX,IY,km,me
437 !
438 !
440 !
441 !..............................
442 !..............................
443 !
444 ! (*j*) 11/03: test upper limit on KMLL=km - 1
445 ! then do not need hncrit -- test with large hncrit first.
446 ! KMLL = km / 2 ! maximum mtnlm height : # of vertical levels / 2
447  kmll = kmm1
448 ! --- No mtn should be as high as KMLL (so we do not have to start at
449 ! --- the top of the model but could do calc for all levels).
450 !
451  DO i = 1, npt
452  j = ipt(i)
453  elvmax(j) = min(elvmax(j) + sigfac * hprime(j), hncrit)
454  ENDDO
455 !
456  DO k = 1,kmll
457  DO i = 1, npt
458  j = ipt(i)
459 ! --- interpolate to max mtn height for index, iwklm(I) wk[gz]
460 ! --- ELVMAX is limited to hncrit because to hi res topo30 orog.
461  pkp1log = phil(j,k+1) / g
462  pklog = phil(j,k) / g
463 !!!------- ELVMAX(J) = min (ELVMAX(J) + sigfac * hprime(j), hncrit)
464  if ( ( elvmax(j) .le. pkp1log ) .and.
465  & ( elvmax(j) .ge. pklog ) ) THEN
466 ! print *,' in gwdps_lm.f 1 =',k,ELVMAX(j),pklog,pkp1log,me
467 ! --- wk for diags but can be saved and reused.
468  wk(i) = g * elvmax(j) / ( phil(j,k+1) - phil(j,k) )
469  iwklm(i) = max(iwklm(i), k+1 )
470 ! print *,' in gwdps_lm.f 2 npt=',npt,i,j,wk(i),iwklm(i),me
471  endif
472 !
473 ! --- find at prsl levels large scale environment variables
474 ! --- these cover all possible mtn max heights
475  vtj(i,k) = t1(j,k) * (1.+fv*q1(j,k))
476  vtk(i,k) = vtj(i,k) / prslk(j,k)
477  ro(i,k) = rdi * prsl(j,k) / vtj(i,k) ! DENSITY Kg/M**3
478  ENDDO
479  ENDDO
480 !
481 ! testing for highest model level of mountain top
482 !
483 ! ihit = 2
484 ! jhit = 0
485 ! do i = 1, npt
486 ! j=ipt(i)
487 ! if ( iwklm(i) .gt. ihit ) then
488 ! ihit = iwklm(i)
489 ! jhit = j
490 ! endif
491 ! enddo
492 ! print *, ' mb: kdt,max(iwklm),jhit,phil,me=',
493 ! & kdt,ihit,jhit,phil(jhit,ihit),me
494 
495  klevm1 = kmll - 1
496  DO k = 1, klevm1
497  DO i = 1, npt
498  j = ipt(i)
499  rdz = g / ( phil(j,k+1) - phil(j,k) )
500 ! --- Brunt-Vaisala Frequency
502  bnv2lm(i,k) = (g+g) * rdz * ( vtk(i,k+1)-vtk(i,k) )
503  & / ( vtk(i,k+1)+vtk(i,k) )
504  bnv2lm(i,k) = max( bnv2lm(i,k), bnv2min )
505  ENDDO
506  ENDDO
507 ! print *,' in gwdps_lm.f 3 npt=',npt,j,RDZ,me
508 !
509  DO i = 1, npt
510  j = ipt(i)
511  delks(i) = 1.0 / (prsi(j,1) - prsi(j,iwklm(i)))
512  delks1(i) = 1.0 / (prsl(j,1) - prsl(j,iwklm(i)))
513  ubar(i) = 0.0
514  vbar(i) = 0.0
515  roll(i) = 0.0
516  pe (i) = 0.0
517  ek (i) = 0.0
518  bnv2bar(i) = (prsl(j,1)-prsl(j,2)) * delks1(i) * bnv2lm(i,1)
519  ENDDO
520 
521 ! --- find the dividing stream line height
522 ! --- starting from the level above the max mtn downward
523 ! --- iwklm(i) is the k-index of mtn elvmax elevation
526  DO ktrial = kmll, 1, -1
527  DO i = 1, npt
528  IF ( ktrial .LT. iwklm(i) .and. kreflm(i) .eq. 0 ) then
529  kreflm(i) = ktrial
530  ENDIF
531  ENDDO
532  ENDDO
533 ! print *,' in gwdps_lm.f 4 npt=',npt,kreflm(npt),me
534 !
535 ! --- in the layer kreflm(I) to 1 find PE (which needs N, ELVMAX)
536 ! --- make averages, guess dividing stream (DS) line layer.
537 ! --- This is not used in the first cut except for testing and
538 ! --- is the vert ave of quantities from the surface to mtn top.
539 !
540  DO i = 1, npt
541  DO k = 1, kreflm(i)
542  j = ipt(i)
543  rdelks = del(j,k) * delks(i)
544  ubar(i) = ubar(i) + rdelks * u1(j,k) ! trial Mean U below
545  vbar(i) = vbar(i) + rdelks * v1(j,k) ! trial Mean V below
546  roll(i) = roll(i) + rdelks * ro(i,k) ! trial Mean RO below
547  rdelks = (prsl(j,k)-prsl(j,k+1)) * delks1(i)
548  bnv2bar(i) = bnv2bar(i) + bnv2lm(i,k) * rdelks
549 ! --- these vert ave are for diags, testing and GWD to follow (*j*).
550  ENDDO
551  ENDDO
552 ! print *,' in gwdps_lm.f 5 =',i,kreflm(npt),BNV2bar(npt),me
553 !
554 ! --- integrate to get PE in the trial layer.
555 ! --- Need the first layer where PE>EK - as soon as
556 ! --- IDXZB is not 0 we have a hit and Zb is found.
557 !
558  DO i = 1, npt
559  j = ipt(i)
560  DO k = iwklm(i), 1, -1
561  phiang = atan2(v1(j,k),u1(j,k))*rad_to_deg
562  ang(i,k) = ( theta(j) - phiang )
563  if ( ang(i,k) .gt. 90. ) ang(i,k) = ang(i,k) - 180.
564  if ( ang(i,k) .lt. -90. ) ang(i,k) = ang(i,k) + 180.
565  ang(i,k) = ang(i,k) * deg_to_rad
566 !
573  uds(i,k) =
574  & max(sqrt(u1(j,k)*u1(j,k) + v1(j,k)*v1(j,k)), minwnd)
575 ! --- Test to see if we found Zb previously
576  IF (idxzb(i) .eq. 0 ) then
577  pe(i) = pe(i) + bnv2lm(i,k) *
578  & ( g * elvmax(j) - phil(j,k) ) *
579  & ( phii(j,k+1) - phii(j,k) ) / (g*g)
580 ! --- KE
581 ! --- Wind projected on the line perpendicular to mtn range, U(Zb(K)).
582 ! --- kenetic energy is at the layer Zb
583 ! --- THETA ranges from -+90deg |_ to the mtn "largest topo variations"
584  up(i) = uds(i,k) * cos(ang(i,k))
585  ek(i) = 0.5 * up(i) * up(i)
586 
587 ! --- Dividing Stream lime is found when PE =exceeds EK.
588  IF ( pe(i) .ge. ek(i) ) idxzb(i) = k
589 ! --- Then mtn blocked flow is between Zb=k(IDXZB(I)) and surface
590 !
604  ENDIF
605  ENDDO
606  ENDDO
607 !
608 ! print *,' in gwdps_lm.f 6 =',phiang,THETA(ipt(npt)),me
609 ! print *,' in gwdps_lm.f 7 =',IDXZB(npt),PE(npt)
610 !
611 ! if (lprnt .and. npr .gt. 0) then
612 ! print *,' BNV2bar,BNV2lm=',bnv2bar(npr),BNV2lm(npr,1:klevm1)
613 ! print *,' npr,IDXZB,UDS=',npr,IDXZB(npr),UDS(npr,:)
614 ! print *,' PE,UP,EK=',PE(npr),UP(npr),EK(npr)
615 ! endif
616 !
617  DO i = 1, npt
618  j = ipt(i)
619 ! --- Calc if N constant in layers (Zb guess) - a diagnostic only.
620  zbk(i) = elvmax(j)
621  & - sqrt(ubar(i)*ubar(i) + vbar(i)*vbar(i))/bnv2bar(i)
622  ENDDO
623 !
624 ! if (lprnt .and. npr .gt. 0) then
625 ! print *,' iwklm,ZBK=',iwklm(npr),ZBK(npr),IDXZB(npr)
626 ! print *,' Zb=',PHIL(ipr),IDXZB(npr))/G
627 ! print *,' in gwdps_lm.f 8 npt =',npt,ZBK(npt),UP(npt),me
628 ! endif
629 !
630 ! --- The drag for mtn blocked flow
631 !
632  DO i = 1, npt
633  j = ipt(i)
634  zlen = 0.
635 ! print *,' in gwdps_lm.f 9 =',i,j,IDXZB(i),me
636  IF ( idxzb(i) .gt. 0 ) then
637  DO k = idxzb(i), 1, -1
638  IF ( phil(j,idxzb(i)) .gt. phil(j,k) ) then
639 
647  zlen = sqrt( ( phil(j,idxzb(i)) - phil(j,k) ) /
648  & ( phil(j,k ) + g * hprime(j) ) )
649 ! --- lm eq 14:
659  r = (cos(ang(i,k))**2 + gamma(j) * sin(ang(i,k))**2) /
660  & (gamma(j) * cos(ang(i,k))**2 + sin(ang(i,k))**2)
661 ! --- (negitive of DB -- see sign at tendency)
671 
672  dbtmp = 0.25 * cdmb *
673  & max( 2. - 1. / r, 0. ) * sigma(j) *
674  & max(cos(ang(i,k)), gamma(j)*sin(ang(i,k))) *
675  & zlen / hprime(j)
676  db(i,k) = dbtmp * uds(i,k)
677 !
678 ! if(lprnt .and. i .eq. npr) then
679 ! print *,' in gwdps_lmi.f 10 npt=',npt,i,j,idxzb(i)
680 ! &, DBTMP,R' ang=',ang(i,k),' gamma=',gamma(j),' K=',K
681 ! print *,' in gwdps_lmi.f 11 K=',k,ZLEN,cos(ANG(I,K))
682 ! print *,' in gwdps_lmi.f 12 DB=',DB(i,k),sin(ANG(I,K))
683 ! endif
684  endif
685  ENDDO
686 ! if(lprnt) print *,' @K=1,ZLEN,DBTMP=',K,ZLEN,DBTMP
687  endif
688  ENDDO
689 !
690 !.............................
691 !.............................
692 ! end mtn blocking section
693 !
694  ELSEIF ( nmtvr .ne. 14) then
695 ! ---- for mb not present and gwd (nmtvr .ne .14)
696  ipt = 0
697  npt = 0
698  DO i = 1,im
699  IF ( hprime(i) .GT. hpmin ) then
700  npt = npt + 1
701  ipt(npt) = i
702  if (ipr .eq. i) npr = npt
703  ENDIF
704  ENDDO
705  IF (npt .eq. 0) RETURN ! No gwd/mb calculation done!
706 !
707 ! if (lprnt) print *,' NPR=',npr,' npt=',npt,' IPR=',IPR
708 ! &,' ipt(npt)=',ipt(npt)
709 !
710  do i=1,npt
711  idxzb(i) = 0
712  enddo
713  ENDIF
714 !
715 !.............................
716 !.............................
717 !
719  kmpbl = km / 2 ! maximum pbl height : # of vertical levels / 2
720 !
721 ! Scale cleff between IM=384*2 and 192*2 for T126/T170 and T62
722 !
723  if (imx .gt. 0) then
724 ! cleff = 1.0E-5 * SQRT(FLOAT(IMX)/384.0) ! this is inverse of CLEFF!
725 ! cleff = 1.0E-5 * SQRT(FLOAT(IMX)/192.0) ! this is inverse of CLEFF!
726 ! cleff = 0.5E-5 * SQRT(FLOAT(IMX)/192.0) ! this is inverse of CLEFF!
727 ! cleff = 1.0E-5 * SQRT(FLOAT(IMX)/192)/float(IMX/192)
728 ! cleff = 1.0E-5 / SQRT(FLOAT(IMX)/192.0) ! this is inverse of CLEFF!
729  cleff = 0.5e-5 / sqrt(float(imx)/192.0) ! this is inverse of CLEFF!
730 ! hmhj for ndsl
731 ! jw cleff = 0.1E-5 / SQRT(FLOAT(IMX)/192.0) ! this is inverse of CLEFF!
732 ! cleff = 2.0E-5 * SQRT(FLOAT(IMX)/192.0) ! this is inverse of CLEFF!
733 ! cleff = 2.5E-5 * SQRT(FLOAT(IMX)/192.0) ! this is inverse of CLEFF!
734  endif
735  if (cdmbgwd(2) >= 0.0) cleff = cleff * cdmbgwd(2)
736 !
737  DO k = 1,km
738  DO i =1,npt
739  j = ipt(i)
740  vtj(i,k) = t1(j,k) * (1.+fv*q1(j,k))
741  vtk(i,k) = vtj(i,k) / prslk(j,k)
742  ro(i,k) = rdi * prsl(j,k) / vtj(i,k) ! DENSITY TONS/M**3
743  taup(i,k) = 0.0
744  ENDDO
745  ENDDO
746  DO k = 1,kmm1
747  DO i =1,npt
748  j = ipt(i)
749  ti = 2.0 / (t1(j,k)+t1(j,k+1))
750  tem = ti / (prsl(j,k)-prsl(j,k+1))
751  rdz = g / (phil(j,k+1) - phil(j,k))
752  tem1 = u1(j,k) - u1(j,k+1)
753  tem2 = v1(j,k) - v1(j,k+1)
754  dw2 = tem1*tem1 + tem2*tem2
755  shr2 = max(dw2,dw2min) * rdz * rdz
756  bvf2 = g*(gocp+rdz*(vtj(i,k+1)-vtj(i,k))) * ti
757  ri_n(i,k) = max(bvf2/shr2,rimin) ! Richardson number
758 ! Brunt-Vaisala Frequency
759 ! TEM = GR2 * (PRSL(J,K)+PRSL(J,K+1)) * TEM
760 ! BNV2(I,K) = TEM * (VTK(I,K+1)-VTK(I,K))/(VTK(I,K+1)+VTK(I,K))
761  bnv2(i,k) = (g+g) * rdz * (vtk(i,k+1)-vtk(i,k))
762  & / (vtk(i,k+1)+vtk(i,k))
763  bnv2(i,k) = max( bnv2(i,k), bnv2min )
764  ENDDO
765  ENDDO
766 ! print *,' in gwdps_lm.f GWD:14 =',npt,kmm1,bnv2(npt,kmm1)
767 !
768 ! Apply 3 point smoothing on BNV2
769 !
770 ! do k=1,km
771 ! do i=1,im
772 ! vtk(i,k) = bnv2(i,k)
773 ! enddo
774 ! enddo
775 ! do k=2,kmm1
776 ! do i=1,im
777 ! bnv2(i,k) = 0.25*(vtk(i,k-1)+vtk(i,k+1)) + 0.5*vtk(i,k)
778 ! enddo
779 ! enddo
780 !
781 ! Finding the first interface index above 50 hPa level
782 !
783  do i=1,npt
784  iwk(i) = 2
785  enddo
786  DO k=3,kmpbl
787  DO i=1,npt
788  j = ipt(i)
789  tem = (prsi(j,1) - prsi(j,k))
790  if (tem .lt. dpmin) iwk(i) = k
791  enddo
792  enddo
793 !
796  kbps = 1
797  kmps = km
798  DO i=1,npt
799  j = ipt(i)
800  kref(i) = max(iwk(i), kpbl(j)+1 ) ! reference level
801  delks(i) = 1.0 / (prsi(j,1) - prsi(j,kref(i)))
802  delks1(i) = 1.0 / (prsl(j,1) - prsl(j,kref(i)))
803  ubar(i) = 0.0
804  vbar(i) = 0.0
805  roll(i) = 0.0
806  kbps = max(kbps, kref(i))
807  kmps = min(kmps, kref(i))
808 !
809  bnv2bar(i) = (prsl(j,1)-prsl(j,2)) * delks1(i) * bnv2(i,1)
810  ENDDO
811 ! print *,' in gwdps_lm.f GWD:15 =',KBPS,KMPS
812  kbpsp1 = kbps + 1
813  kbpsm1 = kbps - 1
814  DO k = 1,kbps
815  DO i = 1,npt
816  IF (k .LT. kref(i)) THEN
817  j = ipt(i)
818  rdelks = del(j,k) * delks(i)
819  ubar(i) = ubar(i) + rdelks * u1(j,k) ! Mean U below kref
820  vbar(i) = vbar(i) + rdelks * v1(j,k) ! Mean V below kref
821 !
822  roll(i) = roll(i) + rdelks * ro(i,k) ! Mean RO below kref
823  rdelks = (prsl(j,k)-prsl(j,k+1)) * delks1(i)
824  bnv2bar(i) = bnv2bar(i) + bnv2(i,k) * rdelks
825  ENDIF
826  ENDDO
827  ENDDO
828 ! print *,' in gwdps_lm.f GWD:15B =',bnv2bar(npt)
829 !
830 ! FIGURE OUT LOW-LEVEL HORIZONTAL WIND DIRECTION AND FIND 'OA'
831 !
832 ! NWD 1 2 3 4 5 6 7 8
833 ! WD W S SW NW E N NE SE
834 !
837  DO i = 1,npt
838  j = ipt(i)
839  wdir = atan2(ubar(i),vbar(i)) + pi
840  idir = mod(nint(fdir*wdir),mdir) + 1
841  nwd = nwdir(idir)
842  oa(i) = (1-2*int( (nwd-1)/4 )) * oa4(j,mod(nwd-1,4)+1)
843  clx(i) = clx4(j,mod(nwd-1,4)+1)
844  ENDDO
845 !
846 !-----XN,YN "LOW-LEVEL" WIND PROJECTIONS IN ZONAL
847 ! & MERIDIONAL DIRECTIONS
848 !-----ULOW "LOW-LEVEL" WIND MAGNITUDE - (= U)
849 !-----BNV2 BNV2 = N**2
850 !-----TAUB BASE MOMENTUM FLUX
851 !-----= -(RO * U**3/(N*XL)*GF(FR) FOR N**2 > 0
852 !-----= 0. FOR N**2 < 0
853 !-----FR FROUDE = N*HPRIME / U
854 !-----G GMAX*FR**2/(FR**2+CG/OC)
855 !
856 !-----INITIALIZE SOME ARRAYS
857 !
858  DO i = 1,npt
859  xn(i) = 0.0
860  yn(i) = 0.0
861  taub(i) = 0.0
862  ulow(i) = 0.0
863  dtfac(i) = 1.0
864  icrilv(i) = .false. ! INITIALIZE CRITICAL LEVEL CONTROL VECTOR
865 
866 !
867 !----COMPUTE THE "LOW LEVEL" WIND MAGNITUDE (M/S)
868 !
869  ulow(i) = max(sqrt(ubar(i)*ubar(i) + vbar(i)*vbar(i)), 1.0)
870  uloi(i) = 1.0 / ulow(i)
871  ENDDO
872 !
873  DO k = 1,kmm1
874  DO i = 1,npt
875  j = ipt(i)
876  velco(i,k) = 0.5 * ((u1(j,k)+u1(j,k+1))*ubar(i)
877  & + (v1(j,k)+v1(j,k+1))*vbar(i))
878  velco(i,k) = velco(i,k) * uloi(i)
879 ! IF ((VELCO(I,K).LT.VELEPS) .AND. (VELCO(I,K).GT.0.)) THEN
880 ! VELCO(I,K) = VELEPS
881 ! ENDIF
882  ENDDO
883  ENDDO
884 !
885 !
886 ! find the interface level of the projected wind where
887 ! low levels & upper levels meet above pbl
888 !
889 ! do i=1,npt
890 ! kint(i) = km
891 ! enddo
892 ! do k = 1,kmm1
893 ! do i = 1,npt
894 ! IF (K .GT. kref(I)) THEN
895 ! if(velco(i,k) .lt. veleps .and. kint(i) .eq. km) then
896 ! kint(i) = k+1
897 ! endif
898 ! endif
899 ! enddo
900 ! enddo
901 ! WARNING KINT = KREF !!!!!!!!!
902  do i=1,npt
903  kint(i) = kref(i)
904  enddo
905 !
906 ! if(lprnt) print *,' ubar=',ubar
907 ! &,' vbar=',vbar,' ulow=',ulow,' veleps=',veleps
908 !
909  DO i = 1,npt
910  j = ipt(i)
911  bnv = sqrt( bnv2bar(i) )
912  fr = bnv * uloi(i) * min(hprime(j),hpmax)
913  fr = min(fr, frmax)
914  xn(i) = ubar(i) * uloi(i)
915  yn(i) = vbar(i) * uloi(i)
916 !
917 ! Compute the base level stress and store it in TAUB
918 ! CALCULATE ENHANCEMENT FACTOR, NUMBER OF MOUNTAINS & ASPECT
919 ! RATIO CONST. USE SIMPLIFIED RELATIONSHIP BETWEEN STANDARD
920 ! DEVIATION & CRITICAL HGT
921 !
950 
959 
960  efact = (oa(i) + 2.) ** (ceofrc*fr)
961  efact = min( max(efact,efmin), efmax )
962 !
963  coefm = (1. + clx(i)) ** (oa(i)+1.)
964 !
965  xlinv(i) = coefm * cleff
966 !
967  tem = fr * fr * oc(j)
968  gfobnv = gmax * tem / ((tem + cg)*bnv) ! G/N0
969 !
970  taub(i) = xlinv(i) * roll(i) * ulow(i) * ulow(i)
971  & * ulow(i) * gfobnv * efact ! BASE FLUX Tau0
972 !
973 ! tem = min(HPRIME(I),hpmax)
974 ! TAUB(I) = XLINV(I) * ROLL(I) * ULOW(I) * BNV * tem * tem
975 !
976  k = max(1, kref(i)-1)
977  tem = max(velco(i,k)*velco(i,k), 0.1)
978  scor(i) = bnv2(i,k) / tem ! Scorer parameter below ref level
979  ENDDO
980 ! if(lprnt) print *,' taub=',taub
981 !
982 !----SET UP BOTTOM VALUES OF STRESS
983 !
984  DO k = 1, kbps
985  DO i = 1,npt
986  IF (k .LE. kref(i)) taup(i,k) = taub(i)
987  ENDDO
988  ENDDO
989 !
990 ! Now compute vertical structure of the stress.
991 !
992  DO k = kmps, kmm1 ! Vertical Level K Loop!
993  kp1 = k + 1
994  DO i = 1, npt
995 !
996 !-----UNSTABLE LAYER IF RI < RIC
997 !-----UNSTABLE LAYER IF UPPER AIR VEL COMP ALONG SURF VEL <=0 (CRIT LAY)
998 !---- AT (U-C)=0. CRIT LAYER EXISTS AND BIT VECTOR SHOULD BE SET (.LE.)
999 !
1000  IF (k .GE. kref(i)) THEN
1001  icrilv(i) = icrilv(i) .OR. ( ri_n(i,k) .LT. ric)
1002  & .OR. (velco(i,k) .LE. 0.0)
1003  ENDIF
1004  ENDDO
1005 !
1018  DO i = 1,npt
1019  IF (k .GE. kref(i)) THEN
1020  IF (.NOT.icrilv(i) .AND. taup(i,k) .GT. 0.0 ) THEN
1021  temv = 1.0 / max(velco(i,k), 0.01)
1022 ! IF (OA(I) .GT. 0. .AND. PRSI(ipt(i),KP1).GT.RLOLEV) THEN
1023  IF (oa(i).GT.0. .AND. kp1 .lt. kint(i)) THEN
1024  scork = bnv2(i,k) * temv * temv
1025  rscor = min(1.0, scork / scor(i))
1026  scor(i) = scork
1027  ELSE
1028  rscor = 1.
1029  ENDIF
1030 !
1042 
1043  brvf = sqrt(bnv2(i,k)) ! Brunt-Vaisala Frequency
1044 ! TEM1 = XLINV(I)*(RO(I,KP1)+RO(I,K))*BRVF*VELCO(I,K)*0.5
1045  tem1 = xlinv(i)*(ro(i,kp1)+ro(i,k))*brvf*0.5
1046  & * max(velco(i,k),0.01)
1047  hd = sqrt(taup(i,k) / tem1)
1048  fro = brvf * hd * temv
1049 !
1050 ! RIM is the MINIMUM-RICHARDSON NUMBER BY SHUTTS (1985)
1051 !
1060 
1061  tem2 = sqrt(ri_n(i,k))
1062  tem = 1. + tem2 * fro
1063  rim = ri_n(i,k) * (1.-fro) / (tem * tem)
1064 !
1065 ! CHECK STABILITY TO EMPLOY THE 'SATURATION HYPOTHESIS'
1066 ! OF LINDZEN (1981) EXCEPT AT TROPOSPHERIC DOWNSTREAM REGIONS
1067 !
1083 ! ----------------------
1084  IF (rim .LE. ric .AND.
1085 ! & (OA(I) .LE. 0. .OR. PRSI(ipt(I),KP1).LE.RLOLEV )) THEN
1086  & (oa(i) .LE. 0. .OR. kp1 .ge. kint(i) )) THEN
1087  temc = 2.0 + 1.0 / tem2
1088  hd = velco(i,k) * (2.*sqrt(temc)-temc) / brvf
1089  taup(i,kp1) = tem1 * hd * hd
1090  ELSE
1091  taup(i,kp1) = taup(i,k) * rscor
1092  ENDIF
1093  taup(i,kp1) = min(taup(i,kp1), taup(i,k))
1094  ENDIF
1095  ENDIF
1096  ENDDO
1097  ENDDO
1098 !
1099 ! DO I=1,IM
1100 ! taup(i,km+1) = taup(i,km)
1101 ! ENDDO
1102 !
1103  IF(lcap .LE. km) THEN
1104  DO klcap = lcapp1, km+1
1105  DO i = 1,npt
1106  sira = prsi(ipt(i),klcap) / prsi(ipt(i),lcap)
1107  taup(i,klcap) = sira * taup(i,lcap)
1108  ENDDO
1109  ENDDO
1110  ENDIF
1111 !
1112 ! Calculate - (g/p*)*d(tau)/d(sigma) and Decel terms DTAUX, DTAUY
1113 !
1114  DO k = 1,km
1115  DO i = 1,npt
1116  taud(i,k) = g * (taup(i,k+1) - taup(i,k)) / del(ipt(i),k)
1117  ENDDO
1118  ENDDO
1119 !
1120 !------LIMIT DE-ACCELERATION (MOMENTUM DEPOSITION ) AT TOP TO 1/2 VALUE
1121 !------THE IDEA IS SOME STUFF MUST GO OUT THE 'TOP'
1122 !
1123  DO klcap = lcap, km
1124  DO i = 1,npt
1125  taud(i,klcap) = taud(i,klcap) * factop
1126  ENDDO
1127  ENDDO
1128 !
1129 !------IF THE GRAVITY WAVE DRAG WOULD FORCE A CRITICAL LINE IN THE
1130 !------LAYERS BELOW SIGMA=RLOLEV DURING THE NEXT DELTIM TIMESTEP,
1131 !------THEN ONLY APPLY DRAG UNTIL THAT CRITICAL LINE IS REACHED.
1132 !
1133  DO k = 1,kmm1
1134  DO i = 1,npt
1135  IF (k .GT. kref(i) .and. prsi(ipt(i),k) .GE. rlolev) THEN
1136  IF(taud(i,k).NE.0.) THEN
1137  tem = deltim * taud(i,k)
1138  dtfac(i) = min(dtfac(i),abs(velco(i,k)/tem))
1139  ENDIF
1140  ENDIF
1141  ENDDO
1142  ENDDO
1143 !
1144 ! if(lprnt .and. npr .gt. 0) then
1145 ! print *,' before A=',A(npr,:)
1146 ! print *,' before B=',B(npr,:)
1147 ! endif
1148 
1153  DO k = 1,km
1154  DO i = 1,npt
1155  j = ipt(i)
1156  taud(i,k) = taud(i,k) * dtfac(i)
1157  dtaux = taud(i,k) * xn(i)
1158  dtauy = taud(i,k) * yn(i)
1159  eng0 = 0.5*(u1(j,k)*u1(j,k)+v1(j,k)*v1(j,k))
1160 ! --- lm mb (*j*) changes overwrite GWD
1161  if ( k .lt. idxzb(i) .AND. idxzb(i) .ne. 0 ) then
1162  dbim = db(i,k) / (1.+db(i,k)*deltim)
1163  a(j,k) = - dbim * v1(j,k) + a(j,k)
1164  b(j,k) = - dbim * u1(j,k) + b(j,k)
1165  eng1 = eng0*(1.0-dbim*deltim)*(1.0-dbim*deltim)
1166 ! if ( ABS(DBIM * U1(J,K)) .gt. .01 )
1167 ! & print *,' in gwdps_lmi.f KDT=',KDT,I,K,DB(I,K),
1168 ! & dbim,idxzb(I),U1(J,K),V1(J,K),me
1169  dusfc(j) = dusfc(j) - dbim * v1(j,k) * del(j,k)
1170  dvsfc(j) = dvsfc(j) - dbim * u1(j,k) * del(j,k)
1171  else
1172 !
1173  a(j,k) = dtauy + a(j,k)
1174  b(j,k) = dtaux + b(j,k)
1175  eng1 = 0.5*(
1176  & (u1(j,k)+dtaux*deltim)*(u1(j,k)+dtaux*deltim)
1177  & + (v1(j,k)+dtauy*deltim)*(v1(j,k)+dtauy*deltim))
1178  dusfc(j) = dusfc(j) + dtaux * del(j,k)
1179  dvsfc(j) = dvsfc(j) + dtauy * del(j,k)
1180  endif
1181  c(j,k) = c(j,k) + max(eng0-eng1,0.)/cp/deltim
1182  ENDDO
1183  ENDDO
1184 ! if (lprnt) then
1185 ! print *,' in gwdps_lm.f after A=',A(ipr,:)
1186 ! print *,' in gwdps_lm.f after B=',B(ipr,:)
1187 ! print *,' DB=',DB(ipr,:)
1188 ! endif
1189  tem = -1.0/g
1190  DO i = 1,npt
1191  j = ipt(i)
1192 ! TEM = (-1.E3/G)
1193  dusfc(j) = tem * dusfc(j)
1194  dvsfc(j) = tem * dvsfc(j)
1195  ENDDO
1196 !
1197 ! MONITOR FOR EXCESSIVE GRAVITY WAVE DRAG TENDENCIES IF NCNT>0
1198 !
1199 ! IF(NCNT.GT.0) THEN
1200 ! IF(LAT.GE.38.AND.LAT.LE.42) THEN
1201 !CMIC$ GUARD 37
1202 ! DO 92 I = 1,IM
1203 ! IF(IKOUNT.GT.NCNT) GO TO 92
1204 ! IF(I.LT.319.OR.I.GT.320) GO TO 92
1205 ! DO 91 K = 1,KM
1206 ! IF(ABS(TAUD(I,K)) .GT. CRITAC) THEN
1207 ! IF(I.LE.IM) THEN
1208 ! IKOUNT = IKOUNT+1
1209 ! PRINT 123,I,LAT,KDT
1210 ! PRINT 124,TAUB(I),BNV(I),ULOW(I),
1211 ! 1 GF(I),FR(I),ROLL(I),HPRIME(I),XN(I),YN(I)
1212 ! PRINT 124,(TAUD(I,KK),KK = 1,KM)
1213 ! PRINT 124,(TAUP(I,KK),KK = 1,KM+1)
1214 ! PRINT 124,(ri_n(I,KK),KK = 1,KM)
1215 ! DO 93 KK = 1,KMM1
1216 ! VELKO(KK) =
1217 ! 1 0.5*((U1(I,KK)+U1(I,KK+1))*UBAR(I)+
1218 ! 2 (V1(I,KK)+V1(I,KK+1))*VBAR(I))*ULOI(I)
1219 !93 CONTINUE
1220 ! PRINT 124,(VELKO(KK),KK = 1,KMM1)
1221 ! PRINT 124,(A (I,KK),KK = 1,KM)
1222 ! PRINT 124,(DTAUY(I,KK),KK = 1,KM)
1223 ! PRINT 124,(B (I,KK),KK = 1,KM)
1224 ! PRINT 124,(DTAUX(I,KK),KK = 1,KM)
1225 ! GO TO 92
1226 ! ENDIF
1227 ! ENDIF
1228 !91 CONTINUE
1229 !92 CONTINUE
1230 !CMIC$ END GUARD 37
1231 !123 FORMAT(' *** MIGWD PRINT *** I=',I3,' LAT=',I3,' KDT=',I3)
1232 !124 FORMAT(2X, 10E13.6)
1233 ! ENDIF
1234 ! ENDIF
1235 !
1236 ! print *,' in gwdps_lm.f 18 =',A(ipt(1),idxzb(1))
1237 ! &, B(ipt(1),idxzb(1)),me
1238  RETURN
1239  END
1240 
subroutine gwdps(IM, IX, IY, KM, A, B, C, U1, V1, T1, Q1, KPBL, PRSI, DEL, PRSL, PRSLK, PHII, PHIL, DELTIM, KDT, HPRIME, OC, OA4, CLX4, THETA, SIGMA, GAMMA, ELVMAX, DUSFC, DVSFC, G, CP, RD, RV, IMX, nmtvr, cdmbgwd, me, lprnt, ipr)
Definition: gwdps.f:188