UPP  001
 All Data Structures Files Functions Pages
SLP_NMM.f
1  SUBROUTINE memslp_nmm(TPRES,QPRES,FIPRES)
2 !
3 !$$$ SUBPROGRAM DOCUMENTATION BLOCK
4 ! . . .
5 ! SUBROUTINE: MEMSLP MEMBRANE SLP REDUCTION
6 !
7 ! ABSTRACT: THIS ROUTINE COMPUTES THE SEA LEVEL PRESSURE
8 ! REDUCTION USING THE MESINGER RELAXATION
9 ! METHOD FOR SIGMA COORDINATES.
10 ! A BY-PRODUCT IS THE
11 ! SET OF VALUES FOR THE UNDERGROUND TEMPERATURES
12 ! ON THE SPECIFIED PRESSURE LEVELS
13 !
14 ! PROGRAM HISTORY LOG:
15 ! 99-09-23 T BLACK - REWRITTEN FROM ROUTINE SLP (ETA
16 ! COORDINATES)
17 ! 02-07-26 H CHUANG - PARALLIZE AND MODIFIED FOR WRF A/C GRIDS
18 ! ALSO REDUCE S.O.R. COEFF FROM 1.75 to 1.25
19 ! BECAUSE THERE WAS NUMERICAL INSTABILITY
20 ! 02-08-21 H CHUANG - MODIFIED TO ALWAYS USE OLD TTV FOR RELAXATION
21 ! SO THAT THERE WAS BIT REPRODUCIBILITY BETWEEN
22 ! USING ONE AND MULTIPLE TASKS
23 ! 13-12-06 H CHUANG - REMOVE EXTRA SMOOTHING OF SLP AT THE END
24 ! 19-10-30 Bo CUI - REMOVE "GOTO" STATEMENT
25 !
26 ! USAGE: CALL SLPSIG FROM SUBROUITNE ETA2P
27 !
28 ! INPUT ARGUMENT LIST:
29 ! PD - SFC PRESSURE MINUS PTOP
30 ! FIS - SURFACE GEOPOTENTIAL
31 ! T - TEMPERATURE
32 ! Q - SPECIFIC HUMIDITY
33 ! FI - GEOPOTENTIAL
34 ! PT - TOP PRESSURE OF DOMAIN
35 !
36 ! OUTPUT ARGUMENT LIST:
37 ! PSLP - THE FINAL REDUCED SEA LEVEL PRESSURE ARRAY
38 !
39 ! SUBPROGRAMS CALLED:
40 ! UNIQUE:
41 ! NONE
42 !
43 !-----------------------------------------------------------------------
44  use vrbls3d, only: pint, zint, t, q
45  use vrbls2d, only: pslp, fis
46  use masks, only: lmh
47  use params_mod, only: overrc, ad05, cft0, g, rd, d608, h1, kslpd
48  use ctlblk_mod, only: jsta, jend, spl, num_procs, mpi_comm_comp, lsmp1, jsta_m2, jend_m2,&
49  lm, jsta_m, jend_m, im, jsta_2l, jend_2u, im_jm, lsm, jm
50 !- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
51  implicit none
52 !
53  include "mpif.h"
54 !-----------------------------------------------------------------------
55  integer, PARAMETER :: nfill=0,nrlx1=500,nrlx2=100
56 !-----------------------------------------------------------------------
57  real,dimension(IM,JSTA_2L:JEND_2U,LSM),intent(in) :: qpres
58  real,dimension(IM,JSTA_2L:JEND_2U,LSM),intent(inout) :: tpres,fipres
59  REAL :: ttv(im,jsta_2l:jend_2u),tnew(im,jsta_2l:jend_2u) &
60  ,slpx(im,jsta_2l:jend_2u) &
61  ,p1(im,jsta_2l:jend_2u),htm2d(im,jsta_2l:jend_2u)
62  REAL :: htmo(im,jsta_2l:jend_2u,lsm)
63  real p2,gz1,gz2,tlyr,spll,pchk,psfc,slope,tvrt,dis,tinit
64 !-----------------------------------------------------------------------
65 !-----------------------------------------------------------------------
66  INTEGER :: kmntm(lsm),imnt(im_jm,lsm),jmnt(im_jm,lsm) &
67  ,lmho(im,jsta_2l:jend_2u)
68  INTEGER :: ihe(jm),ihw(jm),ive(jm),ivw(jm),ihs(jm),ihn(jm)
69  integer ii,jj,i,j,l,n,km,ks,kp,kmn,kmm,kount,lp,llmh,lhmnt &
70  ,lmhij,lmap1,lxxx,ierr,nrlx,ihh2
71 !-----------------------------------------------------------------------
72  LOGICAL :: done(im,jsta_2l:jend_2u)
73  logical, parameter :: debugprint = .false.
74 !-----------------------------------------------------------------------
75 !-----------------------------------------------------------------------
76 !***
77 !*** CALCULATE THE I-INDEX EAST-WEST INCREMENTS
78 !***
79 !
80  ii=279
81  jj=314
82  DO j=1,jm
83  ihe(j)=mod(j+1,2)
84  ihw(j)=ihe(j)-1
85  ENDDO
86 ! print*,'relaxation coeff= ',OVERRC
87 !-----------------------------------------------------------------------
88 !***
89 !*** INITIALIZE ARRAYS. LOAD SLP ARRAY WITH SURFACE PRESSURE.
90 !***
91 !$omp parallel do
92  DO j=jsta,jend
93  DO i=1,im
94  llmh=nint(lmh(i,j))
95  pslp(i,j)=pint(i,j,llmh+1)
96  if(debugprint .and. i==ii .and. j==jj)print*,'Debug: FIS,IC for PSLP=' &
97  ,fis(i,j),pslp(i,j)
98  ttv(i,j)=0.
99  lmho(i,j)=0
100  done(i,j)=.false.
101  ENDDO
102  ENDDO
103 !
104 !*** CALCULATE SEA LEVEL PRESSURE FOR PROFILES (AND POSSIBLY
105 !*** FOR POSTING BY POST PROCESSOR).
106 !
107 !--------------------------------------------------------------------
108 !***
109 !*** CREATE A 3-D "HEIGHT MASK" FOR THE SPECIFIED PRESSURE LEVELS
110 !*** (1 => ABOVE GROUND) AND A 2-D INDICATOR ARRAY THAT SAYS
111 !*** WHICH PRESSURE LEVEL IS THE LOWEST ONE ABOVE THE GROUND
112 !***
113  DO 100 l=1,lsm
114  spll=spl(l)
115 !
116  DO j=jsta,jend
117  DO i=1,im
118  psfc=pslp(i,j)
119  pchk=psfc
120  IF(nfill>0)THEN
121  pchk=pint(i,j,nint(lmh(i,j))+1-nfill)
122  ENDIF
123 ! IF(SM(I,J)>0.5.AND.FIS(I,J)<1.)PCHK=PSLP(I,J)
124  IF(fis(i,j)<1.)pchk=pslp(i,j)
125 !
126 ! IF(SPLL<PSFC)THEN
127  IF(spll<pchk)THEN
128  htmo(i,j,l)=1.
129  ELSE
130  htmo(i,j,l)=0.
131  IF(l>1.AND.htmo(i,j,l-1)>0.5)lmho(i,j)=l-1
132  ENDIF
133 !
134  IF(l==lsm.AND.htmo(i,j,l)>0.5)lmho(i,j)=lsm
135  if(debugprint .and. i==ii .and. j==jj)print*,'Debug: HTMO= ',htmo(i,j,l)
136  ENDDO
137  ENDDO
138 !
139  100 CONTINUE
140 ! if(jj>=jsta.and.jj<=jend)
141 ! +print*,'Debug: LMHO=',LMHO(ii,jj)
142 !--------------------------------------------------------------------
143 !***
144 !*** WE REACH THIS LINE IF WE WANT THE MESINGER ETA SLP REDUCTION
145 !*** BASED ON RELAXATION TEMPERATURES. THE FIRST STEP IS TO
146 !*** FIND THE HIGHEST LAYER CONTAINING MOUNTAINS.
147 !***
148  loop210: DO l=lsm,1,-1
149 !
150  DO j=jsta,jend
151  DO i=1,im
152  IF(htmo(i,j,l)<0.5) cycle loop210
153  ENDDO
154  ENDDO
155 !
156  lhmnt=l+1
157  exit loop210
158  enddo loop210
159 
160  if(debugprint)print*,'Debug in SLP: LHMNT=',lhmnt
161  if ( num_procs > 1 ) then
162  CALL mpi_allreduce &
163  (lhmnt,lxxx,1,mpi_integer,mpi_min,mpi_comm_comp,ierr)
164  lhmnt = lxxx
165  end if
166 
167  IF(lhmnt==lsmp1)THEN
168  go to 325
169  ENDIF
170  if(debugprint)print*,'Debug in SLP: LHMNT A ALLREDUCE=',lhmnt
171 !***
172 !*** NOW GATHER THE ADDRESSES OF ALL THE UNDERGROUND POINTS.
173 !***
174 !$omp parallel do private(kmn,kount)
175  DO 250 l=lhmnt,lsm
176  kmn=0
177  kmntm(l)=0
178  kount=0
179  DO 240 j=jsta_m2,jend_m2
180 ! DO 240 J=JSTA_M,JEND_M
181  DO 240 i=2,im-1
182  kount=kount+1
183  imnt(kount,l)=0
184  jmnt(kount,l)=0
185  IF(htmo(i,j,l)>0.5) cycle
186  kmn=kmn+1
187  imnt(kmn,l)=i
188  jmnt(kmn,l)=j
189  240 CONTINUE
190  kmntm(l)=kmn
191  250 CONTINUE
192 !
193 !
194 !*** CREATE A TEMPORARY TV ARRAY, AND FOLLOW BY SEQUENTIAL
195 !*** OVERRELAXATION, DOING NRLX PASSES.
196 !
197 ! IF(NTSD==1)THEN
198  nrlx=nrlx1
199 ! ELSE
200 ! NRLX=NRLX2
201 ! ENDIF
202 !
203 !!$omp parallel do private(i,j,tinit,ttv)
204  DO 300 l=lhmnt,lsm
205 !
206  DO 270 j=jsta,jend
207  DO 270 i=1,im
208  ttv(i,j)=tpres(i,j,l)
209  IF(ttv(i,j)<150. .and. ttv(i,j)>325.0)print* &
210  ,'abnormal IC for T relaxation',i,j,ttv(i,j)
211  htm2d(i,j)=htmo(i,j,l)
212  270 CONTINUE
213 !
214 !*** FOR GRID BOXES NEXT TO MOUNTAINS, COMPUTE TV TO USE AS
215 !*** BOUNDARY CONDITIONS FOR THE RELAXATION UNDERGROUND
216 !
217  CALL exch2(htm2d(1,jsta_2l)) !NEED TO EXCHANGE TWO ROW FOR E GRID
218  DO j=jsta_m2,jend_m2
219  DO i=2,im-1
220  IF(htm2d(i,j)>0.5.AND.htm2d(i+ihw(j),j-1)*htm2d(i+ihe(j),j-1) &
221  *htm2d(i+ihw(j),j+1)*htm2d(i+ihe(j),j+1) &
222  *htm2d(i-1 ,j )*htm2d(i+1 ,j ) &
223  *htm2d(i ,j-2)*htm2d(i ,j+2)<0.5)THEN
224 !HC MODIFICATION FOR C AND A GRIDS
225 !HC IF(HTM2D(I,J)>0.5.AND.
226 !HC 1 HTM2D(I-1,J)*HTM2D(I+1,J)
227 !HC 2 *HTM2D(I,J-1)*HTM2D(I,J+1)
228 !HC 3 *HTM2D(I-1,J-1)*HTM2D(I+1,J-1)
229 !HC 4 *HTM2D(I-1,J+1)*HTM2D(I+1,J+1)<0.5)THEN
230 !
231  ttv(i,j)=tpres(i,j,l)*(1.+0.608*qpres(i,j,l))
232  ENDIF
233 ! if(i==ii.and.j==jj)print*,'Debug:L,TTV B SMOO= ',l,TTV(I,J)
234  ENDDO
235  ENDDO
236 !
237  kmm=kmntm(l)
238 !
239  DO 285 n=1,nrlx
240  CALL exch2(ttv(1,jsta_2l))
241 ! print*,'Debug:L,KMM=',L,KMM
242  DO 280 km=1,kmm
243  i=imnt(km,l)
244  j=jmnt(km,l)
245  tinit=ttv(i,j)
246  tnew(i,j)=ad05*(4.*(ttv(i+ihw(j),j-1)+ttv(i+ihe(j),j-1) &
247  +ttv(i+ihw(j),j+1)+ttv(i+ihe(j),j+1)) &
248  +ttv(i-1,j) +ttv(i+1,j) &
249  +ttv(i,j-2) +ttv(i,j+2)) &
250  -cft0*ttv(i,j)
251 !HC MODIFICATION FOR C AND A GRIDS
252 ! eight point relaxation using old TTV
253 !HC TNEW(I,J)=AD05*(4.*(TTV(I-1,J)+TTV(I+1,J)
254 !HC 1 +TTV(I,J-1)+TTV(I,J+1))
255 !HC 2 +TTV(I-1,J-1)+TTV(I+1,J-1)
256 !HC 3 +TTV(I-1,J+1)+TTV(I+1,J+1))
257 !HC 4 -CFT0*TTV(I,J)
258 !
259 ! if(i==ii.and.j==jj)print*,'Debug: L,TTV A S'
260 ! 1,l,TTV(I,J),N
261 ! 1,l,TNEW(I,J),N
262  280 CONTINUE
263 !
264  DO km=1,kmm
265  i=imnt(km,l)
266  j=jmnt(km,l)
267  ttv(i,j)=tnew(i,j)
268  END DO
269  285 CONTINUE
270 !
271  DO 290 km=1,kmm
272  i=imnt(km,l)
273  j=jmnt(km,l)
274  tpres(i,j,l)=ttv(i,j)
275  290 CONTINUE
276  300 CONTINUE
277 !----------------------------------------------------------------
278 !***
279 !*** CALCULATE THE SEA LEVEL PRESSURE AS PER THE NEW SCHEME.
280 !*** INTEGRATE THE HYDROSTATIC EQUATION DOWNWARD FROM THE
281 !*** GROUND THROUGH EACH OUTPUT PRESSURE LEVEL (WHERE TV
282 !*** IS NOW KNOWN) TO FIND GZ AT THE NEXT MIDPOINT BETWEEN
283 !*** PRESSURE LEVELS. WHEN GZ=0 IS REACHED, SOLVE FOR THE
284 !*** PRESSURE.
285 !***
286 !
287 !*** COUNT THE POINTS WHERE SLP IS DONE BELOW EACH OUTPUT LEVEL
288 !
289  kount=0
290  DO j=jsta,jend
291  DO i=1,im
292 ! P1(I,J)=SPL(NINT(LMH(I,J)))
293 ! DONE(I,J)=.FALSE.
294  IF(abs(fis(i,j))<1.)THEN
295  pslp(i,j)=pint(i,j,nint(lmh(i,j))+1)
296  done(i,j)=.true.
297  kount=kount+1
298  if(i==ii.and.j==jj)print*,'Debug:DONE,PSLP A S1=' &
299  ,done(i,j),pslp(i,j)
300  ELSE IF(fis(i,j)<-1.0) THEN
301  DO l=lm,1,-1
302  IF(zint(i,j,l)>0.)THEN
303  pslp(i,j)=pint(i,j,l)/exp(-zint(i,j,l)*g &
304  /(rd*t(i,j,l)*(q(i,j,l)*d608+1.0)))
305  done(i,j)=.true.
306  if(debugprint .and. i==ii.and.j==jj)print* &
307  ,'Debug:DONE,PINT,PSLP A S1=' &
308  ,done(i,j),pint(i,j,l),pslp(i,j)
309  EXIT
310  END IF
311  END DO
312  ENDIF
313  ENDDO
314  ENDDO
315 !
316  kmm=kmntm(lsm)
317 !$omp parallel do private(gz1,gz2,i,j,lmap1,p1,p2),shared(pslp)
318 
319 loop320: DO km=1,kmm
320  i=imnt(km,lsm)
321  j=jmnt(km,lsm)
322  IF(done(i,j)) cycle
323  lmhij=lmho(i,j)
324  gz1=fipres(i,j,lmhij)
325  p1(i,j)=spl(lmhij)
326 !
327  lmap1=lmhij+1
328  DO l=lmap1,lsm
329  p2=spl(l)
330  tlyr=0.5*(tpres(i,j,l)+tpres(i,j,l-1))
331  gz2=gz1+rd*tlyr*alog(p1(i,j)/p2)
332  fipres(i,j,l)=gz2
333 ! if(i==ii.and.j==jj)print*,'Debug:L,FI A S2=',L,GZ2
334  IF(gz2<=0.)THEN
335  pslp(i,j)=p1(i,j)/exp(-gz1/(rd*tpres(i,j,l-1)))
336 ! if(i==ii.and.j==jj)print*,'Debug:PSLP A S2=',PSLP(I,J)
337  done(i,j)=.true.
338  kount=kount+1
339  cycle loop320
340  ENDIF
341  p1(i,j)=p2
342  gz1=gz2
343  ENDDO
344 !HC EXPERIMENT
345  lp=lsm
346  slope=-6.6e-4
347  tlyr=tpres(i,j,lp)-0.5*fipres(i,j,lp)*slope
348  pslp(i,j)=spl(lp)/exp(-fipres(i,j,lp)/(rd*tlyr))
349  done(i,j)=.true.
350 ! if(i==ii.and.j==jj)print*,'Debug:spl,FI,TLYR,PSLPA3=' &
351 ! ,spl(lp),FIPRES(I,J,LP),TLYR,PSLP(I,J)
352 !HC EXPERIMENT
353 ENDDO loop320
354 !
355 !*** WHEN SEA LEVEL IS BELOW THE LOWEST OUTPUT PRESSURE LEVEL,
356 !*** SOLVE THE HYDROSTATIC EQUATION BY CHOOSING A TEMPERATURE
357 !*** AT THE MIDPOINT OF THE LAYER BETWEEN THAT LOWEST PRESSURE
358 !*** LEVEL AND THE GROUND BY EXTRAPOLATING DOWNWARD FROM T ON
359 !*** THE LOWEST PRESSURE LEVEL USING THE DT/DFI BETWEEN THE
360 !*** LOWEST PRESSURE LEVEL AND THE ONE ABOVE IT.
361 !
362 ! TOTAL=(IM-2)*(JM-4)
363 !
364 !HC DO 340 LP=LSM,1,-1
365 ! IF(KOUNT==TOTAL)GO TO 350
366 !HC MODIFICATION FOR SMALL HILL HIGH PRESSURE SITUATION
367 !HC IF SURFACE PRESSURE IS CLOSER TO SEA LEVEL THAN LWOEST
368 !HC OUTPUT PRESSURE LEVEL, USE SURFACE PRESSURE TO DO EXTRAPOLATION
369  325 CONTINUE
370  lp=lsm
371  DO 330 j=jsta,jend
372  DO 330 i=1,im
373  if(debugprint .and. i==ii.and.j==jj)print*,'Debug: with 330 loop'
374  IF(done(i,j)) cycle
375  if(debugprint .and. i==ii.and.j==jj)print*,'Debug: still within 330 loop'
376 !HC Comment out the following line for situation with terrain
377 !HC at boundary (ie FIPRES<0)
378 !HC because they were not counted as undergound point for 8 pt
379 !HC relaxation
380 !HC IF(FIPRES(I,J,LP)<0.)GO TO 330
381 ! IF(FIPRES(I,J,LP)<0.)THEN
382 ! DO LP=LSM,1,-1
383 ! IF (FIPRES(I,J) <= 0)
384 
385 ! IF(FIPRES(I,J,LP)<0..OR.DONE(I,J))GO TO 330
386 ! SLOPE=(TPRES(I,J,LP)-TPRES(I,J,LP-1))
387 ! & /(FIPRES(I,J,LP)-FIPRES(I,J,LP-1))
388  slope=-6.6e-4
389  IF(pint(i,j,nint(lmh(i,j))+1)>spl(lp))THEN
390  llmh=nint(lmh(i,j))
391  tvrt=t(i,j,llmh)*(h1+d608*q(i,j,llmh))
392  dis=zint(i,j,llmh+1)-zint(i,j,llmh)+0.5*zint(i,j,llmh+1)
393  tlyr=tvrt-dis*g*slope
394  pslp(i,j)=pint(i,j,llmh+1)*exp(zint(i,j,llmh+1)*g/(rd*tlyr))
395 ! if(i==ii.and.j==jj)print*,'Debug:PSFC,zsfc,TLYR,PSLPA3='
396 ! 1,PINT(I,J,LLMH+1),ZINT(I,J,LLMH+1),TLYR,PSLP(I,J)
397  ELSE
398  tlyr=tpres(i,j,lp)-0.5*fipres(i,j,lp)*slope
399  pslp(i,j)=spl(lp)/exp(-fipres(i,j,lp)/(rd*tlyr))
400  if(debugprint .and. i==ii.and.j==jj)print*,'Debug:spl,FI,TLYR,PSLPA3=' &
401  ,spl(lp),fipres(i,j,lp),tlyr,pslp(i,j)
402  END IF
403  done(i,j)=.true.
404  kount=kount+1
405  330 CONTINUE
406 !HC 340 CONTINUE
407 !
408  350 CONTINUE
409 !----------------------------------------------------------------
410  RETURN
411  END
Definition: MASKS_mod.f:1