2 ! ======================================================================================
3 ! This file was generated by the version 4.3.7 of ADG on 08/10/2010. The Adjoint Code
4 ! Generator (ADG) was developed and sponsored by LASG of IAP (1999-2010)
5 ! The Copyright of the ADG system was declared by Walls at LASG, 1999-2010
6 ! ======================================================================================
8 MODULE a_module_diffusion_em
10 USE a_module_bc, only: a_set_physical_bc3d
11 USE module_state_description, only: p_m23, p_m13, p_m22, p_m33, p_r23, p_r13, p_r12, p_m12, p_m11
12 USE module_big_step_utilities_em, only: grid_config_rec_type, param_first_scalar, p_qv, p_qi, p_qc
14 USE module_model_constants
15 USE module_diffusion_em ! Added by Ning Pan, 2010-08-10
19 SUBROUTINE a_cal_deform_and_div(config_flags,u,a_u,v,a_v,w,a_w,div,a_div, &
20 defor11,a_defor11,defor22,a_defor22,defor33,a_defor33,defor12,a_defor12, &
21 defor13,a_defor13,defor23,a_defor23,nba_rij,a_nba_rij,n_nba_rij,u_base,v_base, &
22 msfux,msfuy,msfvx,msfvy,msftx,msfty,rdx,rdy,dn,dnw,rdz,a_rdz,rdzw,a_rdzw,fnm,fnp, &
23 cf1,cf2,cf3,zx,a_zx,zy,a_zy,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its, &
26 !PART I: DECLARATION OF VARIABLES
30 INTEGER :: K0_ADJ,K1_ADJ,K2_ADJ,K3_ADJ
31 TYPE(grid_config_rec_type) :: config_flags
32 INTEGER :: ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte
33 REAL :: rdx,rdy,cf1,cf2,cf3
34 REAL,DIMENSION(kms:kme) :: fnm,fnp,dn,dnw,u_base,v_base
35 REAL,DIMENSION(ims:ime,jms:jme) :: msfux,msfuy,msfvx,msfvy,msftx,msfty
36 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: u,a_u,v,a_v,w,a_w,zx,a_zx,zy, &
37 a_zy,rdz,a_rdz,rdzw,a_rdzw
38 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: defor11,a_defor11,defor22,a_defor22, &
39 defor33,a_defor33,defor12,a_defor12,defor13,a_defor13,defor23,a_defor23,div,a_div
41 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_nba_rij) :: nba_rij,a_nba_rij
42 INTEGER :: i,j,k,ktf,ktes1,ktes2,i_start,i_end,j_start,j_end
43 REAL :: tmp,a_tmp,tmpzx,a_tmpzx,tmpzy,a_tmpzy,tmpzeta_z,a_tmpzeta_z,cft1, &
45 REAL,DIMENSION(its:ite,jts:jte) :: mm,a_mm,zzavg,a_zzavg,zeta_zd12,a_zeta_zd12
46 REAL,DIMENSION(its-2:ite+2,kts:kte,jts-2:jte+2) :: tmp1,a_tmp1,hat,a_hat,hatavg, &
49 !BIG ERRORS, ADDED BY WALLS
50 !BIG ERRORS, ADDED BY WALLS
51 REAL,DIMENSION(its-2:ite+2,kts:kte,jts-2:jte+2) :: Keep_Lpb5_hatavg
52 REAL,DIMENSION(its-2:ite+2,kts:kte,jts-2:jte+2) :: Keep_Lpb12_hatavg
53 REAL,DIMENSION(its-2:ite+2,kts:kte,jts-2:jte+2) :: Keep_Lpb35_hatavg
54 REAL,DIMENSION(its-2:ite+2,kts:kte,jts-2:jte+2) :: Keep_Lpb40_hatavg
55 REAL,DIMENSION(its-2:ite+2,kts:kte,jts-2:jte+2) :: Keep_Lpb60_hatavg
57 !BIG ERRORS, ADDED BY WALLS
58 !BIG ERRORS, ADDED BY WALLS
59 REAL,DIMENSION(its-2:ite+2,kts:kte,jts-2:jte+2) :: Keep_Lpb2_hat
60 REAL,DIMENSION(its-2:ite+2,kts:kte,jts-2:jte+2) :: Keep_Lpb9_hat
61 REAL,DIMENSION(its-2:ite+2,kts:kte,jts-2:jte+2) :: Keep_Lpb32_hat
62 REAL,DIMENSION(its-2:ite+2,kts:kte,jts-2:jte+2) :: Keep_Lpb37_hat
63 REAL,DIMENSION(its-2:ite+2,kts:kte,jts-2:jte+2) :: Keep_Lpb54_hat
65 !BIG ERRORS, ADDED BY WALLS
66 !BIG ERRORS, ADDED BY WALLS
67 REAL,DIMENSION(its:ite,jts:jte) :: Keep_Lpb1_mm
68 REAL,DIMENSION(its:ite,jts:jte) :: Keep_Lpb31_mm
69 REAL,DIMENSION(its:ite,jts:jte) :: Keep_Lpb53_mm
71 !BIG ERRORS, ADDED BY WALLS
72 !BIG ERRORS, ADDED BY WALLS
73 REAL,DIMENSION(its-2:ite+2,kts:kte,jts-2:jte+2) :: Keep_Lpb35_tmp1
74 REAL,DIMENSION(its-2:ite+2,kts:kte,jts-2:jte+2) :: Keep_Lpb40_tmp1
75 REAL,DIMENSION(its-2:ite+2,kts:kte,jts-2:jte+2) :: Keep_Lpb60_tmp1
77 REAL,DIMENSION(its-2:ite+2,kts:kte,jts-2:jte+2) :: Keep_Lpb6_tmp1
78 REAL,DIMENSION(its-2:ite+2,kts:kte,jts-2:jte+2) :: Keep_Lpb13_tmp1
79 REAL,DIMENSION(max(jds+1,jts):min(jde-1,jte)) :: Keep_Lpb35_tmpzy
80 REAL,DIMENSION(max(jds+1,jts):min(jde-1,jte)) :: Keep_Lpb40_tmpzx
82 REAL :: a_Tmpv1,Tmpv001,a_Tmpv2,Tmpv002,a_Tmpv3,Tmpv003,a_Tmpv4,Tmpv004, &
83 a_Tmpv5,Tmpv005,a_Tmpv6,Tmpv006,a_Tmpv7,Tmpv007
84 REAL,DIMENSION(its:max0(min(ite,ide-1),ite)) :: Tmpv200
85 REAL,DIMENSION(its:max0(min(ite,ide-1),ite)) :: Tmpv201
86 REAL,DIMENSION(its:max0(min(ite,ide-1),ite,min(ite,ide)),min0(kts,kts+1) &
87 :min(kte,kde-1)) :: Tmpv300
88 REAL,DIMENSION(its:max0(min(ite,ide-1),ite,min(ite,ide)),min0(kts,kts+1) &
89 :min(kte,kde-1)) :: Tmpv301
90 REAL,DIMENSION(its:max0(min(ite,ide-1),ite,min(ite,ide)),min0(kts,kts+1) &
91 :min(kte,kde-1)) :: Tmpv302
92 REAL,DIMENSION(its:ite,kts:min(kte,kde-1)) :: Tmpv303
93 REAL,DIMENSION(its:max0(ite,min(ite,ide),min(ite,ide-1)),min0(kts,kts+1) &
94 :min(kte,kde-1),max(jds+1,jts):max0(min(jde-1,jte),min(jte,jde))) :: Tmpv400
95 REAL,DIMENSION(its:max0(ite,min(ite,ide),min(ite,ide-1)),min0(kts,kts+1) &
96 :min(kte,kde-1),max(jds+1,jts):max0(min(jde-1,jte),min(jte,jde))) :: Tmpv401
97 REAL,DIMENSION(its:max0(ite,min(ite,ide),min(ite,ide-1)),min0(kts,kts+1) &
98 :min(kte,kde-1),max(jds+1,jts):max0(min(jde-1,jte),min(jte,jde))) :: Tmpv402
99 REAL,DIMENSION(its:max0(min(ite,ide),min(ite,ide-1)),kts+1:min(kte,kde-1) &
100 ,max(jds+1,jts):min(jte,jde)) :: Tmpv403
103 !PART II: CALCULATIONS OF B. S. TRAJECTORY
108 cft2 = - 0.5 * dnw(ktes1) / dn(ktes1)
110 ktf = MIN( kte, kde-1 )
112 i_end = MIN( ite, ide-1 )
114 j_end = MIN( jte, jde-1 )
117 DO j = j_start, j_end
119 DO i = i_start, i_end
120 mm(i,j) = msftx(i,j) * msfty(i,j)
125 !BIG ERRORS, REVISED BY WALLS
129 DO j = j_start, j_end
132 DO i = i_start, i_end+1
133 hat(i,k,j) = u(i,k,j) / msfuy(i,j)
139 !BIG ERRORS, REVISED BY WALLS
140 ! Keep_Lpb2_hat =hat ! Remarked by Ning Pan, 2010-08-31
147 hatavg(i,k,j) = 0.5 * &
148 ( fnm(k) * ( hat(i,k ,j) + hat(i+1, k,j) ) + &
149 fnp(k) * ( hat(i,k-1,j) + hat(i+1,k-1,j) ) )
156 DO j = j_start, j_end
158 DO i = i_start, i_end
159 hatavg(i,1,j) = 0.5 * ( &
160 cf1 * hat(i ,1,j) + &
161 cf2 * hat(i ,2,j) + &
162 cf3 * hat(i ,3,j) + &
163 cf1 * hat(i+1,1,j) + &
164 cf2 * hat(i+1,2,j) + &
166 hatavg(i,kte,j) = 0.5 * ( &
167 cft1 * ( hat(i,ktes1,j) + hat(i+1,ktes1,j) ) + &
168 cft2 * ( hat(i,ktes2,j) + hat(i+1,ktes2,j) ) )
174 DO j = j_start, j_end
177 DO i = i_start, i_end
179 zx(i,k ,j) + zx(i+1,k ,j) + &
180 zx(i,k+1,j) + zx(i+1,k+1,j) )
181 !BIG ERRORS, ADDED BY WALLS
182 !BIG ERRORS, ADDED BY WALLS
183 Keep_Lpb5_hatavg(i,k,j) =hatavg(i,k+1,j) - hatavg(i,k,j)
184 tmp1(i,k,j) = ( hatavg(i,k+1,j) - hatavg(i,k,j) ) *tmpzx * rdzw(i,k,j)
190 ! Remarked by Ning Pan, 2010-08-31 : LPB[6]-[8]
192 ! DO j = j_start, j_end
195 !! DO k=kts, min(kte,kde-1)
196 !! DO i=its, min(ite,ide-1)
198 ! DO i=i_start, i_end
199 ! Keep_Lpb6_tmp1(i,k,j) =tmp1(i,k,j)
204 ! DO i = i_start, i_end
205 ! tmp1(i,k,j) = mm(i,j) * ( rdx * ( hat(i+1,k,j) - hat(i,k,j) ) - &
213 ! DO j = j_start, j_end
216 ! DO i = i_start, i_end
217 ! defor11(i,k,j) = 2.0 * tmp1(i,k,j)
224 ! DO j = j_start, j_end
227 ! DO i = i_start, i_end
228 ! div(i,k,j) = tmp1(i,k,j)
235 DO j = j_start, j_end+1
238 DO i = i_start, i_end
239 IF ((config_flags%polar) .AND. ((j == jds) .OR. (j == jde))) THEN
243 hat(i,k,j) = v(i,k,j) / msfvx(i,j)
250 !BIG ERRORS, REVISED BY WALLS
251 ! Keep_Lpb9_hat =hat ! Remarked by Ning Pan, 2010-08-31
258 hatavg(i,k,j) = 0.5 * ( &
259 fnm(k) * ( hat(i,k ,j) + hat(i,k ,j+1) ) + &
260 fnp(k) * ( hat(i,k-1,j) + hat(i,k-1,j+1) ) )
267 DO j = j_start, j_end
269 DO i = i_start, i_end
270 hatavg(i,1,j) = 0.5 * ( &
271 cf1 * hat(i,1,j ) + &
272 cf2 * hat(i,2,j ) + &
273 cf3 * hat(i,3,j ) + &
274 cf1 * hat(i,1,j+1) + &
275 cf2 * hat(i,2,j+1) + &
277 hatavg(i,kte,j) = 0.5 * ( &
278 cft1 * ( hat(i,ktes1,j) + hat(i,ktes1,j+1) ) + &
279 cft2 * ( hat(i,ktes2,j) + hat(i,ktes2,j+1) ) )
285 DO j = j_start, j_end
288 DO i = i_start, i_end
290 zy(i,k ,j) + zy(i,k ,j+1) + &
291 zy(i,k+1,j) + zy(i,k+1,j+1) )
292 !BIG ERRORS, ADDED BY WALLS
293 !BIG ERRORS, ADDED BY WALLS
294 Keep_Lpb12_hatavg(i,k,j) =hatavg(i,k+1,j) - hatavg(i,k,j)
295 tmp1(i,k,j) = ( hatavg(i,k+1,j) - hatavg(i,k,j) ) * tmpzy * rdzw(i,k,j)
301 ! Remarked by Ning Pan, 2010-08-31 : LPB[13]-[18]
303 ! DO j = j_start, j_end
305 ! DO k=kts, min(kte,kde-1)
306 ! DO i=its, min(ite,ide-1)
307 ! Keep_Lpb13_tmp1(i,k,j) =tmp1(i,k,j)
312 ! DO i = i_start, i_end
313 ! tmp1(i,k,j) = mm(i,j) * ( &
314 ! rdy * ( hat(i,k,j+1) - hat(i,k,j) ) - tmp1(i,k,j) )
321 ! DO j = j_start, j_end
324 ! DO i = i_start, i_end
325 ! defor22(i,k,j) = 2.0 * tmp1(i,k,j)
332 ! DO j = j_start, j_end
335 ! DO i = i_start, i_end
336 ! div(i,k,j) = div(i,k,j) + tmp1(i,k,j)
343 ! DO j = j_start, j_end
346 ! DO i = i_start, i_end
347 ! tmp1(i,k,j) = ( w(i,k+1,j) - w(i,k,j) ) * rdzw(i,k,j)
354 ! DO j = j_start, j_end
357 ! DO i = i_start, i_end
358 ! defor33(i,k,j) = 2.0 * tmp1(i,k,j)
365 ! DO j = j_start, j_end
368 ! DO i = i_start, i_end
369 ! div(i,k,j) = div(i,k,j) + tmp1(i,k,j)
382 IF ( config_flags%open_xs .OR. config_flags%specified .OR. &
383 config_flags%nested) i_start = MAX( ids+1, its )
388 IF ( config_flags%open_xe .OR. config_flags%specified .OR. &
389 config_flags%nested) i_end = MIN( ide-1, ite )
394 IF ( config_flags%open_ys .OR. config_flags%specified .OR. &
395 config_flags%nested) j_start = MAX( jds+1, jts )
400 IF ( config_flags%open_ye .OR. config_flags%specified .OR. &
401 config_flags%nested) j_end = MIN( jde-1, jte )
406 IF ( config_flags%periodic_x ) i_start = its
411 IF ( config_flags%periodic_x ) i_end = ite
414 DO j = j_start, j_end
416 DO i = i_start, i_end
417 mm(i,j) = 0.25 * ( msfux(i,j-1) + msfux(i,j) ) * ( msfvy(i-1,j) + msfvy(i,j) )
422 !BIG ERRORS, REVISED BY WALLS
426 DO j =j_start-1, j_end
430 hat(i,k,j) = u(i,k,j) / msfux(i,j)
436 !BIG ERRORS, REVISED BY WALLS
437 ! Keep_Lpb32_hat =hat ! Remarked by Ning Pan, 2010-08-31
444 hatavg(i,k,j) = 0.5 * ( &
445 fnm(k) * ( hat(i,k ,j-1) + hat(i,k ,j) ) + &
446 fnp(k) * ( hat(i,k-1,j-1) + hat(i,k-1,j) ) )
453 DO j = j_start, j_end
455 DO i = i_start, i_end
456 hatavg(i,1,j) = 0.5 * ( &
457 cf1 * hat(i,1,j-1) + &
458 cf2 * hat(i,2,j-1) + &
459 cf3 * hat(i,3,j-1) + &
460 cf1 * hat(i,1,j ) + &
461 cf2 * hat(i,2,j ) + &
463 hatavg(i,kte,j) = 0.5 * ( &
464 cft1 * ( hat(i,ktes1,j-1) + hat(i,ktes1,j) ) + &
465 cft2 * ( hat(i,ktes2,j-1) + hat(i,ktes2,j) ) )
471 DO j = j_start, j_end
473 ! Keep_Lpb35_tmpzy(j) =tmpzy ! Remarked by Ning Pan, 2010-08-31
476 DO i = i_start, i_end
478 zy(i-1,k ,j) + zy(i,k ,j) + &
479 zy(i-1,k+1,j) + zy(i,k+1,j) )
480 !BIG ERRORS, ADDED BY WALLS
481 !BIG ERRORS, ADDED BY WALLS
482 Keep_Lpb35_hatavg(i,k,j) =hatavg(i,k+1,j) - hatavg(i,k,j)
483 tmp1(i,k,j) = ( hatavg(i,k+1,j) - hatavg(i,k,j) ) * &
484 0.25 * tmpzy * ( rdzw(i,k,j) + rdzw(i-1,k,j) + &
485 rdzw(i-1,k,j-1) + rdzw(i,k,j-1) )
491 !BIG ERRORS, ADDED BY WALLS
492 ! Keep_Lpb35_tmp1 =tmp1 ! Remarked by Ning Pan, 2010-08-31
494 ! Remarked by Ning Pan, 2010-08-31 : LPB[36]
496 ! DO j = j_start, j_end
499 ! DO i = i_start, i_end
500 ! defor12(i,k,j) = mm(i,j) * ( &
501 ! rdy * ( hat(i,k,j) - hat(i,k,j-1) ) - tmp1(i,k,j) )
508 DO j = j_start, j_end
511 DO i = i_start-1, i_end
512 hat(i,k,j) = v(i,k,j) / msfvy(i,j)
518 !BIG ERRORS, REVISED BY WALLS
519 ! Keep_Lpb37_hat =hat ! Remarked by Ning Pan, 2010-08-31
522 DO j = j_start, j_end
525 DO i = i_start, i_end
526 hatavg(i,k,j) = 0.5 * ( &
527 fnm(k) * ( hat(i-1,k ,j) + hat(i,k ,j) ) + &
528 fnp(k) * ( hat(i-1,k-1,j) + hat(i,k-1,j) ) )
535 DO j = j_start, j_end
537 DO i = i_start, i_end
538 hatavg(i,1,j) = 0.5 * ( &
539 cf1 * hat(i-1,1,j) + &
540 cf2 * hat(i-1,2,j) + &
541 cf3 * hat(i-1,3,j) + &
542 cf1 * hat(i ,1,j) + &
543 cf2 * hat(i ,2,j) + &
545 hatavg(i,kte,j) = 0.5 * ( &
546 cft1 * ( hat(i,ktes1,j) + hat(i-1,ktes1,j) ) + &
547 cft2 * ( hat(i,ktes2,j) + hat(i-1,ktes2,j) ) )
553 DO j = j_start, j_end
555 ! Keep_Lpb40_tmpzx(j) =tmpzx ! Remarked by Ning Pan, 2010-08-31
558 DO i = i_start, i_end
560 zx(i,k ,j-1) + zx(i,k ,j) + &
561 zx(i,k+1,j-1) + zx(i,k+1,j) )
562 !BIG ERRORS, ADDED BY WALLS
563 !BIG ERRORS, ADDED BY WALLS
564 Keep_Lpb40_hatavg(i,k,j) =hatavg(i,k+1,j) - hatavg(i,k,j)
565 tmp1(i,k,j) = ( hatavg(i,k+1,j) - hatavg(i,k,j) ) * &
566 0.25 * tmpzx * ( rdzw(i,k,j) + rdzw(i,k,j-1) + &
567 rdzw(i-1,k,j-1) + rdzw(i-1,k,j) )
573 !BIG ERRORS, ADDED BY WALLS
574 ! Keep_Lpb40_tmp1 =tmp1 ! Remarked by Ning Pan, 2010-08-31
578 ! Remarked by Ning Pan, 2010-08-31
580 ! IF ( config_flags%sfs_opt .GT. 0 ) THEN
582 ! DO j = j_start, j_end
584 ! DO i = i_start, i_end
585 ! nba_rij(i,k,j,P_r12) = defor12(i,k,j) - &
587 ! rdx * ( hat(i,k,j) - hat(i-1,k,j) ) - tmp1(i,k,j) )
588 ! defor12(i,k,j) = defor12(i,k,j) + &
590 ! rdx * ( hat(i,k,j) - hat(i-1,k,j) ) - tmp1(i,k,j) )
594 ! IF ( .NOT. config_flags%periodic_x .AND. i_start .EQ. ids+1 ) THEN
598 ! defor12(ids,k,j) = defor12(ids+1,k,j)
599 ! nba_rij(ids,k,j,P_r12) = nba_rij(ids+1,k,j,P_r12)
603 ! IF ( .NOT. config_flags%periodic_y .AND. j_start .EQ. jds+1) THEN
607 ! defor12(i,k,jds) = defor12(i,k,jds+1)
608 ! nba_rij(i,k,jds,P_r12) = nba_rij(i,k,jds+1,P_r12)
612 ! IF ( .NOT. config_flags%periodic_x .AND. i_end .EQ. ide-1) THEN
616 ! defor12(ide,k,j) = defor12(ide-1,k,j)
617 ! nba_rij(ide,k,j,P_r12) = nba_rij(ide-1,k,j,P_r12)
621 ! IF ( .NOT. config_flags%periodic_y .AND. j_end .EQ. jde-1) THEN
625 ! defor12(i,k,jde) = defor12(i,k,jde-1)
626 ! nba_rij(i,k,jde,P_r12) = nba_rij(i,k,jde-1,P_r12)
632 ! DO j = j_start, j_end
634 ! DO i = i_start, i_end
635 ! defor12(i,k,j) = defor12(i,k,j) + &
637 ! rdx * ( hat(i,k,j) - hat(i-1,k,j) ) - tmp1(i,k,j) )
641 ! IF ( .NOT. config_flags%periodic_x .AND. i_start .EQ. ids+1 ) THEN
645 ! defor12(ids,k,j) = defor12(ids+1,k,j)
649 ! IF ( .NOT. config_flags%periodic_y .AND. j_start .EQ. jds+1) THEN
653 ! defor12(i,k,jds) = defor12(i,k,jds+1)
657 ! IF ( .NOT. config_flags%periodic_x .AND. i_end .EQ. ide-1) THEN
661 ! defor12(ide,k,j) = defor12(ide-1,k,j)
665 ! IF ( .NOT. config_flags%periodic_y .AND. j_end .EQ. jde-1) THEN
669 ! defor12(i,k,jde) = defor12(i,k,jde-1)
679 i_end = MIN( ite, ide-1 )
681 j_end = MIN( jte, jde-1 )
684 IF ( config_flags%open_xs .OR. config_flags%specified .OR. &
685 config_flags%nested) i_start = MAX( ids+1, its )
690 IF ( config_flags%open_ys .OR. config_flags%specified .OR. &
691 config_flags%nested) j_start = MAX( jds+1, jts )
696 IF ( config_flags%periodic_x ) i_start = its
701 IF ( config_flags%periodic_x ) i_end = MIN( ite, ide )
706 IF ( config_flags%periodic_y ) j_end = MIN( jte, jde )
712 mm(i,j) = msfux(i,j) * msfuy(i,j)
717 !BIG ERRORS, REVISED BY WALLS
720 DO j = j_start, j_end
723 DO i = i_start, i_end
724 hat(i,k,j) = w(i,k,j) / msfty(i,j)
734 DO j = j_start, MIN( jte, jde-1 )
737 hat(i,k,j) = w(i,k,j) / msfty(i,j)
748 DO i = i_start, MIN( ite, ide-1 )
749 hat(i,k,j) = w(i,k,j) / msfty(i,j)
754 !BIG ERRORS, REVISED BY WALLS
755 ! Keep_Lpb54_hat =hat ! Remarked by Ning Pan, 2010-08-31
758 DO j = j_start, j_end
761 DO i = i_start, i_end
762 hatavg(i,k,j) = 0.25 * ( &
773 DO j = j_start, j_end
776 DO i = i_start, i_end
777 !BIG ERRORS, ADDED BY WALLS
778 !BIG ERRORS, ADDED BY WALLS
779 Keep_Lpb60_hatavg(i,k,j) =hatavg(i,k,j) - hatavg(i,k-1,j)
780 tmp1(i,k,j) = ( hatavg(i,k,j) - hatavg(i,k-1,j) ) * zx(i,k,j) * &
781 0.5 * ( rdz(i,k,j) + rdz(i-1,k,j) )
787 !BIG ERRORS, ADDED BY WALLS
788 ! Keep_Lpb60_tmp1 =tmp1 ! Remarked by Ning Pan, 2010-08-31
790 ! Remarked by Ning Pan, 2010-08-31 : LPB[61]-[66]
792 ! DO j = j_start, j_end
795 ! DO i = i_start, i_end
796 ! defor13(i,k,j) = mm(i,j) * ( &
797 ! rdx * ( hat(i,k,j) - hat(i-1,k,j) ) - tmp1(i,k,j) )
804 ! DO j = j_start, j_end
806 ! DO i = i_start, i_end
807 ! defor13(i,kts,j ) = 0.0
808 ! defor13(i,ktf+1,j) = 0.0
816 ! IF ( config_flags%mix_full_fields ) THEN
818 ! DO j = j_start, j_end
820 ! DO i = i_start, i_end
821 ! tmp1(i,k,j) = ( u(i,k,j) - u(i,k-1,j) ) * &
822 ! 0.5 * ( rdz(i,k,j) + rdz(i-1,k,j) )
828 ! DO j = j_start, j_end
830 ! DO i = i_start, i_end
831 ! tmp1(i,k,j) = ( u(i,k,j) - u_base(k) - u(i,k-1,j) + u_base(k-1) ) * &
832 ! 0.5 * ( rdz(i,k,j) + rdz(i-1,k,j) )
843 ! IF ( config_flags%sfs_opt .GT. 0 ) THEN
845 ! DO j = j_start, j_end
847 ! DO i = i_start, i_end
848 ! nba_rij(i,k,j,P_r13) = tmp1(i,k,j) - defor13(i,k,j)
849 ! defor13(i,k,j) = defor13(i,k,j) + tmp1(i,k,j)
854 ! DO j = j_start, j_end
855 ! DO i = i_start, i_end
856 ! nba_rij(i,kts ,j,P_r13) = 0.0
857 ! nba_rij(i,ktf+1,j,P_r13) = 0.0
862 ! DO j = j_start, j_end
864 ! DO i = i_start, i_end
865 ! defor13(i,k,j) = defor13(i,k,j) + tmp1(i,k,j)
875 i_end = MIN( ite, ide-1 )
877 j_end = MIN( jte, jde-1 )
880 IF ( config_flags%open_xs .OR. config_flags%specified .OR. &
881 config_flags%nested) i_start = MAX( ids+1, its )
886 IF ( config_flags%open_ys .OR. config_flags%specified .OR. &
887 config_flags%nested) j_start = MAX( jds+1, jts )
892 IF ( config_flags%periodic_y ) j_end = MIN( jte, jde )
897 IF ( config_flags%periodic_x ) i_start = its
902 IF ( config_flags%periodic_x ) i_end = MIN( ite, ide-1 )
908 mm(i,j) = msfvx(i,j) * msfvy(i,j)
914 DO j = j_start, j_end
917 DO i = i_start, i_end
918 hat(i,k,j) = w(i,k,j) / msftx(i,j)
928 DO j = j_start, MIN( jte, jde-1 )
931 hat(i,k,j) = w(i,k,j) / msftx(i,j)
942 DO i = i_start, MIN( ite, ide-1 )
943 hat(i,k,j) = w(i,k,j) / msftx(i,j)
949 DO j = j_start, j_end
952 DO i = i_start, i_end
953 hatavg(i,k,j) = 0.25 * ( &
963 ! Remarked by Ning Pan, 2010-08-31 : LPB[84]-[86]
965 ! DO j = j_start, j_end
968 ! DO i = i_start, i_end
969 ! tmp1(i,k,j) = ( hatavg(i,k,j) - hatavg(i,k-1,j) ) * zy(i,k,j) * &
970 ! 0.5 * ( rdz(i,k,j) + rdz(i,k,j-1) )
977 ! DO j = j_start, j_end
980 ! DO i = i_start, i_end
981 ! defor23(i,k,j) = mm(i,j) * ( &
982 ! rdy * ( hat(i,k,j) - hat(i,k,j-1) ) - tmp1(i,k,j) )
989 ! DO j = j_start, j_end
991 ! DO i = i_start, i_end
992 ! defor23(i,kts,j ) = 0.0
993 ! defor23(i,ktf+1,j) = 0.0
1001 ! IF ( config_flags%mix_full_fields ) THEN
1003 ! DO j = j_start, j_end
1005 ! DO i = i_start, i_end
1006 ! tmp1(i,k,j) = ( v(i,k,j) - v(i,k-1,j) ) * &
1007 ! 0.5 * ( rdz(i,k,j) + rdz(i,k,j-1) )
1013 ! DO j = j_start, j_end
1015 ! DO i = i_start, i_end
1016 ! tmp1(i,k,j) = ( v(i,k,j) - v_base(k) - v(i,k-1,j) + v_base(k-1) ) * &
1017 ! 0.5 * ( rdz(i,k,j) + rdz(i,k,j-1) )
1028 ! IF ( config_flags%sfs_opt .GT. 0 ) THEN
1030 ! DO j = j_start, j_end
1032 ! DO i = i_start, i_end
1033 ! nba_rij(i,k,j,P_r23) = tmp1(i,k,j) - defor23(i,k,j)
1034 ! defor23(i,k,j) = defor23(i,k,j) + tmp1(i,k,j)
1039 ! DO j = j_start, j_end
1040 ! DO i = i_start, i_end
1041 ! nba_rij(i,kts ,j,P_r23) = 0.0
1042 ! nba_rij(i,ktf+1,j,P_r23) = 0.0
1045 ! IF ( .NOT. config_flags%periodic_x .AND. i_start .EQ. ids+1) THEN
1049 ! defor13(ids,k,j) = defor13(ids+1,k,j)
1050 ! defor23(ids,k,j) = defor23(ids+1,k,j)
1051 ! nba_rij(ids,k,j,P_r13) = nba_rij(ids+1,k,j,P_r13)
1052 ! nba_rij(ids,k,j,P_r23) = nba_rij(ids+1,k,j,P_r23)
1056 ! IF ( .NOT. config_flags%periodic_y .AND. j_start .EQ. jds+1) THEN
1060 ! defor13(i,k,jds) = defor13(i,k,jds+1)
1061 ! defor23(i,k,jds) = defor23(i,k,jds+1)
1062 ! nba_rij(i,k,jds,P_r13) = nba_rij(i,k,jds+1,P_r13)
1063 ! nba_rij(i,k,jds,P_r23) = nba_rij(i,k,jds+1,P_r23)
1067 ! IF ( .NOT. config_flags%periodic_x .AND. i_end .EQ. ide-1) THEN
1071 ! defor13(ide,k,j) = defor13(ide-1,k,j)
1072 ! defor23(ide,k,j) = defor23(ide-1,k,j)
1073 ! nba_rij(ide,k,j,P_r13) = nba_rij(ide-1,k,j,P_r13)
1074 ! nba_rij(ide,k,j,P_r23) = nba_rij(ide-1,k,j,P_r23)
1078 ! IF ( .NOT. config_flags%periodic_y .AND. j_end .EQ. jde-1) THEN
1082 ! defor13(i,k,jde) = defor13(i,k,jde-1)
1083 ! defor23(i,k,jde) = defor23(i,k,jde-1)
1084 ! nba_rij(i,k,jde,P_r13) = nba_rij(i,k,jde-1,P_r13)
1085 ! nba_rij(i,k,jde,P_r23) = nba_rij(i,k,jde-1,P_r23)
1091 ! DO j = j_start, j_end
1093 ! DO i = i_start, i_end
1094 ! defor23(i,k,j) = defor23(i,k,j) + tmp1(i,k,j)
1098 ! IF ( .NOT. config_flags%periodic_x .AND. i_start .EQ. ids+1) THEN
1102 ! defor13(ids,k,j) = defor13(ids+1,k,j)
1103 ! defor23(ids,k,j) = defor23(ids+1,k,j)
1107 ! IF ( .NOT. config_flags%periodic_y .AND. j_start .EQ. jds+1) THEN
1111 ! defor13(i,k,jds) = defor13(i,k,jds+1)
1112 ! defor23(i,k,jds) = defor23(i,k,jds+1)
1116 ! IF ( .NOT. config_flags%periodic_x .AND. i_end .EQ. ide-1) THEN
1120 ! defor13(ide,k,j) = defor13(ide-1,k,j)
1121 ! defor23(ide,k,j) = defor23(ide-1,k,j)
1125 ! IF ( .NOT. config_flags%periodic_y .AND. j_end .EQ. jde-1) THEN
1129 ! defor13(i,k,jde) = defor13(i,k,jde-1)
1130 ! defor23(i,k,jde) = defor23(i,k,jde-1)
1137 !PART III: INITIALIZATION OF LOCAL ADJOINT PERTURBATIONS
1143 ! Remarked by Ning Pan, 2010-08-31
1147 ! Remarked by Ning Pan, 2010-08-31
1148 ! Do K1_ADJ =jts, jte
1149 ! Do K0_ADJ =its, ite
1150 ! a_mm(K0_ADJ,K1_ADJ) =0.0
1154 ! Remarked by Ning Pan, 2010-08-31
1155 ! Do K1_ADJ =jts, jte
1156 ! Do K0_ADJ =its, ite
1157 ! a_zzavg(K0_ADJ,K1_ADJ) =0.0
1161 ! Remarked by Ning Pan, 2010-08-31
1162 ! Do K1_ADJ =jts, jte
1163 ! Do K0_ADJ =its, ite
1164 ! a_zeta_zd12(K0_ADJ,K1_ADJ) =0.0
1168 Do K2_ADJ =jts-2, jte+2
1170 Do K0_ADJ =its-2, ite+2
1171 a_tmp1(K0_ADJ,K1_ADJ,K2_ADJ) =0.0
1176 Do K2_ADJ =jts-2, jte+2
1178 Do K0_ADJ =its-2, ite+2
1179 a_hat(K0_ADJ,K1_ADJ,K2_ADJ) =0.0
1184 Do K2_ADJ =jts-2, jte+2
1186 Do K0_ADJ =its-2, ite+2
1187 a_hatavg(K0_ADJ,K1_ADJ,K2_ADJ) =0.0
1192 !PART IV: REVERSE/BACKWARD ACCUMULATIONS
1196 ! IF( config_flags%sfs_opt .GT. 0 ) THEN
1197 ! DO j =j_start, j_end
1199 ! DO i =i_start, i_end
1200 ! Tmpv001 =tmp1(i,k,j) -defor23(i,k,j)
1201 ! nba_rij(i,k,j,P_r23) =Tmpv001
1203 ! Tmpv001 =defor23(i,k,j) +tmp1(i,k,j)
1204 ! defor23(i,k,j) =Tmpv001
1209 ! DO j =j_start, j_end
1210 ! DO i =i_start, i_end
1211 ! nba_rij(i,kts,j,P_r23) =0.0
1213 ! nba_rij(i,ktf+1,j,P_r23) =0.0
1217 ! IF( .NOT. config_flags%periodic_x .AND. i_start .EQ. ids+1) THEN
1220 ! defor13(ids,k,j) =defor13(ids+1,k,j)
1222 ! defor23(ids,k,j) =defor23(ids+1,k,j)
1224 ! nba_rij(ids,k,j,P_r13) =nba_rij(ids+1,k,j,P_r13)
1226 ! nba_rij(ids,k,j,P_r23) =nba_rij(ids+1,k,j,P_r23)
1231 ! IF( .NOT. config_flags%periodic_y .AND. j_start .EQ. jds+1) THEN
1234 ! defor13(i,k,jds) =defor13(i,k,jds+1)
1236 ! defor23(i,k,jds) =defor23(i,k,jds+1)
1238 ! nba_rij(i,k,jds,P_r13) =nba_rij(i,k,jds+1,P_r13)
1240 ! nba_rij(i,k,jds,P_r23) =nba_rij(i,k,jds+1,P_r23)
1245 ! IF( .NOT. config_flags%periodic_x .AND. i_end .EQ. ide-1) THEN
1248 ! defor13(ide,k,j) =defor13(ide-1,k,j)
1250 ! defor23(ide,k,j) =defor23(ide-1,k,j)
1252 ! nba_rij(ide,k,j,P_r13) =nba_rij(ide-1,k,j,P_r13)
1254 ! nba_rij(ide,k,j,P_r23) =nba_rij(ide-1,k,j,P_r23)
1259 ! IF( .NOT. config_flags%periodic_y .AND. j_end .EQ. jde-1) THEN
1262 ! defor13(i,k,jde) =defor13(i,k,jde-1)
1264 ! defor23(i,k,jde) =defor23(i,k,jde-1)
1266 ! nba_rij(i,k,jde,P_r13) =nba_rij(i,k,jde-1,P_r13)
1268 ! nba_rij(i,k,jde,P_r23) =nba_rij(i,k,jde-1,P_r23)
1274 ! DO j =j_start, j_end
1276 ! DO i =i_start, i_end
1277 ! Tmpv001 =defor23(i,k,j) +tmp1(i,k,j)
1278 ! defor23(i,k,j) =Tmpv001
1283 ! IF( .NOT. config_flags%periodic_x .AND. i_start .EQ. ids+1) THEN
1286 ! defor13(ids,k,j) =defor13(ids+1,k,j)
1288 ! defor23(ids,k,j) =defor23(ids+1,k,j)
1293 ! IF( .NOT. config_flags%periodic_y .AND. j_start .EQ. jds+1) THEN
1296 ! defor13(i,k,jds) =defor13(i,k,jds+1)
1298 ! defor23(i,k,jds) =defor23(i,k,jds+1)
1303 ! IF( .NOT. config_flags%periodic_x .AND. i_end .EQ. ide-1) THEN
1306 ! defor13(ide,k,j) =defor13(ide-1,k,j)
1308 ! defor23(ide,k,j) =defor23(ide-1,k,j)
1313 ! IF( .NOT. config_flags%periodic_y .AND. j_end .EQ. jde-1) THEN
1316 ! defor13(i,k,jde) =defor13(i,k,jde-1)
1318 ! defor23(i,k,jde) =defor23(i,k,jde-1)
1325 IF( config_flags%sfs_opt .GT. 0 ) THEN
1327 IF( .NOT. config_flags%periodic_y .AND. j_end .EQ. jde-1) THEN
1331 a_nba_rij(i,k,jde-1,P_r23) =a_nba_rij(i,k,jde-1,P_r23) +a_nba_rij(i,k,jde,P_r23)
1332 a_nba_rij(i,k,jde,P_r23) =0.0
1333 a_nba_rij(i,k,jde-1,P_r13) =a_nba_rij(i,k,jde-1,P_r13) +a_nba_rij(i,k,jde,P_r13)
1334 a_nba_rij(i,k,jde,P_r13) =0.0
1335 a_defor23(i,k,jde-1) =a_defor23(i,k,jde-1) +a_defor23(i,k,jde)
1336 a_defor23(i,k,jde) =0.0
1337 a_defor13(i,k,jde-1) =a_defor13(i,k,jde-1) +a_defor13(i,k,jde)
1338 a_defor13(i,k,jde) =0.0
1344 IF( .NOT. config_flags%periodic_x .AND. i_end .EQ. ide-1) THEN
1348 a_nba_rij(ide-1,k,j,P_r23) =a_nba_rij(ide-1,k,j,P_r23) +a_nba_rij(ide,k,j,P_r23)
1349 a_nba_rij(ide,k,j,P_r23) =0.0
1350 a_nba_rij(ide-1,k,j,P_r13) =a_nba_rij(ide-1,k,j,P_r13) +a_nba_rij(ide,k,j,P_r13)
1351 a_nba_rij(ide,k,j,P_r13) =0.0
1352 a_defor23(ide-1,k,j) =a_defor23(ide-1,k,j) +a_defor23(ide,k,j)
1353 a_defor23(ide,k,j) =0.0
1354 a_defor13(ide-1,k,j) =a_defor13(ide-1,k,j) +a_defor13(ide,k,j)
1355 a_defor13(ide,k,j) =0.0
1361 IF( .NOT. config_flags%periodic_y .AND. j_start .EQ. jds+1) THEN
1365 a_nba_rij(i,k,jds+1,P_r23) =a_nba_rij(i,k,jds+1,P_r23) +a_nba_rij(i,k,jds,P_r23)
1366 a_nba_rij(i,k,jds,P_r23) =0.0
1367 a_nba_rij(i,k,jds+1,P_r13) =a_nba_rij(i,k,jds+1,P_r13) +a_nba_rij(i,k,jds,P_r13)
1368 a_nba_rij(i,k,jds,P_r13) =0.0
1369 a_defor23(i,k,jds+1) =a_defor23(i,k,jds+1) +a_defor23(i,k,jds)
1370 a_defor23(i,k,jds) =0.0
1371 a_defor13(i,k,jds+1) =a_defor13(i,k,jds+1) +a_defor13(i,k,jds)
1372 a_defor13(i,k,jds) =0.0
1378 IF( .NOT. config_flags%periodic_x .AND. i_start .EQ. ids+1) THEN
1382 a_nba_rij(ids+1,k,j,P_r23) =a_nba_rij(ids+1,k,j,P_r23) +a_nba_rij(ids,k,j,P_r23)
1383 a_nba_rij(ids,k,j,P_r23) =0.0
1384 a_nba_rij(ids+1,k,j,P_r13) =a_nba_rij(ids+1,k,j,P_r13) +a_nba_rij(ids,k,j,P_r13)
1385 a_nba_rij(ids,k,j,P_r13) =0.0
1386 a_defor23(ids+1,k,j) =a_defor23(ids+1,k,j) +a_defor23(ids,k,j)
1387 a_defor23(ids,k,j) =0.0
1388 a_defor13(ids+1,k,j) =a_defor13(ids+1,k,j) +a_defor13(ids,k,j)
1389 a_defor13(ids,k,j) =0.0
1394 DO j =j_end, j_start, -1
1395 DO i =i_end, i_start, -1
1396 a_nba_rij(i,ktf+1,j,P_r23) =0.0
1397 a_nba_rij(i,kts,j,P_r23) =0.0
1400 DO j =j_end, j_start, -1
1401 DO k =ktf, kts+1, -1
1402 DO i =i_end, i_start, -1
1403 a_Tmpv1 =a_defor23(i,k,j)
1404 a_defor23(i,k,j) =0.0
1405 a_defor23(i,k,j) =a_defor23(i,k,j) +a_Tmpv1
1406 a_tmp1(i,k,j) =a_tmp1(i,k,j) +a_Tmpv1
1407 a_Tmpv1 =a_nba_rij(i,k,j,P_r23)
1408 a_nba_rij(i,k,j,P_r23) =0.0
1409 a_tmp1(i,k,j) =a_tmp1(i,k,j) +a_Tmpv1
1410 a_defor23(i,k,j) =a_defor23(i,k,j) -a_Tmpv1
1417 IF( .NOT. config_flags%periodic_y .AND. j_end .EQ. jde-1) THEN
1421 a_defor23(i,k,jde-1) =a_defor23(i,k,jde-1) +a_defor23(i,k,jde)
1422 a_defor23(i,k,jde) =0.0
1423 a_defor13(i,k,jde-1) =a_defor13(i,k,jde-1) +a_defor13(i,k,jde)
1424 a_defor13(i,k,jde) =0.0
1430 IF( .NOT. config_flags%periodic_x .AND. i_end .EQ. ide-1) THEN
1434 a_defor23(ide-1,k,j) =a_defor23(ide-1,k,j) +a_defor23(ide,k,j)
1435 a_defor23(ide,k,j) =0.0
1436 a_defor13(ide-1,k,j) =a_defor13(ide-1,k,j) +a_defor13(ide,k,j)
1437 a_defor13(ide,k,j) =0.0
1443 IF( .NOT. config_flags%periodic_y .AND. j_start .EQ. jds+1) THEN
1447 a_defor23(i,k,jds+1) =a_defor23(i,k,jds+1) +a_defor23(i,k,jds)
1448 a_defor23(i,k,jds) =0.0
1449 a_defor13(i,k,jds+1) =a_defor13(i,k,jds+1) +a_defor13(i,k,jds)
1450 a_defor13(i,k,jds) =0.0
1456 IF( .NOT. config_flags%periodic_x .AND. i_start .EQ. ids+1) THEN
1460 a_defor23(ids+1,k,j) =a_defor23(ids+1,k,j) +a_defor23(ids,k,j)
1461 a_defor23(ids,k,j) =0.0
1462 a_defor13(ids+1,k,j) =a_defor13(ids+1,k,j) +a_defor13(ids,k,j)
1463 a_defor13(ids,k,j) =0.0
1468 DO j =j_end, j_start, -1
1469 DO k =ktf, kts+1, -1
1470 DO i =i_end, i_start, -1
1471 a_Tmpv1 =a_defor23(i,k,j)
1472 a_defor23(i,k,j) =0.0
1473 a_defor23(i,k,j) =a_defor23(i,k,j) +a_Tmpv1
1474 a_tmp1(i,k,j) =a_tmp1(i,k,j) +a_Tmpv1
1485 IF( config_flags%mix_full_fields ) THEN
1486 DO j =j_start, j_end
1488 DO i =i_start, i_end
1489 Tmpv001 =v(i,k,j) -v(i,k-1,j)
1490 Tmpv002 =Tmpv001*0.5
1491 Tmpv003 =rdz(i,k,j) +rdz(i,k,j-1)
1492 Tmpv400(i,k,j) =Tmpv002
1493 Tmpv401(i,k,j) =Tmpv003
1494 ! Remarked by Ning Pan, 2010-08-31
1495 ! Tmpv004 =Tmpv400(i,k,j)*Tmpv401(i,k,j)
1496 ! tmp1(i,k,j) =Tmpv004
1502 DO j =j_start, j_end
1504 DO i =i_start, i_end
1505 Tmpv001 =v(i,k,j) -v_base(k) -v(i,k-1,j)
1506 Tmpv002 =Tmpv001 +v_base(k-1)
1507 Tmpv003 =Tmpv002*0.5
1508 Tmpv004 =rdz(i,k,j) +rdz(i,k,j-1)
1509 Tmpv402(i,k,j) =Tmpv003
1510 Tmpv403(i,k,j) =Tmpv004
1511 ! Remarked by Ning Pan, 2010-08-31
1512 ! Tmpv005 =Tmpv402(i,k,j)*Tmpv403(i,k,j)
1513 ! tmp1(i,k,j) =Tmpv005
1520 IF( config_flags%mix_full_fields ) THEN
1522 DO j =j_end, j_start, -1
1523 DO k =ktf, kts+1, -1
1524 DO i =i_end, i_start, -1
1525 a_Tmpv4 =a_tmp1(i,k,j)
1527 a_Tmpv2 =Tmpv401(i,k,j)*a_Tmpv4
1528 a_Tmpv3 =Tmpv400(i,k,j)*a_Tmpv4
1529 a_rdz(i,k,j) =a_rdz(i,k,j) +a_Tmpv3
1530 a_rdz(i,k,j-1) =a_rdz(i,k,j-1) +a_Tmpv3
1531 a_Tmpv1 =0.5*a_Tmpv2
1532 a_v(i,k,j) =a_v(i,k,j) +a_Tmpv1
1533 a_v(i,k-1,j) =a_v(i,k-1,j) -a_Tmpv1
1540 DO j =j_end, j_start, -1
1541 DO k =ktf, kts+1, -1
1542 DO i =i_end, i_start, -1
1543 a_Tmpv5 =a_tmp1(i,k,j)
1545 a_Tmpv3 =Tmpv403(i,k,j)*a_Tmpv5
1546 a_Tmpv4 =Tmpv402(i,k,j)*a_Tmpv5
1547 a_rdz(i,k,j) =a_rdz(i,k,j) +a_Tmpv4
1548 a_rdz(i,k,j-1) =a_rdz(i,k,j-1) +a_Tmpv4
1549 a_Tmpv2 =0.5*a_Tmpv3
1551 a_v(i,k,j) =a_v(i,k,j) +a_Tmpv1
1552 a_v(i,k-1,j) =a_v(i,k-1,j) -a_Tmpv1
1562 DO j =j_end, j_start, -1
1564 ! DO i =i_start, i_end
1565 ! defor23(i,kts,j) =0.0
1567 ! defor23(i,ktf+1,j) =0.0
1571 DO i =i_end, i_start, -1
1572 a_defor23(i,ktf+1,j) =0.0
1573 a_defor23(i,kts,j) =0.0
1579 DO j =j_end, j_start, -1
1581 ! Remarked by Ning Pan, 2010-08-31
1583 ! DO i =i_start, i_end
1584 ! Tmpv001 =hat(i,k,j) -hat(i,k,j-1)
1585 ! Tmpv002 =rdy*Tmpv001
1586 ! Tmpv003 =Tmpv002 -tmp1(i,k,j)
1587 ! Tmpv300(i,k) =Tmpv003
1588 ! Tmpv004 =mm(i,j)*Tmpv300(i,k)
1589 ! defor23(i,k,j) =Tmpv004
1594 DO k =ktf, kts+1, -1
1595 DO i =i_end, i_start, -1
1596 a_Tmpv4 =a_defor23(i,k,j)
1597 a_defor23(i,k,j) =0.0
1598 ! a_mm(i,j) =a_mm(i,j) +Tmpv300(i,k)*a_Tmpv4 ! Remarked by Ning Pan, 2010-08-31
1599 a_Tmpv3 =mm(i,j)*a_Tmpv4
1601 a_tmp1(i,k,j) =a_tmp1(i,k,j) -a_Tmpv3
1602 a_Tmpv1 =rdy*a_Tmpv2
1603 a_hat(i,k,j) =a_hat(i,k,j) +a_Tmpv1
1604 a_hat(i,k,j-1) =a_hat(i,k,j-1) -a_Tmpv1
1612 DO j =j_end, j_start, -1
1615 DO i =i_start, i_end
1616 Tmpv001 =hatavg(i,k,j) -hatavg(i,k-1,j)
1617 Tmpv300(i,k) =Tmpv001
1618 Tmpv002 =Tmpv300(i,k)*zy(i,k,j)
1619 Tmpv003 =Tmpv002*0.5
1620 Tmpv004 =rdz(i,k,j) +rdz(i,k,j-1)
1621 Tmpv301(i,k) =Tmpv003
1622 Tmpv302(i,k) =Tmpv004
1623 ! Remarked by Ning Pan, 2010-08-31
1624 ! Tmpv005 =Tmpv301(i,k)*Tmpv302(i,k)
1625 ! tmp1(i,k,j) =Tmpv005
1630 DO k =ktf, kts+1, -1
1631 DO i =i_end, i_start, -1
1632 a_Tmpv5 =a_tmp1(i,k,j)
1634 a_Tmpv3 =Tmpv302(i,k)*a_Tmpv5
1635 a_Tmpv4 =Tmpv301(i,k)*a_Tmpv5
1636 a_rdz(i,k,j) =a_rdz(i,k,j) +a_Tmpv4
1637 a_rdz(i,k,j-1) =a_rdz(i,k,j-1) +a_Tmpv4
1638 a_Tmpv2 =0.5*a_Tmpv3
1639 a_Tmpv1 =zy(i,k,j)*a_Tmpv2
1640 a_zy(i,k,j) =a_zy(i,k,j) +Tmpv300(i,k)*a_Tmpv2
1641 a_hatavg(i,k,j) =a_hatavg(i,k,j) +a_Tmpv1
1642 a_hatavg(i,k-1,j) =a_hatavg(i,k-1,j) -a_Tmpv1
1648 !BIG ERRORS, ADDED BY WALLS
1649 ! tmp1 =Keep_Lpb60_tmp1 ! Remarked by Ning Pan, 2010-08-31
1652 DO j =j_end, j_start, -1
1655 ! DO i =i_start, i_end
1656 ! Tmpv001 =hat(i,k,j) +hat(i,k+1,j)
1657 ! Tmpv002 =Tmpv001 +hat(i,k,j-1)
1658 ! Tmpv003 =Tmpv002 +hat(i,k+1,j-1)
1659 ! Tmpv004 =0.25*Tmpv003
1660 ! hatavg(i,k,j) =Tmpv004
1666 DO i =i_end, i_start, -1
1667 a_Tmpv4 =a_hatavg(i,k,j)
1668 a_hatavg(i,k,j) =0.0
1669 a_Tmpv3 =0.25*a_Tmpv4
1671 a_hat(i,k+1,j-1) =a_hat(i,k+1,j-1) +a_Tmpv3
1673 a_hat(i,k,j-1) =a_hat(i,k,j-1) +a_Tmpv2
1674 a_hat(i,k,j) =a_hat(i,k,j) +a_Tmpv1
1675 a_hat(i,k+1,j) =a_hat(i,k+1,j) +a_Tmpv1
1688 ! DO i =i_start, min(ite, ide-1)
1689 ! hat(i,k,j) =w(i,k,j)/msftx(i,j)
1693 DO i =min(ite, ide-1), i_start, -1
1694 a_w(i,k,j) =a_w(i,k,j) +1.0/msftx(i,j)*a_hat(i,k,j)
1708 DO j =min(jte, jde-1), j_start, -1
1711 ! hat(i,k,j) =w(i,k,j)/msftx(i,j)
1716 a_w(i,k,j) =a_w(i,k,j) +1.0/msftx(i,j)*a_hat(i,k,j)
1726 DO j =j_end, j_start, -1
1729 ! DO i =i_start, i_end
1730 ! hat(i,k,j) =w(i,k,j)/msftx(i,j)
1736 DO i =i_end, i_start, -1
1737 a_w(i,k,j) =a_w(i,k,j) +1.0/msftx(i,j)*a_hat(i,k,j)
1744 !BIG ERRORS, REVISED BY WALLS
1745 ! hat =Keep_Lpb54_hat ! Remarked by Ning Pan, 2010-08-31
1748 ! Remarked by Ning Pan, 2010-08-31
1749 ! DO j =jte, jts, -1
1752 !! mm(i,j) =msfvx(i,j)*msfvy(i,j)
1756 ! DO i =ite, its, -1
1762 !BIG ERRORS, REVISED BY WALLS
1767 ! IF( config_flags%periodic_x ) THEN
1768 ! i_end =min(ite, ide-1)
1771 ! IF( config_flags%periodic_x ) THEN
1779 ! IF( config_flags%periodic_x ) THEN
1783 ! IF( config_flags%periodic_x ) THEN
1791 ! IF( config_flags%periodic_y ) THEN
1792 ! j_end =min(jte, jde)
1795 ! IF( config_flags%periodic_y ) THEN
1803 ! IF( config_flags%open_ys .OR. config_flags%specified .OR. config_flags%nested) THEN
1804 ! j_start =max(jds+1, jts)
1807 ! IF( config_flags%open_ys .OR. config_flags%specified .OR. &
1808 ! config_flags%nested) THEN
1816 ! IF( config_flags%open_xs .OR. config_flags%specified .OR. config_flags%nested) THEN
1817 ! i_start =max(ids+1, its)
1820 ! IF( config_flags%open_xs .OR. config_flags%specified .OR. &
1821 ! config_flags%nested) THEN
1827 ! i_end =min(ite, ide-1)
1829 ! j_end =min(jte, jde-1)
1835 i_end = MIN( ite, ide-1 )
1837 j_end = MIN( jte, jde-1 )
1840 IF ( config_flags%open_xs .OR. config_flags%specified .OR. &
1841 config_flags%nested) i_start = MAX( ids+1, its )
1846 IF ( config_flags%open_ys .OR. config_flags%specified .OR. &
1847 config_flags%nested) j_start = MAX( jds+1, jts )
1852 IF ( config_flags%periodic_x ) i_start = its
1857 IF ( config_flags%periodic_x ) i_end = MIN( ite, ide )
1862 IF ( config_flags%periodic_y ) j_end = MIN( jte, jde )
1866 ! IF( config_flags%sfs_opt .GT. 0 ) THEN
1867 ! DO j =j_start, j_end
1869 ! DO i =i_start, i_end
1870 ! Tmpv001 =tmp1(i,k,j) -defor13(i,k,j)
1871 ! nba_rij(i,k,j,P_r13) =Tmpv001
1873 ! Tmpv001 =defor13(i,k,j) +tmp1(i,k,j)
1874 ! defor13(i,k,j) =Tmpv001
1879 ! DO j =j_start, j_end
1880 ! DO i =i_start, i_end
1881 ! nba_rij(i,kts,j,P_r13) =0.0
1883 ! nba_rij(i,ktf+1,j,P_r13) =0.0
1888 ! DO j =j_start, j_end
1890 ! DO i =i_start, i_end
1891 ! Tmpv001 =defor13(i,k,j) +tmp1(i,k,j)
1892 ! defor13(i,k,j) =Tmpv001
1899 IF( config_flags%sfs_opt .GT. 0 ) THEN
1901 DO j =j_end, j_start, -1
1902 DO i =i_end, i_start, -1
1903 a_nba_rij(i,ktf+1,j,P_r13) =0.0
1904 a_nba_rij(i,kts,j,P_r13) =0.0
1907 DO j =j_end, j_start, -1
1908 DO k =ktf, kts+1, -1
1909 DO i =i_end, i_start, -1
1910 a_Tmpv1 =a_defor13(i,k,j)
1911 a_defor13(i,k,j) =0.0
1912 a_defor13(i,k,j) =a_defor13(i,k,j) +a_Tmpv1
1913 a_tmp1(i,k,j) =a_tmp1(i,k,j) +a_Tmpv1
1914 a_Tmpv1 =a_nba_rij(i,k,j,P_r13)
1915 a_nba_rij(i,k,j,P_r13) =0.0
1916 a_tmp1(i,k,j) =a_tmp1(i,k,j) +a_Tmpv1
1917 a_defor13(i,k,j) =a_defor13(i,k,j) -a_Tmpv1
1924 DO j =j_end, j_start, -1
1925 DO k =ktf, kts+1, -1
1926 DO i =i_end, i_start, -1
1927 a_Tmpv1 =a_defor13(i,k,j)
1928 a_defor13(i,k,j) =0.0
1929 a_defor13(i,k,j) =a_defor13(i,k,j) +a_Tmpv1
1930 a_tmp1(i,k,j) =a_tmp1(i,k,j) +a_Tmpv1
1941 IF( config_flags%mix_full_fields ) THEN
1942 DO j =j_start, j_end
1944 DO i =i_start, i_end
1945 Tmpv001 =u(i,k,j) -u(i,k-1,j)
1946 Tmpv002 =Tmpv001*0.5
1947 Tmpv003 =rdz(i,k,j) +rdz(i-1,k,j)
1948 Tmpv400(i,k,j) =Tmpv002
1949 Tmpv401(i,k,j) =Tmpv003
1950 ! Remarked by Ning Pan, 2010-08-31
1951 ! Tmpv004 =Tmpv400(i,k,j)*Tmpv401(i,k,j)
1952 ! tmp1(i,k,j) =Tmpv004
1958 DO j =j_start, j_end
1960 DO i =i_start, i_end
1961 Tmpv001 =u(i,k,j) -u_base(k) -u(i,k-1,j)
1962 Tmpv002 =Tmpv001 +u_base(k-1)
1963 Tmpv003 =Tmpv002*0.5
1964 Tmpv004 =rdz(i,k,j) +rdz(i-1,k,j)
1965 Tmpv402(i,k,j) =Tmpv003
1966 Tmpv403(i,k,j) =Tmpv004
1967 ! Remarked by Ning Pan, 2010-08-31
1968 ! Tmpv005 =Tmpv402(i,k,j)*Tmpv403(i,k,j)
1969 ! tmp1(i,k,j) =Tmpv005
1976 IF( config_flags%mix_full_fields ) THEN
1978 DO j =j_end, j_start, -1
1979 DO k =ktf, kts+1, -1
1980 DO i =i_end, i_start, -1
1981 a_Tmpv4 =a_tmp1(i,k,j)
1983 a_Tmpv2 =Tmpv401(i,k,j)*a_Tmpv4
1984 a_Tmpv3 =Tmpv400(i,k,j)*a_Tmpv4
1985 a_rdz(i,k,j) =a_rdz(i,k,j) +a_Tmpv3
1986 a_rdz(i-1,k,j) =a_rdz(i-1,k,j) +a_Tmpv3
1987 a_Tmpv1 =0.5*a_Tmpv2
1988 a_u(i,k,j) =a_u(i,k,j) +a_Tmpv1
1989 a_u(i,k-1,j) =a_u(i,k-1,j) -a_Tmpv1
1996 DO j =j_end, j_start, -1
1997 DO k =ktf, kts+1, -1
1998 DO i =i_end, i_start, -1
1999 a_Tmpv5 =a_tmp1(i,k,j)
2001 a_Tmpv3 =Tmpv403(i,k,j)*a_Tmpv5
2002 a_Tmpv4 =Tmpv402(i,k,j)*a_Tmpv5
2003 a_rdz(i,k,j) =a_rdz(i,k,j) +a_Tmpv4
2004 a_rdz(i-1,k,j) =a_rdz(i-1,k,j) +a_Tmpv4
2005 a_Tmpv2 =0.5*a_Tmpv3
2007 a_u(i,k,j) =a_u(i,k,j) +a_Tmpv1
2008 a_u(i,k-1,j) =a_u(i,k-1,j) -a_Tmpv1
2018 DO j =j_end, j_start, -1
2020 ! DO i =i_start, i_end
2021 ! defor13(i,kts,j) =0.0
2023 ! defor13(i,ktf+1,j) =0.0
2027 DO i =i_end, i_start, -1
2028 a_defor13(i,ktf+1,j) =0.0
2029 a_defor13(i,kts,j) =0.0
2035 DO j =j_end, j_start, -1
2037 ! Remarked by Ning Pan, 2010-08-31
2039 ! DO i =i_start, i_end
2040 ! Tmpv001 =hat(i,k,j) -hat(i-1,k,j)
2041 ! Tmpv002 =rdx*Tmpv001
2042 ! Tmpv003 =Tmpv002 -tmp1(i,k,j)
2043 ! Tmpv300(i,k) =Tmpv003
2044 ! Tmpv004 =mm(i,j)*Tmpv300(i,k)
2045 ! defor13(i,k,j) =Tmpv004
2050 DO k =ktf, kts+1, -1
2051 DO i =i_end, i_start, -1
2052 a_Tmpv4 =a_defor13(i,k,j)
2053 a_defor13(i,k,j) =0.0
2054 ! a_mm(i,j) =a_mm(i,j) +Tmpv300(i,k)*a_Tmpv4 ! Remarked by Ning Pan, 2010-08-31
2055 a_Tmpv3 =mm(i,j)*a_Tmpv4
2057 a_tmp1(i,k,j) =a_tmp1(i,k,j) -a_Tmpv3
2058 a_Tmpv1 =rdx*a_Tmpv2
2059 a_hat(i,k,j) =a_hat(i,k,j) +a_Tmpv1
2060 a_hat(i-1,k,j) =a_hat(i-1,k,j) -a_Tmpv1
2067 DO j =j_end, j_start, -1
2070 DO i =i_start, i_end
2071 !BIG ERRORS, ADDED BY WALLS
2072 !BIG ERRORS, ADDED BY WALLS
2073 ! Tmpv001 =hatavg(i,k,j) -hatavg(i,k-1,j)
2074 Tmpv001 =Keep_Lpb60_hatavg(i,k,j)
2076 Tmpv300(i,k) =Tmpv001
2077 Tmpv002 =Tmpv300(i,k)*zx(i,k,j)
2078 Tmpv003 =Tmpv002*0.5
2079 Tmpv004 =rdz(i,k,j) +rdz(i-1,k,j)
2080 Tmpv301(i,k) =Tmpv003
2081 Tmpv302(i,k) =Tmpv004
2082 ! Remarked by Ning Pan, 2010-08-31
2083 ! Tmpv005 =Tmpv301(i,k)*Tmpv302(i,k)
2084 ! tmp1(i,k,j) =Tmpv005
2089 DO k =ktf, kts+1, -1
2090 DO i =i_end, i_start, -1
2091 a_Tmpv5 =a_tmp1(i,k,j)
2093 a_Tmpv3 =Tmpv302(i,k)*a_Tmpv5
2094 a_Tmpv4 =Tmpv301(i,k)*a_Tmpv5
2095 a_rdz(i,k,j) =a_rdz(i,k,j) +a_Tmpv4
2096 a_rdz(i-1,k,j) =a_rdz(i-1,k,j) +a_Tmpv4
2097 a_Tmpv2 =0.5*a_Tmpv3
2098 a_Tmpv1 =zx(i,k,j)*a_Tmpv2
2099 a_zx(i,k,j) =a_zx(i,k,j) +Tmpv300(i,k)*a_Tmpv2
2100 a_hatavg(i,k,j) =a_hatavg(i,k,j) +a_Tmpv1
2101 a_hatavg(i,k-1,j) =a_hatavg(i,k-1,j) -a_Tmpv1
2107 !BIG ERRORS, ADDED BY WALLS
2108 ! tmp1 =Keep_Lpb40_tmp1 ! Remarked by Ning Pan, 2010-08-31
2111 DO j =j_end, j_start, -1
2114 ! DO i =i_start, i_end
2115 ! Tmpv001 =hat(i,k,j) +hat(i,k+1,j)
2116 ! Tmpv002 =Tmpv001 +hat(i-1,k,j)
2117 ! Tmpv003 =Tmpv002 +hat(i-1,k+1,j)
2118 ! Tmpv004 =0.25*Tmpv003
2119 ! hatavg(i,k,j) =Tmpv004
2125 DO i =i_end, i_start, -1
2126 a_Tmpv4 =a_hatavg(i,k,j)
2127 a_hatavg(i,k,j) =0.0
2128 a_Tmpv3 =0.25*a_Tmpv4
2130 a_hat(i-1,k+1,j) =a_hat(i-1,k+1,j) +a_Tmpv3
2132 a_hat(i-1,k,j) =a_hat(i-1,k,j) +a_Tmpv2
2133 a_hat(i,k,j) =a_hat(i,k,j) +a_Tmpv1
2134 a_hat(i,k+1,j) =a_hat(i,k+1,j) +a_Tmpv1
2147 ! DO i =i_start, min(ite, ide-1)
2148 ! hat(i,k,j) =w(i,k,j)/msfty(i,j)
2152 DO i =min(ite, ide-1), i_start, -1
2153 a_w(i,k,j) =a_w(i,k,j) +1.0/msfty(i,j)*a_hat(i,k,j)
2167 DO j =min(jte, jde-1), j_start, -1
2170 ! hat(i,k,j) =w(i,k,j)/msfty(i,j)
2175 a_w(i,k,j) =a_w(i,k,j) +1.0/msfty(i,j)*a_hat(i,k,j)
2185 DO j =j_end, j_start, -1
2188 ! DO i =i_start, i_end
2189 ! hat(i,k,j) =w(i,k,j)/msfty(i,j)
2195 DO i =i_end, i_start, -1
2196 a_w(i,k,j) =a_w(i,k,j) +1.0/msfty(i,j)*a_hat(i,k,j)
2203 !BIG ERRORS, REVISED BY WALLS
2204 ! hat =Keep_Lpb37_hat ! Remarked by Ning Pan, 2010-08-31
2207 ! Remarked by Ning Pan, 2010-08-31
2208 ! DO j =jte, jts, -1
2211 !! mm(i,j) =msfux(i,j)*msfuy(i,j)
2215 ! DO i =ite, its, -1
2221 !BIG ERRORS, REVISED BY WALLS
2226 ! IF( config_flags%periodic_y ) THEN
2227 ! j_end =min(jte, jde)
2230 ! IF( config_flags%periodic_y ) THEN
2238 ! IF( config_flags%periodic_x ) THEN
2239 ! i_end =min(ite, ide)
2242 ! IF( config_flags%periodic_x ) THEN
2250 ! IF( config_flags%periodic_x ) THEN
2254 ! IF( config_flags%periodic_x ) THEN
2262 ! IF( config_flags%open_ys .OR. config_flags%specified .OR. config_flags%nested) THEN
2263 ! j_start =max(jds+1, jts)
2266 ! IF( config_flags%open_ys .OR. config_flags%specified .OR. &
2267 ! config_flags%nested) THEN
2275 ! IF( config_flags%open_xs .OR. config_flags%specified .OR. config_flags%nested) THEN
2276 ! i_start =max(ids+1, its)
2279 ! IF( config_flags%open_xs .OR. config_flags%specified .OR. &
2280 ! config_flags%nested) THEN
2286 ! i_end =min(ite, ide-1)
2288 ! j_end =min(jte, jde-1)
2298 IF ( config_flags%open_xs .OR. config_flags%specified .OR. &
2299 config_flags%nested) i_start = MAX( ids+1, its )
2304 IF ( config_flags%open_xe .OR. config_flags%specified .OR. &
2305 config_flags%nested) i_end = MIN( ide-1, ite )
2310 IF ( config_flags%open_ys .OR. config_flags%specified .OR. &
2311 config_flags%nested) j_start = MAX( jds+1, jts )
2316 IF ( config_flags%open_ye .OR. config_flags%specified .OR. &
2317 config_flags%nested) j_end = MIN( jde-1, jte )
2322 IF ( config_flags%periodic_x ) i_start = its
2327 IF ( config_flags%periodic_x ) i_end = ite
2331 IF( config_flags%sfs_opt .GT. 0 ) THEN
2332 DO j =j_start, j_end
2334 DO i =i_start, i_end
2335 Tmpv001 =hat(i,k,j) -hat(i-1,k,j)
2336 Tmpv002 =rdx*Tmpv001
2337 Tmpv003 =Tmpv002 -tmp1(i,k,j)
2338 Tmpv400(i,k,j) =Tmpv003
2339 ! Remarked by Ning Pan, 2010-08-31
2340 ! Tmpv004 =mm(i,j)*Tmpv400(i,k,j)
2341 ! Tmpv005 =defor12(i,k,j) -Tmpv004
2342 ! nba_rij(i,k,j,P_r12) =Tmpv005
2344 Tmpv001 =hat(i,k,j) -hat(i-1,k,j)
2345 Tmpv002 =rdx*Tmpv001
2346 Tmpv003 =Tmpv002 -tmp1(i,k,j)
2347 Tmpv401(i,k,j) =Tmpv003
2348 ! Remarked by Ning Pan, 2010-08-31
2349 ! Tmpv004 =mm(i,j)*Tmpv401(i,k,j)
2350 ! Tmpv005 =defor12(i,k,j) +Tmpv004
2351 ! defor12(i,k,j) =Tmpv005
2356 ! Remarked by Ning Pan, 2010-08-31
2357 ! IF( .NOT. config_flags%periodic_x .AND. i_start .EQ. ids+1 ) THEN
2360 ! defor12(ids,k,j) =defor12(ids+1,k,j)
2362 ! nba_rij(ids,k,j,P_r12) =nba_rij(ids+1,k,j,P_r12)
2367 ! IF( .NOT. config_flags%periodic_y .AND. j_start .EQ. jds+1) THEN
2370 ! defor12(i,k,jds) =defor12(i,k,jds+1)
2372 ! nba_rij(i,k,jds,P_r12) =nba_rij(i,k,jds+1,P_r12)
2377 ! IF( .NOT. config_flags%periodic_x .AND. i_end .EQ. ide-1) THEN
2380 ! defor12(ide,k,j) =defor12(ide-1,k,j)
2382 ! nba_rij(ide,k,j,P_r12) =nba_rij(ide-1,k,j,P_r12)
2387 ! IF( .NOT. config_flags%periodic_y .AND. j_end .EQ. jde-1) THEN
2390 ! defor12(i,k,jde) =defor12(i,k,jde-1)
2392 ! nba_rij(i,k,jde,P_r12) =nba_rij(i,k,jde-1,P_r12)
2398 ! DO j =j_start, j_end
2400 ! DO i =i_start, i_end
2401 ! Tmpv001 =hat(i,k,j) -hat(i-1,k,j)
2402 ! Tmpv002 =rdx*Tmpv001
2403 ! Tmpv003 =Tmpv002 -tmp1(i,k,j)
2404 ! Tmpv402(i,k,j) =Tmpv003
2405 ! Tmpv004 =mm(i,j)*Tmpv402(i,k,j)
2406 ! Tmpv005 =defor12(i,k,j) +Tmpv004
2407 ! defor12(i,k,j) =Tmpv005
2412 ! IF( .NOT. config_flags%periodic_x .AND. i_start .EQ. ids+1 ) THEN
2415 ! defor12(ids,k,j) =defor12(ids+1,k,j)
2420 ! IF( .NOT. config_flags%periodic_y .AND. j_start .EQ. jds+1) THEN
2423 ! defor12(i,k,jds) =defor12(i,k,jds+1)
2428 ! IF( .NOT. config_flags%periodic_x .AND. i_end .EQ. ide-1) THEN
2431 ! defor12(ide,k,j) =defor12(ide-1,k,j)
2436 ! IF( .NOT. config_flags%periodic_y .AND. j_end .EQ. jde-1) THEN
2439 ! defor12(i,k,jde) =defor12(i,k,jde-1)
2446 IF( config_flags%sfs_opt .GT. 0 ) THEN
2448 IF( .NOT. config_flags%periodic_y .AND. j_end .EQ. jde-1) THEN
2452 a_nba_rij(i,k,jde-1,P_r12) =a_nba_rij(i,k,jde-1,P_r12) +a_nba_rij(i,k,jde,P_r12)
2453 a_nba_rij(i,k,jde,P_r12) =0.0
2454 a_defor12(i,k,jde-1) =a_defor12(i,k,jde-1) +a_defor12(i,k,jde)
2455 a_defor12(i,k,jde) =0.0
2461 IF( .NOT. config_flags%periodic_x .AND. i_end .EQ. ide-1) THEN
2465 a_nba_rij(ide-1,k,j,P_r12) =a_nba_rij(ide-1,k,j,P_r12) +a_nba_rij(ide,k,j,P_r12)
2466 a_nba_rij(ide,k,j,P_r12) =0.0
2467 a_defor12(ide-1,k,j) =a_defor12(ide-1,k,j) +a_defor12(ide,k,j)
2468 a_defor12(ide,k,j) =0.0
2474 IF( .NOT. config_flags%periodic_y .AND. j_start .EQ. jds+1) THEN
2478 a_nba_rij(i,k,jds+1,P_r12) =a_nba_rij(i,k,jds+1,P_r12) +a_nba_rij(i,k,jds,P_r12)
2479 a_nba_rij(i,k,jds,P_r12) =0.0
2480 a_defor12(i,k,jds+1) =a_defor12(i,k,jds+1) +a_defor12(i,k,jds)
2481 a_defor12(i,k,jds) =0.0
2487 IF( .NOT. config_flags%periodic_x .AND. i_start .EQ. ids+1 ) THEN
2491 a_nba_rij(ids+1,k,j,P_r12) =a_nba_rij(ids+1,k,j,P_r12) +a_nba_rij(ids,k,j,P_r12)
2492 a_nba_rij(ids,k,j,P_r12) =0.0
2493 a_defor12(ids+1,k,j) =a_defor12(ids+1,k,j) +a_defor12(ids,k,j)
2494 a_defor12(ids,k,j) =0.0
2499 DO j =j_end, j_start, -1
2501 DO i =i_end, i_start, -1
2502 a_Tmpv5 =a_defor12(i,k,j)
2503 a_defor12(i,k,j) =0.0
2504 a_defor12(i,k,j) =a_defor12(i,k,j) +a_Tmpv5
2506 ! a_mm(i,j) =a_mm(i,j) +Tmpv401(i,k,j)*a_Tmpv4 ! Remarked by Ning Pan, 2010-08-31
2507 a_Tmpv3 =mm(i,j)*a_Tmpv4
2509 a_tmp1(i,k,j) =a_tmp1(i,k,j) -a_Tmpv3
2510 a_Tmpv1 =rdx*a_Tmpv2
2511 a_hat(i,k,j) =a_hat(i,k,j) +a_Tmpv1
2512 a_hat(i-1,k,j) =a_hat(i-1,k,j) -a_Tmpv1
2513 a_Tmpv5 =a_nba_rij(i,k,j,P_r12)
2514 a_nba_rij(i,k,j,P_r12) =0.0
2515 a_defor12(i,k,j) =a_defor12(i,k,j) +a_Tmpv5
2517 ! a_mm(i,j) =a_mm(i,j) +Tmpv400(i,k,j)*a_Tmpv4 ! Remarked by Ning Pan, 2010-08-31
2518 a_Tmpv3 =mm(i,j)*a_Tmpv4
2520 a_tmp1(i,k,j) =a_tmp1(i,k,j) -a_Tmpv3
2521 a_Tmpv1 =rdx*a_Tmpv2
2522 a_hat(i,k,j) =a_hat(i,k,j) +a_Tmpv1
2523 a_hat(i-1,k,j) =a_hat(i-1,k,j) -a_Tmpv1
2530 IF( .NOT. config_flags%periodic_y .AND. j_end .EQ. jde-1) THEN
2534 a_defor12(i,k,jde-1) =a_defor12(i,k,jde-1) +a_defor12(i,k,jde)
2535 a_defor12(i,k,jde) =0.0
2541 IF( .NOT. config_flags%periodic_x .AND. i_end .EQ. ide-1) THEN
2545 a_defor12(ide-1,k,j) =a_defor12(ide-1,k,j) +a_defor12(ide,k,j)
2546 a_defor12(ide,k,j) =0.0
2552 IF( .NOT. config_flags%periodic_y .AND. j_start .EQ. jds+1) THEN
2556 a_defor12(i,k,jds+1) =a_defor12(i,k,jds+1) +a_defor12(i,k,jds)
2557 a_defor12(i,k,jds) =0.0
2563 IF( .NOT. config_flags%periodic_x .AND. i_start .EQ. ids+1 ) THEN
2567 a_defor12(ids+1,k,j) =a_defor12(ids+1,k,j) +a_defor12(ids,k,j)
2568 a_defor12(ids,k,j) =0.0
2573 DO j =j_end, j_start, -1
2575 DO i =i_end, i_start, -1
2576 a_Tmpv5 =a_defor12(i,k,j)
2577 a_defor12(i,k,j) =0.0
2578 a_defor12(i,k,j) =a_defor12(i,k,j) +a_Tmpv5
2580 ! a_mm(i,j) =a_mm(i,j) +Tmpv402(i,k,j)*a_Tmpv4 ! Remarked by Ning Pan, 2010-08-31
2581 a_Tmpv3 =mm(i,j)*a_Tmpv4
2583 a_tmp1(i,k,j) =a_tmp1(i,k,j) -a_Tmpv3
2584 a_Tmpv1 =rdx*a_Tmpv2
2585 a_hat(i,k,j) =a_hat(i,k,j) +a_Tmpv1
2586 a_hat(i-1,k,j) =a_hat(i-1,k,j) -a_Tmpv1
2596 DO j =j_end, j_start, -1
2598 ! tmpzx =Keep_Lpb40_tmpzx(j) ! Remarked by Ning Pan, 2010-08-31
2601 DO i =i_start, i_end
2602 Tmpv001 =zx(i,k,j-1) +zx(i,k,j)
2603 Tmpv002 =Tmpv001 +zx(i,k+1,j-1)
2604 Tmpv003 =Tmpv002 +zx(i,k+1,j)
2605 Tmpv004 =0.25*Tmpv003
2609 !BIG ERRORS, ADDED BY WALLS
2610 !BIG ERRORS, ADDED BY WALLS
2611 ! Tmpv001 =hatavg(i,k+1,j) -hatavg(i,k,j)
2612 Tmpv001 =Keep_Lpb40_hatavg(i,k,j)
2613 Tmpv002 =Tmpv001*0.25
2614 Tmpv301(i,k) =Tmpv002
2615 Tmpv003 =Tmpv301(i,k)*tmpzx
2616 Tmpv004 =rdzw(i,k,j) +rdzw(i,k,j-1)
2617 Tmpv005 =Tmpv004 +rdzw(i-1,k,j-1)
2618 Tmpv006 =Tmpv005 +rdzw(i-1,k,j)
2619 Tmpv302(i,k) =Tmpv003
2620 Tmpv303(i,k) =Tmpv006
2621 ! Remarked by Ning Pan, 2010-08-31
2622 ! Tmpv007 =Tmpv302(i,k)*Tmpv303(i,k)
2623 ! tmp1(i,k,j) =Tmpv007
2629 DO i =i_end, i_start, -1
2632 a_Tmpv7 =a_tmp1(i,k,j)
2634 a_Tmpv3 =Tmpv303(i,k)*a_Tmpv7
2635 a_Tmpv6 =Tmpv302(i,k)*a_Tmpv7
2637 a_rdzw(i-1,k,j) =a_rdzw(i-1,k,j) +a_Tmpv6
2639 a_rdzw(i-1,k,j-1) =a_rdzw(i-1,k,j-1) +a_Tmpv5
2640 a_rdzw(i,k,j) =a_rdzw(i,k,j) +a_Tmpv4
2641 a_rdzw(i,k,j-1) =a_rdzw(i,k,j-1) +a_Tmpv4
2642 a_Tmpv2 =tmpzx*a_Tmpv3
2643 a_tmpzx =a_tmpzx +Tmpv301(i,k)*a_Tmpv3
2644 a_Tmpv1 =0.25*a_Tmpv2
2645 a_hatavg(i,k+1,j) =a_hatavg(i,k+1,j) +a_Tmpv1
2646 a_hatavg(i,k,j) =a_hatavg(i,k,j) -a_Tmpv1
2648 ! tmpzx =Tmpv300(i,k)
2652 a_Tmpv3 =0.25*a_Tmpv4
2654 a_zx(i,k+1,j) =a_zx(i,k+1,j) +a_Tmpv3
2656 a_zx(i,k+1,j-1) =a_zx(i,k+1,j-1) +a_Tmpv2
2657 a_zx(i,k,j-1) =a_zx(i,k,j-1) +a_Tmpv1
2658 a_zx(i,k,j) =a_zx(i,k,j) +a_Tmpv1
2665 !BIG ERRORS, ADDED BY WALLS
2666 ! tmp1 =Keep_Lpb35_tmp1 ! Remarked by Ning Pan, 2010-08-31
2669 DO j =j_end, j_start, -1
2671 ! Remarked by Ning Pan, 2010-08-31
2672 ! DO i =i_start, i_end
2673 ! Tmpv001 =cf1*hat(i-1,1,j) +cf2*hat(i-1,2,j)
2674 ! Tmpv002 =Tmpv001 +cf3*hat(i-1,3,j)
2675 ! Tmpv003 =Tmpv002 +cf1*hat(i,1,j)
2676 ! Tmpv004 =Tmpv003 +cf2*hat(i,2,j)
2677 ! Tmpv005 =Tmpv004 +cf3*hat(i,3,j)
2678 ! Tmpv006 =0.5*Tmpv005
2679 ! hatavg(i,1,j) =Tmpv006
2681 ! Tmpv001 =hat(i,ktes1,j) +hat(i-1,ktes1,j)
2682 ! Tmpv200(i) =Tmpv001
2683 ! Tmpv002 =cft1*Tmpv200(i)
2684 ! Tmpv003 =hat(i,ktes2,j) +hat(i-1,ktes2,j)
2685 ! Tmpv201(i) =Tmpv003
2686 ! Tmpv004 =cft2*Tmpv201(i)
2687 ! Tmpv005 =Tmpv002 +Tmpv004
2688 ! Tmpv006 =0.5*Tmpv005
2689 ! hatavg(i,kte,j) =Tmpv006
2693 DO i =i_end, i_start, -1
2694 a_Tmpv6 =a_hatavg(i,kte,j)
2695 a_hatavg(i,kte,j) =0.0
2696 a_Tmpv5 =0.5*a_Tmpv6
2699 ! a_cft2 =a_cft2 +Tmpv201(i)*a_Tmpv4 ! Remarked by Ning Pan, 2010-08-31
2700 a_Tmpv3 =cft2*a_Tmpv4
2701 a_hat(i,ktes2,j) =a_hat(i,ktes2,j) +a_Tmpv3
2702 a_hat(i-1,ktes2,j) =a_hat(i-1,ktes2,j) +a_Tmpv3
2703 ! a_cft1 =a_cft1 +Tmpv200(i)*a_Tmpv2 ! Remarked by Ning Pan, 2010-08-31
2704 a_Tmpv1 =cft1*a_Tmpv2
2705 a_hat(i,ktes1,j) =a_hat(i,ktes1,j) +a_Tmpv1
2706 a_hat(i-1,ktes1,j) =a_hat(i-1,ktes1,j) +a_Tmpv1
2707 a_Tmpv6 =a_hatavg(i,1,j)
2708 a_hatavg(i,1,j) =0.0
2709 a_Tmpv5 =0.5*a_Tmpv6
2711 a_hat(i,3,j) =a_hat(i,3,j) +cf3*a_Tmpv5
2713 a_hat(i,2,j) =a_hat(i,2,j) +cf2*a_Tmpv4
2715 a_hat(i,1,j) =a_hat(i,1,j) +cf1*a_Tmpv3
2717 a_hat(i-1,3,j) =a_hat(i-1,3,j) +cf3*a_Tmpv2
2718 a_hat(i-1,1,j) =a_hat(i-1,1,j) +cf1*a_Tmpv1
2719 a_hat(i-1,2,j) =a_hat(i-1,2,j) +cf2*a_Tmpv1
2725 DO j =j_end, j_start, -1
2728 ! DO i =i_start, i_end
2729 ! Tmpv001 =hat(i-1,k,j) +hat(i,k,j)
2730 ! Tmpv002 =fnm(k)*Tmpv001
2731 ! Tmpv003 =hat(i-1,k-1,j) +hat(i,k-1,j)
2732 ! Tmpv004 =fnp(k)*Tmpv003
2733 ! Tmpv005 =Tmpv002 +Tmpv004
2734 ! Tmpv006 =0.5*Tmpv005
2735 ! hatavg(i,k,j) =Tmpv006
2740 DO k =ktf, kts+1, -1
2741 DO i =i_end, i_start, -1
2742 a_Tmpv6 =a_hatavg(i,k,j)
2743 a_hatavg(i,k,j) =0.0
2744 a_Tmpv5 =0.5*a_Tmpv6
2747 a_Tmpv3 =fnp(k)*a_Tmpv4
2748 a_hat(i-1,k-1,j) =a_hat(i-1,k-1,j) +a_Tmpv3
2749 a_hat(i,k-1,j) =a_hat(i,k-1,j) +a_Tmpv3
2750 a_Tmpv1 =fnm(k)*a_Tmpv2
2751 a_hat(i-1,k,j) =a_hat(i-1,k,j) +a_Tmpv1
2752 a_hat(i,k,j) =a_hat(i,k,j) +a_Tmpv1
2759 DO j =j_end, j_start, -1
2762 ! DO i =i_start-1, i_end
2763 ! hat(i,k,j) =v(i,k,j)/msfvy(i,j)
2769 DO i =i_end, i_start-1, -1
2770 a_v(i,k,j) =a_v(i,k,j) +1.0/msfvy(i,j)*a_hat(i,k,j)
2777 !BIG ERRORS, REVISED BY WALLS
2778 ! hat =Keep_Lpb32_hat ! Remarked by Ning Pan, 2010-08-31
2781 DO j =j_end, j_start, -1
2783 ! Remarked by Ning Pan, 2010-08-31
2785 ! DO i =i_start, i_end
2786 ! Tmpv001 =hat(i,k,j) -hat(i,k,j-1)
2787 ! Tmpv002 =rdy*Tmpv001
2788 ! Tmpv003 =Tmpv002 -tmp1(i,k,j)
2789 ! Tmpv300(i,k) =Tmpv003
2790 ! Tmpv004 =mm(i,j)*Tmpv300(i,k)
2791 ! defor12(i,k,j) =Tmpv004
2797 DO i =i_end, i_start, -1
2798 a_Tmpv4 =a_defor12(i,k,j)
2799 a_defor12(i,k,j) =0.0
2800 ! a_mm(i,j) =a_mm(i,j) +Tmpv300(i,k)*a_Tmpv4 ! Remarked by Ning Pan, 2010-08-31
2801 a_Tmpv3 =mm(i,j)*a_Tmpv4
2803 a_tmp1(i,k,j) =a_tmp1(i,k,j) -a_Tmpv3
2804 a_Tmpv1 =rdy*a_Tmpv2
2805 a_hat(i,k,j) =a_hat(i,k,j) +a_Tmpv1
2806 a_hat(i,k,j-1) =a_hat(i,k,j-1) -a_Tmpv1
2813 DO j =j_end, j_start, -1
2815 ! tmpzy =Keep_Lpb35_tmpzy(j) ! Remarked by Ning Pan, 2010-08-31
2818 DO i =i_start, i_end
2819 Tmpv001 =zy(i-1,k,j) +zy(i,k,j)
2820 Tmpv002 =Tmpv001 +zy(i-1,k+1,j)
2821 Tmpv003 =Tmpv002 +zy(i,k+1,j)
2822 Tmpv004 =0.25*Tmpv003
2826 !BIG ERRORS, ADDED BY WALLS
2827 !BIG ERRORS, ADDED BY WALLS
2828 ! Tmpv001 =hatavg(i,k+1,j) -hatavg(i,k,j)
2829 Tmpv001 =Keep_Lpb35_hatavg(i,k,j)
2830 Tmpv002 =Tmpv001*0.25
2831 Tmpv301(i,k) =Tmpv002
2832 Tmpv003 =Tmpv301(i,k)*tmpzy
2833 Tmpv004 =rdzw(i,k,j) +rdzw(i-1,k,j)
2834 Tmpv005 =Tmpv004 +rdzw(i-1,k,j-1)
2835 Tmpv006 =Tmpv005 +rdzw(i,k,j-1)
2836 Tmpv302(i,k) =Tmpv003
2837 Tmpv303(i,k) =Tmpv006
2838 ! Remarked by Ning Pan, 2010-08-31
2839 ! Tmpv007 =Tmpv302(i,k)*Tmpv303(i,k)
2840 ! tmp1(i,k,j) =Tmpv007
2846 DO i =i_end, i_start, -1
2849 a_Tmpv7 =a_tmp1(i,k,j)
2851 a_Tmpv3 =Tmpv303(i,k)*a_Tmpv7
2852 a_Tmpv6 =Tmpv302(i,k)*a_Tmpv7
2854 a_rdzw(i,k,j-1) =a_rdzw(i,k,j-1) +a_Tmpv6
2856 a_rdzw(i-1,k,j-1) =a_rdzw(i-1,k,j-1) +a_Tmpv5
2857 a_rdzw(i,k,j) =a_rdzw(i,k,j) +a_Tmpv4
2858 a_rdzw(i-1,k,j) =a_rdzw(i-1,k,j) +a_Tmpv4
2859 a_Tmpv2 =tmpzy*a_Tmpv3
2860 a_tmpzy =a_tmpzy +Tmpv301(i,k)*a_Tmpv3
2861 a_Tmpv1 =0.25*a_Tmpv2
2862 a_hatavg(i,k+1,j) =a_hatavg(i,k+1,j) +a_Tmpv1
2863 a_hatavg(i,k,j) =a_hatavg(i,k,j) -a_Tmpv1
2865 ! tmpzy =Tmpv300(i,k)
2869 a_Tmpv3 =0.25*a_Tmpv4
2871 a_zy(i,k+1,j) =a_zy(i,k+1,j) +a_Tmpv3
2873 a_zy(i-1,k+1,j) =a_zy(i-1,k+1,j) +a_Tmpv2
2874 a_zy(i-1,k,j) =a_zy(i-1,k,j) +a_Tmpv1
2875 a_zy(i,k,j) =a_zy(i,k,j) +a_Tmpv1
2883 DO j =j_end, j_start, -1
2885 ! Remarked by Ning Pan, 2010-08-31
2886 ! DO i =i_start, i_end
2887 ! Tmpv001 =cf1*hat(i,1,j-1) +cf2*hat(i,2,j-1)
2888 ! Tmpv002 =Tmpv001 +cf3*hat(i,3,j-1)
2889 ! Tmpv003 =Tmpv002 +cf1*hat(i,1,j)
2890 ! Tmpv004 =Tmpv003 +cf2*hat(i,2,j)
2891 ! Tmpv005 =Tmpv004 +cf3*hat(i,3,j)
2892 ! Tmpv006 =0.5*Tmpv005
2893 ! hatavg(i,1,j) =Tmpv006
2895 ! Tmpv001 =hat(i,ktes1,j-1) +hat(i,ktes1,j)
2896 ! Tmpv200(i) =Tmpv001
2897 ! Tmpv002 =cft1*Tmpv200(i)
2898 ! Tmpv003 =hat(i,ktes2,j-1) +hat(i,ktes2,j)
2899 ! Tmpv201(i) =Tmpv003
2900 ! Tmpv004 =cft2*Tmpv201(i)
2901 ! Tmpv005 =Tmpv002 +Tmpv004
2902 ! Tmpv006 =0.5*Tmpv005
2903 ! hatavg(i,kte,j) =Tmpv006
2907 DO i =i_end, i_start, -1
2908 a_Tmpv6 =a_hatavg(i,kte,j)
2909 a_hatavg(i,kte,j) =0.0
2910 a_Tmpv5 =0.5*a_Tmpv6
2913 ! a_cft2 =a_cft2 +Tmpv201(i)*a_Tmpv4 ! Remarked by Ning Pan, 2010-08-31
2914 a_Tmpv3 =cft2*a_Tmpv4
2915 a_hat(i,ktes2,j-1) =a_hat(i,ktes2,j-1) +a_Tmpv3
2916 a_hat(i,ktes2,j) =a_hat(i,ktes2,j) +a_Tmpv3
2917 ! a_cft1 =a_cft1 +Tmpv200(i)*a_Tmpv2 ! Remarked by Ning Pan, 2010-08-31
2918 a_Tmpv1 =cft1*a_Tmpv2
2919 a_hat(i,ktes1,j-1) =a_hat(i,ktes1,j-1) +a_Tmpv1
2920 a_hat(i,ktes1,j) =a_hat(i,ktes1,j) +a_Tmpv1
2921 a_Tmpv6 =a_hatavg(i,1,j)
2922 a_hatavg(i,1,j) =0.0
2923 a_Tmpv5 =0.5*a_Tmpv6
2925 a_hat(i,3,j) =a_hat(i,3,j) +cf3*a_Tmpv5
2927 a_hat(i,2,j) =a_hat(i,2,j) +cf2*a_Tmpv4
2929 a_hat(i,1,j) =a_hat(i,1,j) +cf1*a_Tmpv3
2931 a_hat(i,3,j-1) =a_hat(i,3,j-1) +cf3*a_Tmpv2
2932 a_hat(i,1,j-1) =a_hat(i,1,j-1) +cf1*a_Tmpv1
2933 a_hat(i,2,j-1) =a_hat(i,2,j-1) +cf2*a_Tmpv1
2939 DO j =j_end, j_start, -1
2942 ! DO i =i_start, i_end
2943 ! Tmpv001 =hat(i,k,j-1) +hat(i,k,j)
2944 ! Tmpv002 =fnm(k)*Tmpv001
2945 ! Tmpv003 =hat(i,k-1,j-1) +hat(i,k-1,j)
2946 ! Tmpv004 =fnp(k)*Tmpv003
2947 ! Tmpv005 =Tmpv002 +Tmpv004
2948 ! Tmpv006 =0.5*Tmpv005
2949 ! hatavg(i,k,j) =Tmpv006
2954 DO k =ktf, kts+1, -1
2955 DO i =i_end, i_start, -1
2956 a_Tmpv6 =a_hatavg(i,k,j)
2957 a_hatavg(i,k,j) =0.0
2958 a_Tmpv5 =0.5*a_Tmpv6
2961 a_Tmpv3 =fnp(k)*a_Tmpv4
2962 a_hat(i,k-1,j-1) =a_hat(i,k-1,j-1) +a_Tmpv3
2963 a_hat(i,k-1,j) =a_hat(i,k-1,j) +a_Tmpv3
2964 a_Tmpv1 =fnm(k)*a_Tmpv2
2965 a_hat(i,k,j-1) =a_hat(i,k,j-1) +a_Tmpv1
2966 a_hat(i,k,j) =a_hat(i,k,j) +a_Tmpv1
2973 DO j =j_end, j_start-1, -1
2976 ! DO i =i_start, i_end
2977 ! hat(i,k,j) =u(i,k,j)/msfux(i,j)
2983 DO i =i_end, i_start, -1
2984 a_u(i,k,j) =a_u(i,k,j) +1.0/msfux(i,j)*a_hat(i,k,j)
2991 !BIG ERRORS, REVISED BY WALLS
2992 ! hat =Keep_Lpb9_hat ! Remarked by Ning Pan, 2010-08-31
2995 ! Remarked by Ning Pan, 2010-08-31
2996 ! DO j =j_end, j_start, -1
2998 !! DO i =i_start, i_end
2999 !! mm(i,j) =0.25*(msfux(i,j-1)+msfux(i,j))*(msfvy(i-1,j)+msfvy(i,j))
3003 ! DO i =i_end, i_start, -1
3009 !BIG ERRORS, REVISED BY WALLS
3014 ! IF( config_flags%periodic_x ) THEN
3018 ! IF( config_flags%periodic_x ) THEN
3026 ! IF( config_flags%periodic_x ) THEN
3030 ! IF( config_flags%periodic_x ) THEN
3038 ! IF( config_flags%open_ye .OR. config_flags%specified .OR. config_flags%nested) THEN
3039 ! j_end =min(jde-1, jte)
3042 ! IF( config_flags%open_ye .OR. config_flags%specified .OR. &
3043 ! config_flags%nested) THEN
3051 ! IF( config_flags%open_ys .OR. config_flags%specified .OR. config_flags%nested) THEN
3052 ! j_start =max(jds+1, jts)
3055 ! IF( config_flags%open_ys .OR. config_flags%specified .OR. &
3056 ! config_flags%nested) THEN
3064 ! IF( config_flags%open_xe .OR. config_flags%specified .OR. config_flags%nested) THEN
3065 ! i_end =min(ide-1, ite)
3068 ! IF( config_flags%open_xe .OR. config_flags%specified .OR. &
3069 ! config_flags%nested) THEN
3077 ! IF( config_flags%open_xs .OR. config_flags%specified .OR. config_flags%nested) THEN
3078 ! i_start =max(ids+1, its)
3081 ! IF( config_flags%open_xs .OR. config_flags%specified .OR. &
3082 ! config_flags%nested) THEN
3094 ! Remarked by Ning Pan, 2010-08-31
3097 ! cft2 = - 0.5 * dnw(ktes1) / dn(ktes1)
3099 ! ktf = MIN( kte, kde-1 )
3101 i_end = MIN( ite, ide-1 )
3103 j_end = MIN( jte, jde-1 )
3106 DO j =j_end, j_start, -1
3109 ! DO i =i_start, i_end
3110 ! Tmpv001 =div(i,k,j) +tmp1(i,k,j)
3111 ! div(i,k,j) =Tmpv001
3117 DO i =i_end, i_start, -1
3118 a_Tmpv1 =a_div(i,k,j)
3120 a_div(i,k,j) =a_div(i,k,j) +a_Tmpv1
3121 a_tmp1(i,k,j) =a_tmp1(i,k,j) +a_Tmpv1
3128 DO j =j_end, j_start, -1
3131 ! DO i =i_start, i_end
3132 ! defor33(i,k,j) =2.0*tmp1(i,k,j)
3138 DO i =i_end, i_start, -1
3139 a_tmp1(i,k,j) =a_tmp1(i,k,j) +2.0*a_defor33(i,k,j)
3140 a_defor33(i,k,j) =0.0
3147 DO j =j_end, j_start, -1
3150 DO i =i_start, i_end
3151 Tmpv001 =w(i,k+1,j) -w(i,k,j)
3152 Tmpv300(i,k) =Tmpv001
3153 ! Remarked by Ning Pan, 2010-08-31
3154 ! Tmpv002 =Tmpv300(i,k)*rdzw(i,k,j)
3155 ! tmp1(i,k,j) =Tmpv002
3161 DO i =i_end, i_start, -1
3162 a_Tmpv2 =a_tmp1(i,k,j)
3164 a_Tmpv1 =rdzw(i,k,j)*a_Tmpv2
3165 a_rdzw(i,k,j) =a_rdzw(i,k,j) +Tmpv300(i,k)*a_Tmpv2
3166 a_w(i,k+1,j) =a_w(i,k+1,j) +a_Tmpv1
3167 a_w(i,k,j) =a_w(i,k,j) -a_Tmpv1
3174 DO j =j_end, j_start, -1
3177 ! DO i =i_start, i_end
3178 ! Tmpv001 =div(i,k,j) +tmp1(i,k,j)
3179 ! div(i,k,j) =Tmpv001
3185 DO i =i_end, i_start, -1
3186 a_Tmpv1 =a_div(i,k,j)
3188 a_div(i,k,j) =a_div(i,k,j) +a_Tmpv1
3189 a_tmp1(i,k,j) =a_tmp1(i,k,j) +a_Tmpv1
3196 DO j =j_end, j_start, -1
3199 ! DO i =i_start, i_end
3200 ! defor22(i,k,j) =2.0*tmp1(i,k,j)
3206 DO i =i_end, i_start, -1
3207 a_tmp1(i,k,j) =a_tmp1(i,k,j) +2.0*a_defor22(i,k,j)
3208 a_defor22(i,k,j) =0.0
3215 DO j =j_end, j_start, -1
3217 ! Remarked by Ning Pan, 2010-08-31
3218 ! DO k=kts, min(kte,kde-1)
3219 ! DO i=its, min(ite,ide-1)
3220 ! tmp1(i,k,j) =Keep_Lpb13_tmp1(i,k,j)
3225 ! DO i =i_start, i_end
3226 ! Tmpv001 =hat(i,k,j+1) -hat(i,k,j)
3227 ! Tmpv002 =rdy*Tmpv001
3228 ! Tmpv003 =Tmpv002 -tmp1(i,k,j)
3229 ! Tmpv300(i,k) =Tmpv003
3230 ! Tmpv004 =mm(i,j)*Tmpv300(i,k)
3231 ! tmp1(i,k,j) =Tmpv004
3237 DO i =i_end, i_start, -1
3238 a_Tmpv4 =a_tmp1(i,k,j)
3240 ! a_mm(i,j) =a_mm(i,j) +Tmpv300(i,k)*a_Tmpv4 ! Remarked by Ning Pan, 2010-08-31
3241 a_Tmpv3 =mm(i,j)*a_Tmpv4
3243 a_tmp1(i,k,j) =a_tmp1(i,k,j) -a_Tmpv3
3244 a_Tmpv1 =rdy*a_Tmpv2
3245 a_hat(i,k,j+1) =a_hat(i,k,j+1) +a_Tmpv1
3246 a_hat(i,k,j) =a_hat(i,k,j) -a_Tmpv1
3253 DO j =j_end, j_start, -1
3256 DO i =i_start, i_end
3258 Tmpv001 =zy(i,k,j) +zy(i,k,j+1)
3259 Tmpv002 =Tmpv001 +zy(i,k+1,j)
3260 Tmpv003 =Tmpv002 +zy(i,k+1,j+1)
3261 Tmpv004 =0.25*Tmpv003
3265 !BIG ERRORS, ADDED BY WALLS
3266 !BIG ERRORS, ADDED BY WALLS
3267 ! Tmpv001 =hatavg(i,k+1,j) -hatavg(i,k,j)
3268 Tmpv001 =Keep_Lpb12_hatavg(i,k,j)
3270 Tmpv301(i,k) =Tmpv001
3271 Tmpv002 =Tmpv301(i,k)*tmpzy
3272 Tmpv302(i,k) =Tmpv002
3273 ! Remarked by Ning Pan, 2010-08-31
3274 ! Tmpv003 =Tmpv302(i,k)*rdzw(i,k,j)
3275 ! tmp1(i,k,j) =Tmpv003
3281 DO i =i_end, i_start, -1
3285 a_Tmpv3 =a_tmp1(i,k,j)
3287 a_Tmpv2 =rdzw(i,k,j)*a_Tmpv3
3288 a_rdzw(i,k,j) =a_rdzw(i,k,j) +Tmpv302(i,k)*a_Tmpv3
3289 a_Tmpv1 =tmpzy*a_Tmpv2
3290 a_tmpzy =a_tmpzy +Tmpv301(i,k)*a_Tmpv2
3291 a_hatavg(i,k+1,j) =a_hatavg(i,k+1,j) +a_Tmpv1
3292 a_hatavg(i,k,j) =a_hatavg(i,k,j) -a_Tmpv1
3294 ! tmpzy =Tmpv300(i,k)
3298 a_Tmpv3 =0.25*a_Tmpv4
3300 a_zy(i,k+1,j+1) =a_zy(i,k+1,j+1) +a_Tmpv3
3302 a_zy(i,k+1,j) =a_zy(i,k+1,j) +a_Tmpv2
3303 a_zy(i,k,j) =a_zy(i,k,j) +a_Tmpv1
3304 a_zy(i,k,j+1) =a_zy(i,k,j+1) +a_Tmpv1
3312 DO j =j_end, j_start, -1
3314 ! Remarked by Ning Pan, 2010-08-31
3315 ! DO i =i_start, i_end
3316 ! Tmpv001 =cf1*hat(i,1,j) +cf2*hat(i,2,j)
3317 ! Tmpv002 =Tmpv001 +cf3*hat(i,3,j)
3318 ! Tmpv003 =Tmpv002 +cf1*hat(i,1,j+1)
3319 ! Tmpv004 =Tmpv003 +cf2*hat(i,2,j+1)
3320 ! Tmpv005 =Tmpv004 +cf3*hat(i,3,j+1)
3321 ! Tmpv006 =0.5*Tmpv005
3322 ! hatavg(i,1,j) =Tmpv006
3324 ! Tmpv001 =hat(i,ktes1,j) +hat(i,ktes1,j+1)
3325 ! Tmpv200(i) =Tmpv001
3326 ! Tmpv002 =cft1*Tmpv200(i)
3327 ! Tmpv003 =hat(i,ktes2,j) +hat(i,ktes2,j+1)
3328 ! Tmpv201(i) =Tmpv003
3329 ! Tmpv004 =cft2*Tmpv201(i)
3330 ! Tmpv005 =Tmpv002 +Tmpv004
3331 ! Tmpv006 =0.5*Tmpv005
3332 ! hatavg(i,kte,j) =Tmpv006
3336 DO i =i_end, i_start, -1
3337 a_Tmpv6 =a_hatavg(i,kte,j)
3338 a_hatavg(i,kte,j) =0.0
3339 a_Tmpv5 =0.5*a_Tmpv6
3342 ! a_cft2 =a_cft2 +Tmpv201(i)*a_Tmpv4 ! Remarked by Ning Pan, 2010-08-31
3343 a_Tmpv3 =cft2*a_Tmpv4
3344 a_hat(i,ktes2,j) =a_hat(i,ktes2,j) +a_Tmpv3
3345 a_hat(i,ktes2,j+1) =a_hat(i,ktes2,j+1) +a_Tmpv3
3346 ! a_cft1 =a_cft1 +Tmpv200(i)*a_Tmpv2 ! Remarked by Ning Pan, 2010-08-31
3347 a_Tmpv1 =cft1*a_Tmpv2
3348 a_hat(i,ktes1,j) =a_hat(i,ktes1,j) +a_Tmpv1
3349 a_hat(i,ktes1,j+1) =a_hat(i,ktes1,j+1) +a_Tmpv1
3350 a_Tmpv6 =a_hatavg(i,1,j)
3351 a_hatavg(i,1,j) =0.0
3352 a_Tmpv5 =0.5*a_Tmpv6
3354 a_hat(i,3,j+1) =a_hat(i,3,j+1) +cf3*a_Tmpv5
3356 a_hat(i,2,j+1) =a_hat(i,2,j+1) +cf2*a_Tmpv4
3358 a_hat(i,1,j+1) =a_hat(i,1,j+1) +cf1*a_Tmpv3
3360 a_hat(i,3,j) =a_hat(i,3,j) +cf3*a_Tmpv2
3361 a_hat(i,1,j) =a_hat(i,1,j) +cf1*a_Tmpv1
3362 a_hat(i,2,j) =a_hat(i,2,j) +cf2*a_Tmpv1
3368 DO j =j_end, j_start, -1
3371 ! DO i =i_start, i_end
3372 ! Tmpv001 =hat(i,k,j) +hat(i,k,j+1)
3373 ! Tmpv002 =fnm(k)*Tmpv001
3374 ! Tmpv003 =hat(i,k-1,j) +hat(i,k-1,j+1)
3375 ! Tmpv004 =fnp(k)*Tmpv003
3376 ! Tmpv005 =Tmpv002 +Tmpv004
3377 ! Tmpv006 =0.5*Tmpv005
3378 ! hatavg(i,k,j) =Tmpv006
3383 DO k =ktf, kts+1, -1
3384 DO i =i_end, i_start, -1
3385 a_Tmpv6 =a_hatavg(i,k,j)
3386 a_hatavg(i,k,j) =0.0
3387 a_Tmpv5 =0.5*a_Tmpv6
3390 a_Tmpv3 =fnp(k)*a_Tmpv4
3391 a_hat(i,k-1,j) =a_hat(i,k-1,j) +a_Tmpv3
3392 a_hat(i,k-1,j+1) =a_hat(i,k-1,j+1) +a_Tmpv3
3393 a_Tmpv1 =fnm(k)*a_Tmpv2
3394 a_hat(i,k,j) =a_hat(i,k,j) +a_Tmpv1
3395 a_hat(i,k,j+1) =a_hat(i,k,j+1) +a_Tmpv1
3402 DO j =j_end+1, j_start, -1
3405 ! DO i =i_start, i_end
3406 ! IF((config_flags%polar) .AND. ((j == jds) .OR. (j == jde))) THEN
3410 ! hat(i,k,j) =v(i,k,j)/msfvx(i,j)
3417 DO i =i_end, i_start, -1
3419 IF((config_flags%polar) .AND. ((j == jds) .OR. (j == jde))) THEN
3425 a_v(i,k,j) =a_v(i,k,j) +1.0/msfvx(i,j)*a_hat(i,k,j)
3434 !BIG ERRORS, REVISED BY WALLS
3435 ! hat =Keep_Lpb2_hat ! Remarked by Ning Pan, 2010-08-31
3438 DO j =j_end, j_start, -1
3441 ! DO i =i_start, i_end
3442 ! div(i,k,j) =tmp1(i,k,j)
3448 DO i =i_end, i_start, -1
3449 a_tmp1(i,k,j) =a_tmp1(i,k,j) +a_div(i,k,j)
3457 DO j =j_end, j_start, -1
3460 ! DO i =i_start, i_end
3461 ! defor11(i,k,j) =2.0*tmp1(i,k,j)
3467 DO i =i_end, i_start, -1
3468 a_tmp1(i,k,j) =a_tmp1(i,k,j) +2.0*a_defor11(i,k,j)
3469 a_defor11(i,k,j) =0.0
3476 DO j =j_end, j_start, -1
3479 ! DO k=kts, min(kte,kde-1)
3480 ! DO i=its, min(ite,ide-1)
3481 ! Remarked by Ning Pan, 2010-08-31
3483 ! DO i=i_start, i_end
3484 ! tmp1(i,k,j) =Keep_Lpb6_tmp1(i,k,j)
3489 ! DO i =i_start, i_end
3490 ! Tmpv001 =hat(i+1,k,j) -hat(i,k,j)
3491 ! Tmpv002 =rdx*Tmpv001
3492 ! Tmpv003 =Tmpv002 -tmp1(i,k,j)
3493 ! Tmpv300(i,k) =Tmpv003
3494 ! Tmpv004 =mm(i,j)*Tmpv300(i,k)
3495 ! tmp1(i,k,j) =Tmpv004
3501 DO i =i_end, i_start, -1
3502 a_Tmpv4 =a_tmp1(i,k,j)
3504 ! a_mm(i,j) =a_mm(i,j) +Tmpv300(i,k)*a_Tmpv4 ! Remarked by Ning Pan, 2010-08-31
3505 a_Tmpv3 =mm(i,j)*a_Tmpv4
3507 a_tmp1(i,k,j) =a_tmp1(i,k,j) -a_Tmpv3
3508 a_Tmpv1 =rdx*a_Tmpv2
3509 a_hat(i+1,k,j) =a_hat(i+1,k,j) +a_Tmpv1
3510 a_hat(i,k,j) =a_hat(i,k,j) -a_Tmpv1
3517 DO j =j_end, j_start, -1
3520 DO i =i_start, i_end
3522 Tmpv001 =zx(i,k,j) +zx(i+1,k,j)
3523 Tmpv002 =Tmpv001 +zx(i,k+1,j)
3524 Tmpv003 =Tmpv002 +zx(i+1,k+1,j)
3525 Tmpv004 =0.25*Tmpv003
3529 !BIG ERRORS, ADDED BY WALLS
3530 !BIG ERRORS, ADDED BY WALLS
3531 ! Tmpv001 =hatavg(i,k+1,j) -hatavg(i,k,j)
3532 Tmpv001 =Keep_Lpb5_hatavg(i,k,j)
3534 Tmpv301(i,k) =Tmpv001
3535 Tmpv002 =Tmpv301(i,k)*tmpzx
3536 Tmpv302(i,k) =Tmpv002
3537 ! Remarked by Ning Pan, 2010-08-31
3538 ! Tmpv003 =Tmpv302(i,k)*rdzw(i,k,j)
3539 ! tmp1(i,k,j) =Tmpv003
3545 DO i =i_end, i_start, -1
3548 a_Tmpv3 =a_tmp1(i,k,j)
3550 a_Tmpv2 =rdzw(i,k,j)*a_Tmpv3
3551 a_rdzw(i,k,j) =a_rdzw(i,k,j) +Tmpv302(i,k)*a_Tmpv3
3552 a_Tmpv1 =tmpzx*a_Tmpv2
3553 a_tmpzx =a_tmpzx +Tmpv301(i,k)*a_Tmpv2
3554 a_hatavg(i,k+1,j) =a_hatavg(i,k+1,j) +a_Tmpv1
3555 a_hatavg(i,k,j) =a_hatavg(i,k,j) -a_Tmpv1
3557 ! tmpzx =Tmpv300(i,k)
3561 a_Tmpv3 =0.25*a_Tmpv4
3563 a_zx(i+1,k+1,j) =a_zx(i+1,k+1,j) +a_Tmpv3
3565 a_zx(i,k+1,j) =a_zx(i,k+1,j) +a_Tmpv2
3566 a_zx(i,k,j) =a_zx(i,k,j) +a_Tmpv1
3567 a_zx(i+1,k,j) =a_zx(i+1,k,j) +a_Tmpv1
3575 DO j =j_end, j_start, -1
3577 ! Remarked by Ning Pan, 2010-08-31
3578 ! DO i =i_start, i_end
3579 ! Tmpv001 =cf1*hat(i,1,j) +cf2*hat(i,2,j)
3580 ! Tmpv002 =Tmpv001 +cf3*hat(i,3,j)
3581 ! Tmpv003 =Tmpv002 +cf1*hat(i+1,1,j)
3582 ! Tmpv004 =Tmpv003 +cf2*hat(i+1,2,j)
3583 ! Tmpv005 =Tmpv004 +cf3*hat(i+1,3,j)
3584 ! Tmpv006 =0.5*Tmpv005
3585 ! hatavg(i,1,j) =Tmpv006
3587 ! Tmpv001 =hat(i,ktes1,j) +hat(i+1,ktes1,j)
3588 ! Tmpv200(i) =Tmpv001
3589 ! Tmpv002 =cft1*Tmpv200(i)
3590 ! Tmpv003 =hat(i,ktes2,j) +hat(i+1,ktes2,j)
3591 ! Tmpv201(i) =Tmpv003
3592 ! Tmpv004 =cft2*Tmpv201(i)
3593 ! Tmpv005 =Tmpv002 +Tmpv004
3594 ! Tmpv006 =0.5*Tmpv005
3595 ! hatavg(i,kte,j) =Tmpv006
3599 DO i =i_end, i_start, -1
3600 a_Tmpv6 =a_hatavg(i,kte,j)
3601 a_hatavg(i,kte,j) =0.0
3602 a_Tmpv5 =0.5*a_Tmpv6
3605 ! a_cft2 =a_cft2 +Tmpv201(i)*a_Tmpv4 ! Remarked by Ning Pan, 2010-08-31
3606 a_Tmpv3 =cft2*a_Tmpv4
3607 a_hat(i,ktes2,j) =a_hat(i,ktes2,j) +a_Tmpv3
3608 a_hat(i+1,ktes2,j) =a_hat(i+1,ktes2,j) +a_Tmpv3
3609 ! a_cft1 =a_cft1 +Tmpv200(i)*a_Tmpv2 ! Remarked by Ning Pan, 2010-08-31
3610 a_Tmpv1 =cft1*a_Tmpv2
3611 a_hat(i,ktes1,j) =a_hat(i,ktes1,j) +a_Tmpv1
3612 a_hat(i+1,ktes1,j) =a_hat(i+1,ktes1,j) +a_Tmpv1
3613 a_Tmpv6 =a_hatavg(i,1,j)
3614 a_hatavg(i,1,j) =0.0
3615 a_Tmpv5 =0.5*a_Tmpv6
3617 a_hat(i+1,3,j) =a_hat(i+1,3,j) +cf3*a_Tmpv5
3619 a_hat(i+1,2,j) =a_hat(i+1,2,j) +cf2*a_Tmpv4
3621 a_hat(i+1,1,j) =a_hat(i+1,1,j) +cf1*a_Tmpv3
3623 a_hat(i,3,j) =a_hat(i,3,j) +cf3*a_Tmpv2
3624 a_hat(i,1,j) =a_hat(i,1,j) +cf1*a_Tmpv1
3625 a_hat(i,2,j) =a_hat(i,2,j) +cf2*a_Tmpv1
3631 DO j =j_end, j_start, -1
3634 ! DO i =i_start, i_end
3635 ! Tmpv001 =hat(i,k,j) +hat(i+1,k,j)
3636 ! Tmpv002 =fnm(k)*Tmpv001
3637 ! Tmpv003 =hat(i,k-1,j) +hat(i+1,k-1,j)
3638 ! Tmpv004 =fnp(k)*Tmpv003
3639 ! Tmpv005 =Tmpv002 +Tmpv004
3640 ! Tmpv006 =0.5*Tmpv005
3641 ! hatavg(i,k,j) =Tmpv006
3646 DO k =ktf, kts+1, -1
3647 DO i =i_end, i_start, -1
3648 a_Tmpv6 =a_hatavg(i,k,j)
3649 a_hatavg(i,k,j) =0.0
3650 a_Tmpv5 =0.5*a_Tmpv6
3653 a_Tmpv3 =fnp(k)*a_Tmpv4
3654 a_hat(i,k-1,j) =a_hat(i,k-1,j) +a_Tmpv3
3655 a_hat(i+1,k-1,j) =a_hat(i+1,k-1,j) +a_Tmpv3
3656 a_Tmpv1 =fnm(k)*a_Tmpv2
3657 a_hat(i,k,j) =a_hat(i,k,j) +a_Tmpv1
3658 a_hat(i+1,k,j) =a_hat(i+1,k,j) +a_Tmpv1
3665 DO j =j_end, j_start, -1
3668 ! DO i =i_start, i_end+1
3669 ! hat(i,k,j) =u(i,k,j)/msfuy(i,j)
3675 DO i =i_end+1, i_start, -1
3676 a_u(i,k,j) =a_u(i,k,j) +1.0/msfuy(i,j)*a_hat(i,k,j)
3684 ! Remarked by Ning Pan, 2010-08-31
3685 ! DO j =j_end, j_start, -1
3687 !! DO i =i_start, i_end
3688 !! mm(i,j) =msftx(i,j)*msfty(i,j)
3692 ! DO i =i_end, i_start, -1
3701 ! cft2 =-0.5*dnw(ktes1)/dn(ktes1)
3705 ! ktf =min(kte, kde-1)
3707 ! i_end =min(ite, ide-1)
3709 ! j_end =min(jte, jde-1)
3711 ! Remarked by Ning Pan, 2010-08-31
3712 ! a_cft2 =a_cft2 -a_cft1
3716 END SUBROUTINE a_cal_deform_and_div
3718 SUBROUTINE a_calculate_km_kh(config_flags,dt,dampcoef,zdamp,damp_opt,xkmh,a_xkmh, &
3719 xkmv,a_xkmv,xkhh,a_xkhh,xkhv,a_xkhv,BN2,a_BN2,khdif,kvdif,div,a_div, &
3720 defor11,a_defor11,defor22,a_defor22,defor33,a_defor33,defor12,a_defor12, &
3721 defor13,a_defor13,defor23,a_defor23,tke,a_tke,p8w,a_p8w,t8w,a_t8w,theta, &
3722 a_theta,t,a_t,p,a_p,moist,a_moist,dn,dnw,dx,dy,rdz,a_rdz,rdzw,a_rdzw, &
3723 isotropic,n_moist,cf1,cf2,cf3,warm_rain,mix_upper_bound,msftx,msfty,zx,a_zx,zy,a_zy,ids,ide,jds,jde, &
3724 kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
3726 !PART I: DECLARATION OF VARIABLES
3730 INTEGER :: K0_ADJ,K1_ADJ,K2_ADJ,K3_ADJ
3731 TYPE(grid_config_rec_type) :: config_flags
3732 INTEGER :: n_moist,damp_opt,isotropic,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms, &
3733 kme,its,ite,jts,jte,kts,kte
3734 LOGICAL :: warm_rain
3735 REAL :: dx,dy,zdamp,dt,dampcoef,cf1,cf2,cf3,khdif,kvdif
3736 REAL,DIMENSION(kms:kme) :: dnw,dn
3737 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_moist) :: moist,a_moist
3738 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: xkmv,a_xkmv,xkmh,a_xkmh,xkhv,a_xkhv, &
3739 xkhh,a_xkhh,BN2,a_BN2
3740 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: defor11,a_defor11,defor22,a_defor22, &
3741 defor33,a_defor33,defor12,a_defor12,defor13,a_defor13,defor23,a_defor23,div, &
3742 a_div,rdz,a_rdz,rdzw,a_rdzw,p8w,a_p8w,t8w,a_t8w,theta,a_theta,t,a_t,p,a_p,zx,a_zx,zy,a_zy
3743 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: tke,a_tke
3744 REAL :: mix_upper_bound
3745 REAL,DIMENSION(ims:ime,jms:jme) :: msftx,msfty
3746 INTEGER :: i_start,i_end,j_start,j_end,ktf,i,j,k!,km_opt
3748 ! REAL,DIMENSION(1,ims:ime,kms:kme,jms:jme) :: Keep_Lpb3_xkmh
3749 ! REAL,DIMENSION(1,ims:ime,kms:kme,jms:jme) :: Keep_Lpb3_xkhh
3750 ! REAL,DIMENSION(1,ims:ime,kms:kme,jms:jme) :: Keep_Lpb3_xkmv
3751 ! REAL,DIMENSION(1,ims:ime,kms:kme,jms:jme) :: Keep_Lpb3_xkhv
3752 INTEGER :: IX1,IX2,IX3
3753 REAL,DIMENSION(jms:jme,kms:kme,ims:ime) :: Tmpv400
3754 REAL,DIMENSION(jms:jme,kms:kme,ims:ime) :: Tmpv401
3755 REAL,DIMENSION(jms:jme,kms:kme,ims:ime) :: Tmpv402
3756 REAL,DIMENSION(jms:jme,kms:kme,ims:ime) :: Tmpv403
3757 REAL,DIMENSION(jms:jme,kms:kme,ims:ime) :: Tmpv404
3758 REAL,DIMENSION(jms:jme,kms:kme,ims:ime) :: Tmpv405
3759 REAL,DIMENSION(jms:jme,kms:kme,ims:ime) :: Tmpv406
3760 REAL,DIMENSION(jms:jme,kms:kme,ims:ime) :: Tmpv407
3761 REAL,DIMENSION(jms:jme,kms:kme,ims:ime) :: Tmpv408
3762 REAL,DIMENSION(jms:jme,kms:kme,ims:ime) :: Tmpv409
3763 REAL,DIMENSION(jms:jme,kms:kme,ims:ime) :: Tmpv4010
3765 REAL, DIMENSION( ims:ime, jms:jme ) &
3768 REAL, DIMENSION( ims:ime, kms:kme, jms:jme ) &
3771 REAL, DIMENSION( ims:ime, kms:kme, jms:jme ) &
3774 !PART II: CALCULATIONS OF B. S. TRAJECTORY
3778 ktf = MIN( kte, kde-1 )
3780 i_end = MIN( ite, ide-1 )
3782 j_end = MIN( jte, jde-1 )
3783 CALL calculate_N2( config_flags, BN2, moist, &
3784 theta, t, p, p8w, t8w, &
3785 dnw, dn, rdz, rdzw, &
3786 n_moist, cf1, cf2, cf3, warm_rain, &
3787 ids, ide, jds, jde, kds, kde, &
3788 ims, ime, jms, jme, kms, kme, &
3789 its, ite, jts, jte, kts, kte )
3792 ! km_opt =config_flags%km_opt
3796 km_coef: SELECT CASE( config_flags%km_opt )
3797 ! km_coef: SELECT CASE( km_opt )
3800 CALL isotropic_km( config_flags, xkmh, xkmv, &
3801 xkhh, xkhv, khdif, kvdif, &
3802 ids, ide, jds, jde, kds, kde, &
3803 ims, ime, jms, jme, kms, kme, &
3804 its, ite, jts, jte, kts, kte )
3806 CALL tke_km( config_flags, xkmh, xkmv, &
3807 xkhh, xkhv, BN2, tke, p8w, t8w, theta, &
3808 rdz, rdzw, dx, dy, dt, isotropic, &
3809 mix_upper_bound, msftx, msfty, &
3810 hpbl,dlk,xkmv_meso, &
3811 defor11,defor22,defor12,zx,zy, &
3812 ids, ide, jds, jde, kds, kde, &
3813 ims, ime, jms, jme, kms, kme, &
3814 its, ite, jts, jte, kts, kte )
3816 CALL smag_km( config_flags, xkmh, xkmv, &
3817 xkhh, xkhv, BN2, div, &
3818 defor11, defor22, defor33, &
3819 defor12, defor13, defor23, &
3820 rdzw, dx, dy, dt, isotropic, &
3821 mix_upper_bound, msftx, msfty, &
3822 ids, ide, jds, jde, kds, kde, &
3823 ims, ime, jms, jme, kms, kme, &
3824 its, ite, jts, jte, kts, kte )
3826 CALL smag2d_km( config_flags, xkmh, xkmv, &
3827 xkhh, xkhv, defor11, defor22, defor12, &
3828 rdzw, dx, dy, msftx, msfty, &
3830 ids, ide, jds, jde, kds, kde, &
3831 ims, ime, jms, jme, kms, kme, &
3832 its, ite, jts, jte, kts, kte )
3834 CALL wrf_error_fatal( 'Please choose diffusion coefficient scheme' )
3844 ! ! Keep_Lpb3_xkmh(IX1,IX2,IX3) =xkmh(IX1,IX2,IX3)
3851 ! ! Keep_Lpb3_xkhh(IX1,IX2,IX3) =xkhh(IX1,IX2,IX3)
3858 ! ! Keep_Lpb3_xkmv(IX1,IX2,IX3) =xkmv(IX1,IX2,IX3)
3865 ! ! Keep_Lpb3_xkhv(IX1,IX2,IX3) =xkhv(IX1,IX2,IX3)
3870 ! IF ( damp_opt .eq. 1 ) THEN
3872 ! CALL cal_dampkm( config_flags, xkmh, xkhh, xkmv, xkhv, &
3873 ! dx, dy, dt, dampcoef, rdz, rdzw, zdamp, &
3875 ! ids, ide, jds, jde, kds, kde, &
3876 ! ims, ime, jms, jme, kms, kme, &
3877 ! its, ite, jts, jte, kts, kte )
3881 !PART IV: REVERSE/BACKWARD ACCUMULATIONS
3887 ! xkmh(IX1,IX2,IX3) =Keep_Lpb3_xkmh(IX1,IX2,IX3)
3894 ! xkhh(IX1,IX2,IX3) =Keep_Lpb3_xkhh(IX1,IX2,IX3)
3901 ! xkmv(IX1,IX2,IX3) =Keep_Lpb3_xkmv(IX1,IX2,IX3)
3908 ! xkhv(IX1,IX2,IX3) =Keep_Lpb3_xkhv(IX1,IX2,IX3)
3913 ! IF( damp_opt .eq. 1 ) THEN
3917 ! Tmpv400(IX1,IX2,IX3) =xkmh(IX1,IX2,IX3)
3925 ! Tmpv401(IX1,IX2,IX3) =xkhh(IX1,IX2,IX3)
3933 ! Tmpv402(IX1,IX2,IX3) =xkmv(IX1,IX2,IX3)
3941 ! Tmpv403(IX1,IX2,IX3) =xkhv(IX1,IX2,IX3)
3946 ! CALL cal_dampkm(config_flags,xkmh,xkhh,xkmv,xkhv,dx,dy,dt,dampcoef,rdz,rdzw,zdamp, &
3947 ! msftx,msfty,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
3951 IF( damp_opt .eq. 1 ) THEN
3953 ! Remarked by Ning Pan, 2010-08-18
3957 ! xkhv(IX1,IX2,IX3) =Tmpv403(IX1,IX2,IX3)
3962 ! Remarked by Ning Pan, 2010-08-18
3966 ! xkmv(IX1,IX2,IX3) =Tmpv402(IX1,IX2,IX3)
3971 ! Remarked by Ning Pan, 2010-08-18
3975 ! xkhh(IX1,IX2,IX3) =Tmpv401(IX1,IX2,IX3)
3980 ! Remarked by Ning Pan, 2010-08-18
3984 ! xkmh(IX1,IX2,IX3) =Tmpv400(IX1,IX2,IX3)
3989 CALL a_cal_dampkm(config_flags,xkmh,a_xkmh,xkhh,a_xkhh,xkmv,a_xkmv,xkhv, &
3990 a_xkhv,dx,dy,dt,dampcoef,rdz,a_rdz,rdzw,a_rdzw,zdamp,msftx,msfty,ids,ide,jds, &
3991 jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
3997 ! Remarked by Ning Pan, 2010-08-18 : recalculation of LPB[1]
4000 ! SELECT CASE (config_flags%km_opt)
4001 !! SELECT CASE (km_opt)
4003 ! CALL isotropic_km(config_flags,xkmh,xkmv,xkhh,xkhv,khdif,kvdif,ids,ide,jds,jde, &
4004 ! kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
4010 ! Tmpv400(IX1,IX2,IX3) =xkmh(IX1,IX2,IX3)
4018 ! Tmpv401(IX1,IX2,IX3) =xkmv(IX1,IX2,IX3)
4026 ! Tmpv402(IX1,IX2,IX3) =xkhh(IX1,IX2,IX3)
4031 ! CALL tke_km(config_flags,xkmh,xkmv,xkhh,xkhv,BN2,tke,p8w,t8w,theta,rdz,rdzw,dx,dy, &
4032 ! dt,isotropic,mix_upper_bound,msftx,msfty,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms, &
4033 ! kme,its,ite,jts,jte,kts,kte)
4039 ! Tmpv403(IX1,IX2,IX3) =xkmh(IX1,IX2,IX3)
4047 ! Tmpv404(IX1,IX2,IX3) =xkmv(IX1,IX2,IX3)
4055 ! Tmpv405(IX1,IX2,IX3) =xkhh(IX1,IX2,IX3)
4063 ! Tmpv406(IX1,IX2,IX3) =xkhv(IX1,IX2,IX3)
4068 ! CALL smag_km(config_flags,xkmh,xkmv,xkhh,xkhv,BN2,div,defor11,defor22,defor33, &
4069 ! defor12,defor13,defor23,rdzw,dx,dy,dt,isotropic,mix_upper_bound,msftx,msfty,ids,ide, &
4070 ! jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
4076 ! Tmpv407(IX1,IX2,IX3) =xkmh(IX1,IX2,IX3)
4084 ! Tmpv408(IX1,IX2,IX3) =xkmv(IX1,IX2,IX3)
4092 ! Tmpv409(IX1,IX2,IX3) =xkhh(IX1,IX2,IX3)
4100 ! Tmpv4010(IX1,IX2,IX3) =xkhv(IX1,IX2,IX3)
4105 ! CALL smag2d_km(config_flags,xkmh,xkmv,xkhh,xkhv,defor11,defor22,defor12,rdzw,dx, &
4106 ! dy,msftx,msfty,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
4109 ! CALL wrf_error_fatal('Please choose diffusion coefficient scheme')
4112 !! END SELECT km_coef
4115 SELECT CASE (config_flags%km_opt)
4116 ! SELECT CASE (km_opt)
4120 CALL a_isotropic_km(config_flags,xkmh,a_xkmh,xkmv,a_xkmv,xkhh,a_xkhh,xkhv, &
4121 a_xkhv,khdif,kvdif,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
4125 ! Remarked by Ning Pan, 2010-08-18
4129 ! xkhh(IX1,IX2,IX3) =Tmpv402(IX1,IX2,IX3)
4134 ! Remarked by Ning Pan, 2010-08-18
4138 ! xkmv(IX1,IX2,IX3) =Tmpv401(IX1,IX2,IX3)
4143 ! Remarked by Ning Pan, 2010-08-18
4147 ! xkmh(IX1,IX2,IX3) =Tmpv400(IX1,IX2,IX3)
4152 CALL a_tke_km(config_flags,xkmh,a_xkmh,xkmv,a_xkmv,xkhh,a_xkhh,xkhv, &
4153 a_xkhv,BN2,a_BN2,tke,a_tke,p8w,a_p8w,t8w,a_t8w,theta,a_theta,rdz,a_rdz, &
4154 rdzw,a_rdzw,dx,dy,dt,isotropic,mix_upper_bound,msftx,msfty,ids,ide,jds,jde,kds,kde, &
4155 ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
4159 ! Remarked by Ning Pan, 2010-08-18
4163 ! xkhv(IX1,IX2,IX3) =Tmpv406(IX1,IX2,IX3)
4168 ! Remarked by Ning Pan, 2010-08-18
4172 ! xkhh(IX1,IX2,IX3) =Tmpv405(IX1,IX2,IX3)
4177 ! Remarked by Ning Pan, 2010-08-18
4181 ! xkmv(IX1,IX2,IX3) =Tmpv404(IX1,IX2,IX3)
4186 ! Remarked by Ning Pan, 2010-08-18
4190 ! xkmh(IX1,IX2,IX3) =Tmpv403(IX1,IX2,IX3)
4195 CALL a_smag_km(config_flags,xkmh,a_xkmh,xkmv,a_xkmv,xkhh,a_xkhh,xkhv, &
4196 a_xkhv,BN2,a_BN2,div,a_div,defor11,a_defor11,defor22,a_defor22,defor33, &
4197 a_defor33,defor12,a_defor12,defor13,a_defor13,defor23,a_defor23,rdzw, &
4198 a_rdzw,dx,dy,dt,isotropic,mix_upper_bound,msftx,msfty,ids,ide,jds,jde,kds,kde,ims, &
4199 ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
4203 ! Remarked by Ning Pan, 2010-08-18
4207 ! xkhv(IX1,IX2,IX3) =Tmpv4010(IX1,IX2,IX3)
4212 ! Remarked by Ning Pan, 2010-08-18
4216 ! xkhh(IX1,IX2,IX3) =Tmpv409(IX1,IX2,IX3)
4221 ! Remarked by Ning Pan, 2010-08-18
4225 ! xkmv(IX1,IX2,IX3) =Tmpv408(IX1,IX2,IX3)
4230 ! Remarked by Ning Pan, 2010-08-18
4234 ! xkmh(IX1,IX2,IX3) =Tmpv407(IX1,IX2,IX3)
4239 CALL a_smag2d_km(config_flags,xkmh,a_xkmh,xkmv,a_xkmv,xkhh,a_xkhh,xkhv, &
4240 a_xkhv,defor11,a_defor11,defor22,a_defor22,defor12,a_defor12,rdzw,a_rdzw, &
4241 dx,dy,msftx,msfty,zx,a_zx,zy,a_zy,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
4246 ! CALL a_wrf_error_fatal('Please choose diffusion coefficient scheme')
4247 CALL wrf_error_fatal('Please choose diffusion coefficient scheme')
4250 ! END SELECT km_coef
4254 ! Remarked by Ning Pan, 2010-08-18
4255 ! ktf =min(kte, kde-1)
4257 ! i_end =min(ite, ide-1)
4259 ! j_end =min(jte, jde-1)
4262 ! CALL calculate_N2(config_flags,BN2,moist,theta,t,p,p8w,t8w,dnw,dn,rdz,rdzw, &
4263 ! n_moist,cf1,cf2,cf3,warm_rain,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its, &
4264 ! ite,jts,jte,kts,kte)
4267 ! CALL a_calculate_N2(config_flags,BN2,a_BN2,moist,a_moist,theta,a_theta,t, &
4268 ! a_t,p,a_p,p8w,a_p8w,t8w,a_t8w,dnw,dn,rdz,a_rdz,rdzw,a_rdzw,n_moist,cf1, &
4269 ! cf2,cf3,,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
4271 CALL a_calculate_N2(config_flags,BN2,a_BN2,moist,a_moist,theta,a_theta,t, &
4272 a_t,p,a_p,p8w,a_p8w,t8w,a_t8w,dnw,dn,rdz,a_rdz,rdzw,a_rdzw,n_moist,cf1, &
4273 cf2,cf3,warm_rain,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
4275 END SUBROUTINE a_calculate_km_kh
4277 SUBROUTINE a_cal_dampkm(config_flags,xkmh,a_xkmh,xkhh,a_xkhh,xkmv,a_xkmv, &
4278 xkhv,a_xkhv,dx,dy,dt,dampcoef,rdz,a_rdz,rdzw,a_rdzw,zdamp,msftx,msfty,ids,ide, &
4279 jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
4281 !PART I: DECLARATION OF VARIABLES
4285 INTEGER :: K0_ADJ,K1_ADJ,K2_ADJ,K3_ADJ
4286 TYPE(grid_config_rec_type) :: config_flags
4287 INTEGER :: ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte
4288 REAL :: zdamp,dx,dy,dt,dampcoef
4289 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: xkmh,a_xkmh,xkhh,a_xkhh,xkmv,a_xkmv, &
4291 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: rdz,a_rdz,rdzw,a_rdzw
4292 REAL,DIMENSION(ims:ime,jms:jme) :: msftx,msfty
4293 INTEGER :: i_start,i_end,j_start,j_end,ktf,ktfm1,i,j,k
4294 REAL :: kmmax,kmmvmax,a_kmmvmax,degrad90,dz,a_dz,tmp,a_tmp
4296 REAL,DIMENSION(its:ite) :: deltaz,a_deltaz
4297 REAL,DIMENSION(its:ite,kts:kte,jts:jte) :: dampk,a_dampk,dampkv,a_dampkv
4299 REAL :: a_Tmpv1,Tmpv001,a_Tmpv2,Tmpv002
4302 ! REAL,DIMENSION(REVISEDBYWALLS:REVISEDBYWALLS) :: Tmpv200
4303 ! REAL,DIMENSION(REVISEDBYWALLS:REVISEDBYWALLS) :: Tmpv201
4304 ! REAL,DIMENSION(REVISEDBYWALLS:REVISEDBYWALLS) :: Tmpv202
4305 ! REAL,DIMENSION(REVISEDBYWALLS:REVISEDBYWALLS,kts:min(kte,kde-1)-1) :: Tmpv300
4306 ! REAL,DIMENSION(REVISEDBYWALLS:REVISEDBYWALLS,kts:min(kte,kde-1)-1) :: Tmpv301
4307 ! REAL,DIMENSION(REVISEDBYWALLS:REVISEDBYWALLS,kts:min(kte,kde-1)-1) :: Tmpv302
4308 ! REAL,DIMENSION(REVISEDBYWALLS:REVISEDBYWALLS,kts:min(kte,kde-1)-1) :: Tmpv303
4310 REAL,DIMENSION(its:MIN(ite,ide-1)) :: Tmpv200
4311 REAL,DIMENSION(its:MIN(ite,ide-1)) :: Tmpv201
4312 REAL,DIMENSION(its:MIN(ite,ide-1)) :: Tmpv202
4313 REAL,DIMENSION(its:MIN(ite,ide-1),kts:min(kte,kde-1)-1) :: Tmpv300
4314 REAL,DIMENSION(its:MIN(ite,ide-1),kts:min(kte,kde-1)-1) :: Tmpv301
4315 REAL,DIMENSION(its:MIN(ite,ide-1),kts:min(kte,kde-1)-1) :: Tmpv302
4316 REAL,DIMENSION(its:MIN(ite,ide-1),kts:min(kte,kde-1)-1) :: Tmpv303
4317 REAL,DIMENSION(its:MIN(ite,ide-1),kts:min(kte,kde-1)-1) :: Tmpv304
4319 !PART II: CALCULATIONS OF B. S. TRAJECTORY
4323 ktf = min(kte,kde-1)
4326 i_end = MIN(ite,ide-1)
4328 j_end = MIN(jte,jde-1)
4331 IF(config_flags%specified .OR. config_flags%nested)THEN
4333 i_start = MAX(i_start,ids+config_flags%spec_bdy_width-1)
4334 i_end = MIN(i_end,ide-config_flags%spec_bdy_width)
4335 j_start = MAX(j_start,jds+config_flags%spec_bdy_width-1)
4336 j_end = MIN(j_end,jde-config_flags%spec_bdy_width)
4346 DO j = j_start, j_end
4350 DO i = i_start, i_end
4351 ds = MIN(dx/msftx(i,j),dy/msfty(i,j))
4356 tmp=min(deltaz(i)/zdamp,1.)
4357 dampk(i,k,j)=cos(degrad90*tmp)*cos(degrad90*tmp)*kmmax*dampcoef
4358 dampkv(i,k,j)=cos(degrad90*tmp)*cos(degrad90*tmp)*kmmvmax*dampcoef
4359 dampkv(i,k,j)=min(dampkv(i,k,j),dampk(i,k,j))
4363 DO i = i_start, i_end
4364 ds = MIN(dx/msftx(i,j),dy/msfty(i,j))
4367 deltaz(i) = deltaz(i) + dz
4370 tmp=min(deltaz(i)/zdamp,1.)
4371 dampk(i,k,j)=cos(degrad90*tmp)*cos(degrad90*tmp)*kmmax*dampcoef
4372 dampkv(i,k,j)=cos(degrad90*tmp)*cos(degrad90*tmp)*kmmvmax*dampcoef
4373 dampkv(i,k,j)=min(dampkv(i,k,j),dampk(i,k,j))
4380 ! DO j = j_start, j_end
4383 ! DO i = i_start, i_end
4384 ! xkmh(i,k,j)=max(xkmh(i,k,j),dampk(i,k,j))
4385 ! xkhh(i,k,j)=max(xkhh(i,k,j),dampk(i,k,j))
4386 ! xkmv(i,k,j)=max(xkmv(i,k,j),dampkv(i,k,j))
4387 ! xkhv(i,k,j)=max(xkhv(i,k,j),dampkv(i,k,j))
4393 !PART III: INITIALIZATION OF LOCAL ADJOINT PERTURBATIONS
4400 a_deltaz(K0_ADJ) =0.0
4406 a_dampk(K0_ADJ,K1_ADJ,K2_ADJ) =0.0
4414 a_dampkv(K0_ADJ,K1_ADJ,K2_ADJ) =0.0
4419 !PART IV: REVERSE/BACKWARD ACCUMULATIONS
4422 DO j =j_end, j_start, -1
4425 ! DO i =i_start, i_end
4426 ! Tmpv001 =max(xkmh(i,k,j), dampk(i,k,j))
4427 ! xkmh(i,k,j) =Tmpv001
4429 ! Tmpv001 =max(xkhh(i,k,j), dampk(i,k,j))
4430 ! xkhh(i,k,j) =Tmpv001
4432 ! Tmpv001 =max(xkmv(i,k,j), dampkv(i,k,j))
4433 ! xkmv(i,k,j) =Tmpv001
4435 ! Tmpv001 =max(xkhv(i,k,j), dampkv(i,k,j))
4436 ! xkhv(i,k,j) =Tmpv001
4442 DO i =i_end, i_start, -1
4443 a_Tmpv1 =a_xkhv(i,k,j)
4445 a_xkhv(i,k,j) =a_xkhv(i,k,j) +(1.0 +sign(1.0, xkhv(i,k,j) -dampkv(i,k,j))) &
4447 a_dampkv(i,k,j) =a_dampkv(i,k,j) +(1.0 -sign(1.0, xkhv(i,k,j) -dampkv(i,k,j)) &
4449 a_Tmpv1 =a_xkmv(i,k,j)
4451 a_xkmv(i,k,j) =a_xkmv(i,k,j) +(1.0 +sign(1.0, xkmv(i,k,j) -dampkv(i,k,j))) &
4453 a_dampkv(i,k,j) =a_dampkv(i,k,j) +(1.0 -sign(1.0, xkmv(i,k,j) -dampkv(i,k,j)) &
4455 a_Tmpv1 =a_xkhh(i,k,j)
4457 a_xkhh(i,k,j) =a_xkhh(i,k,j) +(1.0 +sign(1.0, xkhh(i,k,j) -dampk(i,k,j))) &
4459 a_dampk(i,k,j) =a_dampk(i,k,j) +(1.0 -sign(1.0, xkhh(i,k,j) -dampk(i,k,j))) &
4461 a_Tmpv1 =a_xkmh(i,k,j)
4463 a_xkmh(i,k,j) =a_xkmh(i,k,j) +(1.0 +sign(1.0, xkmh(i,k,j) -dampk(i,k,j))) &
4465 a_dampk(i,k,j) =a_dampk(i,k,j) +(1.0 -sign(1.0, xkmh(i,k,j) -dampk(i,k,j))) &
4473 DO j =j_end, j_start, -1
4476 DO i =i_start, i_end
4477 ds =min(dx/msftx(i,j), dy/msfty(i,j))
4487 tmp =min(deltaz(i)/zdamp, 1.)
4490 dampk(i,k,j) =cos(degrad90*tmp)*cos(degrad90*tmp)*kmmax*dampcoef
4492 Tmpv001 =cos(degrad90*tmp)*cos(degrad90*tmp)*kmmvmax
4493 Tmpv002 =Tmpv001*dampcoef
4494 dampkv(i,k,j) =Tmpv002
4496 Tmpv001 =min(dampkv(i,k,j), dampk(i,k,j))
4497 dampkv(i,k,j) =Tmpv001
4501 DO k =ktfm1, kts, -1
4502 DO i =i_start, i_end
4503 ds =min(dx/msftx(i,j), dy/msfty(i,j))
4508 Tmpv001 =deltaz(i) +dz
4515 Tmpv302(i,k) =kmmvmax
4517 tmp =min(deltaz(i)/zdamp, 1.)
4519 Tmpv304(i,k) =deltaz(i)
4521 dampk(i,k,j) =cos(degrad90*tmp)*cos(degrad90*tmp)*kmmax*dampcoef
4523 Tmpv001 =cos(degrad90*tmp)*cos(degrad90*tmp)*kmmvmax
4524 Tmpv002 =Tmpv001*dampcoef
4525 dampkv(i,k,j) =Tmpv002
4527 Tmpv001 =min(dampkv(i,k,j), dampk(i,k,j))
4528 dampkv(i,k,j) =Tmpv001
4534 DO i =i_end, i_start, -1
4536 ds =min(dx/msftx(i,j), dy/msfty(i,j))
4539 kmmvmax =Tmpv302(i,k)
4541 deltaz(i)=Tmpv304(i,k)
4544 a_Tmpv1 =a_dampkv(i,k,j)
4545 a_dampkv(i,k,j) =0.0
4546 a_dampkv(i,k,j) =a_dampkv(i,k,j) +(1.0 -sign(1.0, dampkv(i,k,j) -dampk(i,k,j) &
4548 a_dampk(i,k,j) =a_dampk(i,k,j) +(1.0 +sign(1.0, dampkv(i,k,j) -dampk(i,k,j))) &
4550 a_Tmpv2 =a_dampkv(i,k,j)
4551 a_dampkv(i,k,j) =0.0
4552 a_Tmpv1 =dampcoef*a_Tmpv2
4553 a_tmp =a_tmp -2.0*cos(degrad90*tmp)*degrad90*sin(degrad90*tmp)*kmmvmax*a_Tmpv1
4554 a_kmmvmax =a_kmmvmax +cos(degrad90*tmp)*cos(degrad90*tmp)*a_Tmpv1
4555 a_tmp =a_tmp -2.0*cos(degrad90*tmp)*degrad90*sin(degrad90*tmp)*kmmax*dampcoef* &
4561 a_deltaz(i) =a_deltaz(i) +(1.0/zdamp -(1.0/zdamp)*sign(1.0, deltaz(i) &
4562 /zdamp -1.))*0.5*a_tmp
4565 ! kmmvmax =Tmpv302(i,k)
4567 a_dz =a_dz +2.0*dz/dt*a_kmmvmax
4572 a_rdzw(i,k,j) =a_rdzw(i,k,j) -1./(rdzw(i,k,j)*rdzw(i,k,j))*a_dz
4574 a_Tmpv1 =a_deltaz(i)
4576 a_deltaz(i) =a_deltaz(i) +a_Tmpv1
4581 a_rdz(i,k,j) =a_rdz(i,k,j) -1./(rdz(i,k,j)*rdz(i,k,j))*a_dz
4589 DO i =i_end, i_start, -1
4591 ds =min(dx/msftx(i,j), dy/msfty(i,j))
4601 a_Tmpv1 =a_dampkv(i,k,j)
4602 a_dampkv(i,k,j) =0.0
4603 a_dampkv(i,k,j) =a_dampkv(i,k,j) +(1.0 -sign(1.0, dampkv(i,k,j) -dampk(i,k,j) &
4605 a_dampk(i,k,j) =a_dampk(i,k,j) +(1.0 +sign(1.0, dampkv(i,k,j) -dampk(i,k,j))) &
4607 a_Tmpv2 =a_dampkv(i,k,j)
4608 a_dampkv(i,k,j) =0.0
4609 a_Tmpv1 =dampcoef*a_Tmpv2
4610 a_tmp =a_tmp -2.0*cos(degrad90*tmp)*degrad90*sin(degrad90*tmp)*kmmvmax*a_Tmpv1
4611 a_kmmvmax =a_kmmvmax +cos(degrad90*tmp)*cos(degrad90*tmp)*a_Tmpv1
4612 a_tmp =a_tmp -2.0*cos(degrad90*tmp)*degrad90*sin(degrad90*tmp)*kmmax*dampcoef* &
4616 a_deltaz(i) =a_deltaz(i) +(1.0/zdamp -(1.0/zdamp)*sign(1.0, deltaz(i) &
4617 /zdamp -1.))*0.5*a_tmp
4620 a_dz =a_dz +2.0*dz/dt*a_kmmvmax
4622 a_dz =a_dz +0.5*a_deltaz(i)
4625 a_rdzw(i,k,j) =a_rdzw(i,k,j) -1./(rdzw(i,k,j)*rdzw(i,k,j))*a_dz
4633 ! degrad90 =DEGRAD*90.
4637 ! IF(config_flags%specified .OR. config_flags%nested) THEN
4638 ! i_start =max(i_start, ids +config_flags%spec_bdy_width -1)
4639 ! i_end =min(i_end, ide -config_flags%spec_bdy_width)
4640 ! j_start =max(j_start, jds +config_flags%spec_bdy_width -1)
4641 ! j_end =min(j_end, jde -config_flags%spec_bdy_width)
4644 IF(config_flags%specified .OR. config_flags%nested) THEN
4649 ! ktf =min(kte, kde-1)
4652 ! i_end =min(ite, ide-1)
4654 ! j_end =min(jte, jde-1)
4656 END SUBROUTINE a_cal_dampkm
4658 ! Generated by TAPENADE (INRIA, Tropics team)
4659 ! Tapenade 3.5 (r3785) - 22 Mar 2011 18:35
4661 ! Differentiation of calculate_n2 in reverse (adjoint) mode:
4662 ! gradient of useful results: p t t8w bn2 theta rdzw rdz
4664 ! with respect to varying inputs: p t t8w bn2 theta rdzw rdz
4666 ! RW status of diff variables: p:incr t:incr t8w:incr bn2:in-out
4667 ! theta:incr rdzw:incr rdz:incr moist:incr p8w:incr
4668 SUBROUTINE A_CALCULATE_N2(config_flags, bn2, bn2b, moist, moistb, theta&
4669 & , thetab, t, tb, p, pb, p8w, p8wb, t8w, t8wb, dnw, dn, rdz, rdzb, rdzw&
4670 & , rdzwb, n_moist, cf1, cf2, cf3, warm_rain, ids, ide, jds, jde, kds, &
4671 & kde, ims, ime, jms, jme, kms, kme, its, ite, jts, jte, kts, kte)
4673 ! end of MARTA/WCS change
4674 TYPE(GRID_CONFIG_REC_TYPE), INTENT(IN) :: config_flags
4675 INTEGER, INTENT(IN) :: n_moist, ids, ide, jds, jde, kds, kde, ims, ime&
4676 & , jms, jme, kms, kme, its, ite, jts, jte, kts, kte
4677 LOGICAL, INTENT(IN) :: warm_rain
4678 REAL, INTENT(IN) :: cf1, cf2, cf3
4679 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: bn2
4680 REAL, DIMENSION(ims:ime, kms:kme, jms:jme) :: bn2b
4681 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(IN) :: rdz, rdzw, &
4682 & theta, t, p, p8w, t8w
4683 REAL, DIMENSION(ims:ime, kms:kme, jms:jme) :: rdzb, rdzwb, thetab, tb&
4685 REAL, DIMENSION(kms:kme), INTENT(IN) :: dnw, dn
4686 REAL, DIMENSION(ims:ime, kms:kme, jms:jme, n_moist), INTENT(INOUT) :: &
4688 REAL, DIMENSION(ims:ime, kms:kme, jms:jme, n_moist) :: moistb
4690 INTEGER :: i, j, k, ktf, ispe, ktes1, ktes2, i_start, i_end, j_start, &
4692 REAL :: coefa, thetaep1, thetaem1, qc_cr, es, tc, qlpqi, qsw, qsi, &
4693 & tmpdz, xlvqv, thetaesfc, thetasfc, qvtop, qvsfc, thetatop, thetaetop
4694 REAL :: coefab, thetaep1b, thetaem1b, esb, tcb, tmpdzb, xlvqvb, &
4695 & thetaesfcb, thetasfcb, qvsfcb
4696 REAL, DIMENSION(its:ite, jts:jte) :: tmp1sfc, tmp1top
4697 REAL, DIMENSION(its:ite, jts:jte) :: tmp1sfcb
4698 REAL, DIMENSION(its:ite, kts:kte, jts:jte) :: tmp1, qvs, qctmp
4699 REAL, DIMENSION(its:ite, kts:kte, jts:jte) :: tmp1b, qvsb
4755 !-----------------------------------------------------------------------
4758 IF (kte .GT. kde - 1) THEN
4764 IF (ite .GT. ide - 1) THEN
4770 IF (jte .GT. jde - 1) THEN
4775 IF ((config_flags%open_xs .OR. config_flags%specified) .OR. &
4776 & config_flags%nested) THEN
4777 IF (ids + 1 .LT. its) THEN
4783 IF ((config_flags%open_xe .OR. config_flags%specified) .OR. &
4784 & config_flags%nested) THEN
4785 IF (ide - 2 .GT. ite) THEN
4791 IF ((config_flags%open_ys .OR. config_flags%specified) .OR. &
4792 & config_flags%nested) THEN
4793 IF (jds + 1 .LT. jts) THEN
4799 IF ((config_flags%open_ye .OR. config_flags%specified) .OR. &
4800 & config_flags%nested) THEN
4801 IF (jde - 2 .GT. jte) THEN
4807 IF (config_flags%periodic_x) i_start = its
4808 IF (config_flags%periodic_x) THEN
4809 IF (ite .GT. ide - 1) THEN
4815 IF (p_qc .GT. param_first_scalar) THEN
4819 qctmp(i, k, j) = moist(i, k, j, p_qc)
4827 qctmp(i, k, j) = 0.0
4844 DO ispe=param_first_scalar,n_moist
4845 IF ((ispe .EQ. p_qv .OR. ispe .EQ. p_qc) .OR. ispe .EQ. p_qi) THEN
4849 tmp1(i, k, j) = tmp1(i, k, j) + moist(i, k, j, ispe)
4855 tmp1sfc(i, j) = tmp1sfc(i, j) + cf1*moist(i, 1, j, ispe) + cf2&
4856 & *moist(i, 2, j, ispe) + cf3*moist(i, 3, j, ispe)
4859 CALL PUSHCONTROL1B(1)
4861 CALL PUSHCONTROL1B(0)
4864 ! Calculate saturation mixing ratio.
4868 tc = t(i, k, j) - svpt0
4870 es = 1000.0*svp1*EXP(svp2*tc/(t(i, k, j)-svp3))
4871 qvs(i, k, j) = ep_2*es/(p(i, k, j)-es)
4878 IF (moist(i, k, j, p_qv) .GE. qvs(i, k, j) .OR. qctmp(i, k, j) &
4880 xlvqv = xlv*moist(i, k, j, p_qv)
4881 CALL PUSHREAL8(coefa)
4882 coefa = (1.0+xlvqv/r_d/t(i, k, j))/(1.0+xlv*xlvqv/cp/r_v/t(i, &
4883 & k, j)/t(i, k, j))/theta(i, k, j)
4884 CALL PUSHREAL8(thetaep1)
4885 thetaep1 = theta(i, k+1, j)*(1.0+xlv*qvs(i, k+1, j)/cp/t(i, k+&
4887 CALL PUSHREAL8(thetaem1)
4888 thetaem1 = theta(i, k-1, j)*(1.0+xlv*qvs(i, k-1, j)/cp/t(i, k-&
4890 CALL PUSHCONTROL1B(1)
4892 CALL PUSHCONTROL1B(0)
4900 tmpdz = 1.0/rdz(i, k+1, j) + 0.5/rdzw(i, k, j)
4901 thetasfc = t8w(i, kts, j)/(p8w(i, k, j)/p1000mb)**(r_d/cp)
4902 IF (moist(i, k, j, p_qv) .GE. qvs(i, k, j) .OR. qctmp(i, k, j) &
4904 CALL PUSHREAL8(qvsfc)
4905 xlvqv = xlv*moist(i, k, j, p_qv)
4906 CALL PUSHREAL8(coefa)
4907 coefa = (1.0+xlvqv/r_d/t(i, k, j))/(1.0+xlv*xlvqv/cp/r_v/t(i, k&
4908 & , j)/t(i, k, j))/theta(i, k, j)
4909 CALL PUSHREAL8(thetaep1)
4910 thetaep1 = theta(i, k+1, j)*(1.0+xlv*qvs(i, k+1, j)/cp/t(i, k+1&
4912 CALL PUSHCONTROL1B(1)
4914 CALL PUSHREAL8(qvsfc)
4915 qvsfc = cf1*moist(i, 1, j, p_qv) + cf2*moist(i, 2, j, p_qv) + &
4916 & cf3*moist(i, 3, j, p_qv)
4917 ! BN2(i,k,j) = g * ( ( theta(i,k+1,j) - thetasfc ) / &
4918 ! theta(i,k,j) / tmpdz + &
4919 ! 1.61 * ( moist(i,k+1,j,P_QV) - qvsfc ) / &
4921 ! ( tmp1(i,k+1,j) - tmp1sfc(i,j) ) / tmpdz )
4922 !...... MARTA: change in computation of BN2 at the surface, WCS 040331
4923 ! controlare come calcola rdzw
4924 ! end of MARTA/WCS change
4925 CALL PUSHCONTROL1B(0)
4929 DO j=j_end,j_start,-1
4930 DO i=i_end,i_start,-1
4931 bn2b(i, ktf-1, j) = bn2b(i, ktf-1, j) + bn2b(i, ktf, j)
4932 bn2b(i, ktf, j) = 0.0
4938 DO j=j_end,j_start,-1
4939 DO i=i_end,i_start,-1
4940 CALL POPCONTROL1B(branch)
4941 IF (branch .EQ. 0) THEN
4942 tmpdz = 1./rdzw(i, k, j)
4943 temp22 = theta(i, k, j)
4944 temp22b0 = g*bn2b(i, k, j)
4945 temp22b1 = temp22b0/(temp22*tmpdz)
4946 temp22b2 = -((theta(i, k+1, j)-theta(i, k, j))*temp22b1/(temp22*&
4948 temp22b3 = 1.61*temp22b0/tmpdz
4949 temp22b4 = -(temp22b0/tmpdz)
4950 thetab(i, k+1, j) = thetab(i, k+1, j) + temp22b1
4951 thetab(i, k, j) = thetab(i, k, j) + tmpdz*temp22b2 - temp22b1
4952 tmpdzb = temp22*temp22b2 - (moist(i, k+1, j, p_qv)-qvsfc)*&
4953 & temp22b3/tmpdz - (tmp1(i, k+1, j)-tmp1sfc(i, j))*temp22b4/&
4955 moistb(i, k+1, j, p_qv) = moistb(i, k+1, j, p_qv) + temp22b3
4957 tmp1b(i, k+1, j) = tmp1b(i, k+1, j) + temp22b4
4958 tmp1sfcb(i, j) = tmp1sfcb(i, j) - temp22b4
4960 rdzwb(i, k, j) = rdzwb(i, k, j) - tmpdzb/rdzw(i, k, j)**2
4961 CALL POPREAL8(qvsfc)
4962 moistb(i, 1, j, p_qv) = moistb(i, 1, j, p_qv) + cf1*qvsfcb
4963 moistb(i, 2, j, p_qv) = moistb(i, 2, j, p_qv) + cf2*qvsfcb
4964 moistb(i, 3, j, p_qv) = moistb(i, 3, j, p_qv) + cf3*qvsfcb
4968 tmpdz = 1.0/rdz(i, k+1, j) + 0.5/rdzw(i, k, j)
4969 thetasfc = t8w(i, kts, j)/(p8w(i, k, j)/p1000mb)**(r_d/cp)
4970 qvsfc = cf1*qvs(i, 1, j) + cf2*qvs(i, 2, j) + cf3*qvs(i, 3, j)
4971 thetaesfc = thetasfc*(1.0+xlv*qvsfc/cp/t8w(i, kts, j))
4972 temp21 = coefa/tmpdz
4973 temp21b = g*bn2b(i, k, j)
4974 temp21b0 = (thetaep1-thetaesfc)*temp21b/tmpdz
4975 temp22b = -(temp21b/tmpdz)
4976 thetaep1b = temp21*temp21b
4977 thetaesfcb = -(temp21*temp21b)
4979 tmpdzb = -((tmp1(i, k+1, j)-tmp1sfc(i, j))*temp22b/tmpdz) - &
4981 tmp1b(i, k+1, j) = tmp1b(i, k+1, j) + temp22b
4982 tmp1sfcb(i, j) = tmp1sfcb(i, j) - temp22b
4984 temp20 = cp*t8w(i, kts, j)
4985 temp20b = xlv*thetasfc*thetaesfcb/temp20
4986 thetasfcb = (xlv*(qvsfc/temp20)+1.0)*thetaesfcb
4988 t8wb(i, kts, j) = t8wb(i, kts, j) - qvsfc*cp*temp20b/temp20
4989 CALL POPREAL8(thetaep1)
4990 temp19 = cp*t(i, k+1, j)
4991 temp18 = qvs(i, k+1, j)/temp19
4992 temp18b = xlv*theta(i, k+1, j)*thetaep1b/temp19
4993 thetab(i, k+1, j) = thetab(i, k+1, j) + (xlv*temp18+1.0)*&
4995 qvsb(i, k+1, j) = qvsb(i, k+1, j) + temp18b
4996 tb(i, k+1, j) = tb(i, k+1, j) - temp18*cp*temp18b
4997 xlvqv = xlv*moist(i, k, j, p_qv)
4998 CALL POPREAL8(coefa)
4999 temp17 = cp*r_v*t(i, k, j)**2
5000 temp15 = xlvqv/temp17
5001 temp14 = (xlv*temp15+1.0)*theta(i, k, j)
5002 temp14b = coefab/temp14
5003 temp16 = r_d*t(i, k, j)
5004 temp14b0 = -((xlvqv/temp16+1.0)*temp14b/temp14)
5005 temp15b = xlv*theta(i, k, j)*temp14b0/temp17
5006 xlvqvb = temp15b + temp14b/temp16
5007 tb(i, k, j) = tb(i, k, j) - cp*r_v*temp15*2*t(i, k, j)*temp15b -&
5008 & xlvqv*r_d*temp14b/temp16**2
5009 thetab(i, k, j) = thetab(i, k, j) + (xlv*temp15+1.0)*temp14b0
5010 moistb(i, k, j, p_qv) = moistb(i, k, j, p_qv) + xlv*xlvqvb
5011 CALL POPREAL8(qvsfc)
5012 qvsb(i, 1, j) = qvsb(i, 1, j) + cf1*qvsfcb
5013 qvsb(i, 2, j) = qvsb(i, 2, j) + cf2*qvsfcb
5014 qvsb(i, 3, j) = qvsb(i, 3, j) + cf3*qvsfcb
5017 temp12 = p8w(i, k, j)/p1000mb
5018 temp11 = temp12**temp13
5019 t8wb(i, kts, j) = t8wb(i, kts, j) + thetasfcb/temp11
5020 IF (.NOT.(temp12 .LE. 0.0 .AND. (temp13 .EQ. 0.0 .OR. temp13 .NE. &
5021 & INT(temp13)))) p8wb(i, k, j) = p8wb(i, k, j) - temp13*temp12**&
5022 & (temp13-1)*t8w(i, kts, j)*thetasfcb/(temp11**2*p1000mb)
5023 rdzb(i, k+1, j) = rdzb(i, k+1, j) - tmpdzb/rdz(i, k+1, j)**2
5024 rdzwb(i, k, j) = rdzwb(i, k, j) - 0.5*tmpdzb/rdzw(i, k, j)**2
5027 DO j=j_end,j_start,-1
5029 DO i=i_end,i_start,-1
5030 CALL POPCONTROL1B(branch)
5031 IF (branch .EQ. 0) THEN
5032 tmpdz = 1.0/rdz(i, k, j) + 1.0/rdz(i, k+1, j)
5033 temp10 = theta(i, k, j)
5034 temp10b0 = g*bn2b(i, k, j)
5035 temp10b1 = temp10b0/(temp10*tmpdz)
5036 temp10b2 = -((theta(i, k+1, j)-theta(i, k-1, j))*temp10b1/(&
5038 temp10b3 = 1.61*temp10b0/tmpdz
5039 temp10b4 = -(temp10b0/tmpdz)
5040 thetab(i, k+1, j) = thetab(i, k+1, j) + temp10b1
5041 thetab(i, k-1, j) = thetab(i, k-1, j) - temp10b1
5042 thetab(i, k, j) = thetab(i, k, j) + tmpdz*temp10b2
5043 tmpdzb = temp10*temp10b2 - (moist(i, k+1, j, p_qv)-moist(i, k-&
5044 & 1, j, p_qv))*temp10b3/tmpdz - (tmp1(i, k+1, j)-tmp1(i, k-1, &
5045 & j))*temp10b4/tmpdz
5046 moistb(i, k+1, j, p_qv) = moistb(i, k+1, j, p_qv) + temp10b3
5047 moistb(i, k-1, j, p_qv) = moistb(i, k-1, j, p_qv) - temp10b3
5048 tmp1b(i, k+1, j) = tmp1b(i, k+1, j) + temp10b4
5049 tmp1b(i, k-1, j) = tmp1b(i, k-1, j) - temp10b4
5052 tmpdz = 1.0/rdz(i, k, j) + 1.0/rdz(i, k+1, j)
5054 temp9b = g*bn2b(i, k, j)
5055 temp9b0 = (thetaep1-thetaem1)*temp9b/tmpdz
5056 temp10b = -(temp9b/tmpdz)
5057 thetaep1b = temp9*temp9b
5058 thetaem1b = -(temp9*temp9b)
5060 tmpdzb = -((tmp1(i, k+1, j)-tmp1(i, k-1, j))*temp10b/tmpdz) - &
5062 tmp1b(i, k+1, j) = tmp1b(i, k+1, j) + temp10b
5063 tmp1b(i, k-1, j) = tmp1b(i, k-1, j) - temp10b
5065 CALL POPREAL8(thetaem1)
5066 temp8 = cp*t(i, k-1, j)
5067 temp7 = qvs(i, k-1, j)/temp8
5068 temp7b = xlv*theta(i, k-1, j)*thetaem1b/temp8
5069 thetab(i, k-1, j) = thetab(i, k-1, j) + (xlv*temp7+1.0)*&
5071 qvsb(i, k-1, j) = qvsb(i, k-1, j) + temp7b
5072 tb(i, k-1, j) = tb(i, k-1, j) - temp7*cp*temp7b
5073 CALL POPREAL8(thetaep1)
5074 temp6 = cp*t(i, k+1, j)
5075 temp5 = qvs(i, k+1, j)/temp6
5076 temp5b = xlv*theta(i, k+1, j)*thetaep1b/temp6
5077 thetab(i, k+1, j) = thetab(i, k+1, j) + (xlv*temp5+1.0)*&
5079 qvsb(i, k+1, j) = qvsb(i, k+1, j) + temp5b
5080 tb(i, k+1, j) = tb(i, k+1, j) - temp5*cp*temp5b
5081 xlvqv = xlv*moist(i, k, j, p_qv)
5082 CALL POPREAL8(coefa)
5083 temp4 = cp*r_v*t(i, k, j)**2
5085 temp1 = (xlv*temp2+1.0)*theta(i, k, j)
5086 temp1b = coefab/temp1
5087 temp3 = r_d*t(i, k, j)
5088 temp1b0 = -((xlvqv/temp3+1.0)*temp1b/temp1)
5089 temp2b = xlv*theta(i, k, j)*temp1b0/temp4
5090 xlvqvb = temp2b + temp1b/temp3
5091 tb(i, k, j) = tb(i, k, j) - cp*r_v*temp2*2*t(i, k, j)*temp2b -&
5092 & xlvqv*r_d*temp1b/temp3**2
5093 thetab(i, k, j) = thetab(i, k, j) + (xlv*temp2+1.0)*temp1b0
5094 moistb(i, k, j, p_qv) = moistb(i, k, j, p_qv) + xlv*xlvqvb
5096 rdzb(i, k, j) = rdzb(i, k, j) - tmpdzb/rdz(i, k, j)**2
5097 rdzb(i, k+1, j) = rdzb(i, k+1, j) - tmpdzb/rdz(i, k+1, j)**2
5101 DO j=j_end,j_start,-1
5103 DO i=i_end,i_start,-1
5104 temp0 = p(i, k, j) - es
5105 temp0b = ep_2*qvsb(i, k, j)/temp0
5106 temp0b0 = -(es*temp0b/temp0)
5107 esb = temp0b - temp0b0
5108 pb(i, k, j) = pb(i, k, j) + temp0b0
5110 tc = t(i, k, j) - svpt0
5112 temp = t(i, k, j) - svp3
5113 tempb = svp2*EXP(svp2*(tc/temp))*svp1*1000.0*esb/temp
5115 tb(i, k, j) = tb(i, k, j) + tcb - tc*tempb/temp
5119 DO ispe=n_moist,param_first_scalar,-1
5120 CALL POPCONTROL1B(branch)
5121 IF (branch .NE. 0) THEN
5122 DO j=j_end,j_start,-1
5123 DO i=i_end,i_start,-1
5124 moistb(i, 1, j, ispe) = moistb(i, 1, j, ispe) + cf1*tmp1sfcb(i&
5126 moistb(i, 2, j, ispe) = moistb(i, 2, j, ispe) + cf2*tmp1sfcb(i&
5128 moistb(i, 3, j, ispe) = moistb(i, 3, j, ispe) + cf3*tmp1sfcb(i&
5132 DO j=j_end,j_start,-1
5134 DO i=i_end,i_start,-1
5135 moistb(i, k, j, ispe) = moistb(i, k, j, ispe) + tmp1b(i, k, &
5142 END SUBROUTINE A_CALCULATE_N2
5144 SUBROUTINE a_isotropic_km(config_flags,xkmh,a_xkmh,xkmv,a_xkmv,xkhh,a_xkhh, &
5145 xkhv,a_xkhv,khdif,kvdif,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite, &
5148 !PART I: DECLARATION OF VARIABLES
5152 INTEGER :: K0_ADJ,K1_ADJ,K2_ADJ,K3_ADJ
5153 TYPE(grid_config_rec_type) :: config_flags
5154 INTEGER :: ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte
5156 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: xkmh,a_xkmh,xkmv,a_xkmv,xkhh,a_xkhh, &
5158 INTEGER :: i_start,i_end,j_start,j_end,ktf,i,j,k
5159 REAL :: khdif3,kvdif3
5161 !PART II: CALCULATIONS OF B. S. TRAJECTORY
5167 i_end = MIN(ite,ide-1)
5169 j_end = MIN(jte,jde-1)
5173 khdif3=khdif/prandtl
5174 kvdif3=kvdif/prandtl
5176 !PART IV: REVERSE/BACKWARD ACCUMULATIONS
5179 DO j =j_end, j_start, -1
5182 ! DO i =i_start, i_end
5183 ! xkmh(i,k,j) =khdif
5185 ! xkmv(i,k,j) =kvdif
5187 ! xkhh(i,k,j) =khdif3
5189 ! xkhv(i,k,j) =kvdif3
5195 DO i =i_end, i_start, -1
5208 ! i_end =min(ite, ide-1)
5210 ! j_end =min(jte, jde-1)
5211 ! khdif3 =khdif/prandtl
5212 ! kvdif3 =kvdif/prandtl
5214 END SUBROUTINE a_isotropic_km
5216 SUBROUTINE a_smag_km(config_flags,xkmh,a_xkmh,xkmv,a_xkmv,xkhh,a_xkhh,xkhv, &
5217 a_xkhv,BN2,a_BN2,div,a_div,defor11,a_defor11,defor22,a_defor22,defor33, &
5218 a_defor33,defor12,a_defor12,defor13,a_defor13,defor23,a_defor23,rdzw, &
5219 a_rdzw,dx,dy,dt,isotropic,mix_upper_bound,msftx,msfty,ids,ide,jds,jde,kds,kde,ims, &
5220 ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
5222 !PART I: DECLARATION OF VARIABLES
5226 INTEGER :: K0_ADJ,K1_ADJ,K2_ADJ,K3_ADJ
5227 TYPE(grid_config_rec_type) :: config_flags
5228 INTEGER :: ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte
5229 INTEGER :: isotropic
5230 REAL :: dx,dy,dt,mix_upper_bound
5231 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: BN2,a_BN2,rdzw,a_rdzw
5232 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: xkmh,a_xkmh,xkmv,a_xkmv,xkhh,a_xkhh, &
5234 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: defor11,a_defor11,defor22,a_defor22, &
5235 defor33,a_defor33,defor12,a_defor12,defor13,a_defor13,defor23,a_defor23,div,a_div
5236 REAL,DIMENSION(ims:ime,jms:jme) :: msftx,msfty
5237 INTEGER :: i_start,i_end,j_start,j_end,ktf,i,j,k
5238 REAL :: deltas,a_deltas,tmp,a_tmp,pr,a_pr,mlen_h,a_mlen_h,mlen_v,a_mlen_v, &
5240 REAL,DIMENSION(its:ite,kts:kte,jts:jte) :: def2,a_def2
5242 REAL,DIMENSION(max(jds+1,jts):min(jde-2,jte)) :: Keep_Lpb15_tmp
5243 REAL,DIMENSION(max(jds+1,jts):min(jde-2,jte)) :: Keep_Lpb16_tmp
5244 ! REAL,DIMENSION(1) :: Keep_Lpb18_tmp
5245 REAL :: a_Tmpv1,Tmpv001,a_Tmpv2,Tmpv002,a_Tmpv3,Tmpv003,a_Tmpv4,Tmpv004
5246 REAL,DIMENSION(its:min(ite,ide-1),kts:min(kte,kde-1)) :: Tmpv300
5247 REAL,DIMENSION(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)) &
5249 REAL,DIMENSION(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)) &
5251 REAL,DIMENSION(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)) &
5253 REAL,DIMENSION(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)) &
5255 REAL,DIMENSION(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)) &
5257 REAL,DIMENSION(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)) &
5259 REAL,DIMENSION(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)) &
5261 REAL,DIMENSION(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)) &
5263 REAL,DIMENSION(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)) &
5265 REAL,DIMENSION(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)) &
5267 REAL,DIMENSION(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)) &
5269 REAL,DIMENSION(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)) &
5271 REAL,DIMENSION(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)) &
5273 REAL,DIMENSION(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)) &
5275 REAL,DIMENSION(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)) &
5277 REAL,DIMENSION(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)) &
5279 REAL,DIMENSION(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)) &
5281 REAL,DIMENSION(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)) &
5283 REAL,DIMENSION(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)) &
5285 REAL,DIMENSION(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)) &
5287 REAL,DIMENSION(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)) &
5289 REAL,DIMENSION(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)) &
5291 REAL,DIMENSION(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)) &
5293 REAL,DIMENSION(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)) &
5295 REAL,DIMENSION(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)) &
5297 REAL,DIMENSION(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)) &
5299 REAL,DIMENSION(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)) &
5301 REAL,DIMENSION(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)) &
5303 REAL,DIMENSION(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)) &
5306 !PART II: CALCULATIONS OF B. S. TRAJECTORY
5309 ktf = min(kte,kde-1)
5311 i_end = MIN(ite,ide-1)
5313 j_end = MIN(jte,jde-1)
5316 IF ( config_flags%open_xs .or. config_flags%specified .or. &
5317 config_flags%nested) i_start = MAX(ids+1,its)
5322 IF ( config_flags%open_xe .or. config_flags%specified .or. &
5323 config_flags%nested) i_end = MIN(ide-2,ite)
5328 IF ( config_flags%open_ys .or. config_flags%specified .or. &
5329 config_flags%nested) j_start = MAX(jds+1,jts)
5334 IF ( config_flags%open_ye .or. config_flags%specified .or. &
5335 config_flags%nested) j_end = MIN(jde-2,jte)
5340 IF ( config_flags%periodic_x ) i_start = its
5345 IF ( config_flags%periodic_x ) i_end = MIN( ite, ide-1 )
5349 c_s = config_flags%c_s
5356 def2(i,k,j)=0.5*(defor11(i,k,j)*defor11(i,k,j) + &
5357 defor22(i,k,j)*defor22(i,k,j) + &
5358 defor33(i,k,j)*defor33(i,k,j))
5369 tmp=0.25*(defor12(i ,k,j)+defor12(i ,k,j+1)+ &
5370 defor12(i+1,k,j)+defor12(i+1,k,j+1))
5371 def2(i,k,j)=def2(i,k,j)+tmp*tmp
5380 Keep_Lpb15_tmp(j) =tmp
5384 tmp=0.25*(defor13(i ,k+1,j)+defor13(i ,k,j)+ &
5385 defor13(i+1,k+1,j)+defor13(i+1,k,j))
5386 def2(i,k,j)=def2(i,k,j)+tmp*tmp
5395 Keep_Lpb16_tmp(j) =tmp
5399 tmp=0.25*(defor23(i,k+1,j )+defor23(i,k,j )+ &
5400 defor23(i,k+1,j+1)+defor23(i,k,j+1))
5401 def2(i,k,j)=def2(i,k,j)+tmp*tmp
5410 ! ! Keep_Lpb18_tmp =tmp
5412 ! IF (isotropic .EQ. 0) THEN
5414 ! DO j = j_start, j_end
5416 ! DO i = i_start, i_end
5417 ! mlen_h=sqrt(dx/msftx(i,j) * dy/msfty(i,j))
5418 ! mlen_v= 1./rdzw(i,k,j)
5419 ! tmp=max(0.,def2(i,k,j)-BN2(i,k,j)/pr)
5421 ! xkmh(i,k,j)=max(c_s*c_s*mlen_h*mlen_h*tmp, 1.0E-6*mlen_h*mlen_h )
5422 ! xkmh(i,k,j)=min(xkmh(i,k,j), mix_upper_bound * mlen_h * mlen_h / dt )
5423 ! xkmv(i,k,j)=max(c_s*c_s*mlen_v*mlen_v*tmp, 1.0E-6*mlen_v*mlen_v )
5424 ! xkmv(i,k,j)=min(xkmv(i,k,j), mix_upper_bound * mlen_v * mlen_v / dt )
5425 ! xkhh(i,k,j)=xkmh(i,k,j)/pr
5426 ! xkhh(i,k,j)=min(xkhh(i,k,j), mix_upper_bound * mlen_h * mlen_h / dt )
5427 ! xkhv(i,k,j)=xkmv(i,k,j)/pr
5428 ! xkhv(i,k,j)=min(xkhv(i,k,j), mix_upper_bound * mlen_v * mlen_v / dt )
5434 ! DO j = j_start, j_end
5436 ! DO i = i_start, i_end
5437 ! deltas=(dx/msftx(i,j) * dy/msfty(i,j)/rdzw(i,k,j))**0.33333333
5438 ! tmp=max(0.,def2(i,k,j)-BN2(i,k,j)/pr)
5440 ! xkmh(i,k,j)=max(c_s*c_s*deltas*deltas*tmp, 1.0E-6*deltas*deltas )
5441 ! xkmh(i,k,j)=min(xkmh(i,k,j), mix_upper_bound * dx/msftx(i,j) * dy/msfty(i,j) / dt )
5442 ! xkmv(i,k,j)=xkmh(i,k,j)
5443 ! xkmv(i,k,j)=min(xkmv(i,k,j), mix_upper_bound / rdzw(i,k,j) / rdzw(i,k,j) / dt )
5444 ! xkhh(i,k,j)=xkmh(i,k,j)/pr
5445 ! xkhh(i,k,j)=min(xkhh(i,k,j), mix_upper_bound * dx/msftx(i,j) * dy/msfty(i,j) / dt )
5446 ! xkhv(i,k,j)=xkmv(i,k,j)/pr
5447 ! xkhv(i,k,j)=min(xkhv(i,k,j), mix_upper_bound / rdzw(i,k,j) / rdzw(i,k,j) / dt )
5454 !PART III: INITIALIZATION OF LOCAL ADJOINT PERTURBATIONS
5466 a_def2(K0_ADJ,K1_ADJ,K2_ADJ) =0.0
5471 !PART IV: REVERSE/BACKWARD ACCUMULATIONS
5474 ! tmp =Keep_Lpb18_tmp
5476 IF(isotropic .EQ. 0) THEN
5477 DO j =j_start, j_end
5479 DO i =i_start, i_end
5480 mlen_h =sqrt(dx/msftx(i,j)*dy/msfty(i,j))
5481 Tmpv400(i,k,j) =mlen_h
5483 mlen_v =1./rdzw(i,k,j)
5484 Tmpv401(i,k,j) =mlen_v
5486 Tmpv001 =BN2(i,k,j)/pr
5487 Tmpv002 =def2(i,k,j) -Tmpv001
5488 Tmpv402(i,k,j) =Tmpv002
5489 tmp =max(0., Tmpv402(i,k,j))
5495 Tmpv001 =c_s*c_s*mlen_h
5496 Tmpv405(i,k,j) =Tmpv001
5497 Tmpv002 =Tmpv405(i,k,j)*mlen_h
5498 Tmpv406(i,k,j) =Tmpv002
5499 Tmpv003 =Tmpv406(i,k,j)*tmp
5500 Tmpv407(i,k,j) =Tmpv003
5501 Tmpv408(i,k,j) =Tmpv407(i,k,j)
5502 Tmpv004 =max(Tmpv408(i,k,j), 1.0E-6*mlen_h*mlen_h)
5503 Tmpv409(i,k,j) =xkmh(i,k,j)
5504 xkmh(i,k,j) =Tmpv004
5506 Tmpv001 =min(xkmh(i,k,j), mix_upper_bound*mlen_h*mlen_h/dt)
5507 Tmpv4010(i,k,j) =xkmh(i,k,j)
5508 xkmh(i,k,j) =Tmpv001
5510 Tmpv001 =c_s*c_s*mlen_v
5511 Tmpv4011(i,k,j) =Tmpv001
5512 Tmpv002 =Tmpv4011(i,k,j)*mlen_v
5513 Tmpv4012(i,k,j) =Tmpv002
5514 Tmpv003 =Tmpv4012(i,k,j)*tmp
5515 Tmpv4013(i,k,j) =Tmpv003
5516 Tmpv4014(i,k,j) =Tmpv4013(i,k,j)
5517 Tmpv004 =max(Tmpv4014(i,k,j), 1.0E-6*mlen_v*mlen_v)
5518 Tmpv4015(i,k,j) =xkmv(i,k,j)
5519 xkmv(i,k,j) =Tmpv004
5521 Tmpv001 =min(xkmv(i,k,j), mix_upper_bound*mlen_v*mlen_v/dt)
5522 Tmpv4016(i,k,j) =xkmv(i,k,j)
5523 xkmv(i,k,j) =Tmpv001
5525 Tmpv001 =xkmh(i,k,j)/pr
5526 xkhh(i,k,j) =Tmpv001
5528 Tmpv001 =min(xkhh(i,k,j), mix_upper_bound*mlen_h*mlen_h/dt)
5529 xkhh(i,k,j) =Tmpv001
5531 Tmpv001 =xkmv(i,k,j)/pr
5532 xkhv(i,k,j) =Tmpv001
5534 Tmpv001 =min(xkhv(i,k,j), mix_upper_bound*mlen_v*mlen_v/dt)
5535 xkhv(i,k,j) =Tmpv001
5543 DO j =j_start, j_end
5545 DO i =i_start, i_end
5546 deltas =(dx/msftx(i,j)*dy/msfty(i,j)/rdzw(i,k,j))**0.33333333
5547 Tmpv4017(i,k,j) =deltas
5549 Tmpv001 =BN2(i,k,j)/pr
5550 Tmpv002 =def2(i,k,j) -Tmpv001
5551 Tmpv4018(i,k,j) =Tmpv002
5552 tmp =max(0., Tmpv4018(i,k,j))
5553 Tmpv4019(i,k,j) =tmp
5556 Tmpv4020(i,k,j) =tmp
5558 Tmpv001 =c_s*c_s*deltas
5559 Tmpv4021(i,k,j) =Tmpv001
5560 Tmpv002 =Tmpv4021(i,k,j)*deltas
5561 Tmpv4022(i,k,j) =Tmpv002
5562 Tmpv003 =Tmpv4022(i,k,j)*tmp
5563 Tmpv4023(i,k,j) =Tmpv003
5564 Tmpv4024(i,k,j) =Tmpv4023(i,k,j)
5565 Tmpv004 =max(Tmpv4024(i,k,j), 1.0E-6*deltas*deltas)
5566 Tmpv4025(i,k,j) =xkmh(i,k,j)
5567 xkmh(i,k,j) =Tmpv004
5569 Tmpv4026(i,k,j) =xkmh(i,k,j)
5570 xkmh(i,k,j) =min(xkmh(i,k,j), mix_upper_bound*dx/msftx(i,j)*dy/msfty(i,j)/dt)
5572 Tmpv4027(i,k,j) =xkmv(i,k,j)
5573 xkmv(i,k,j) =xkmh(i,k,j)
5575 Tmpv4028(i,k,j) =xkmv(i,k,j)
5576 xkmv(i,k,j) =min(xkmv(i,k,j), mix_upper_bound/rdzw(i,k,j)/rdzw(i,k,j)/dt)
5578 Tmpv001 =xkmh(i,k,j)/pr
5579 xkhh(i,k,j) =Tmpv001
5581 xkhh(i,k,j) =min(xkhh(i,k,j), mix_upper_bound*dx/msftx(i,j)*dy/msfty(i,j)/dt)
5583 Tmpv001 =xkmv(i,k,j)/pr
5584 xkhv(i,k,j) =Tmpv001
5586 xkhv(i,k,j) =min(xkhv(i,k,j), mix_upper_bound/rdzw(i,k,j)/rdzw(i,k,j)/dt)
5593 IF(isotropic .EQ. 0) THEN
5595 DO j =j_end, j_start, -1
5597 DO i =i_end, i_start, -1
5600 mlen_v =Tmpv401(i,k,j)
5601 mlen_h =Tmpv400(i,k,j)
5603 a_Tmpv1 =a_xkhv(i,k,j)
5605 a_xkhv(i,k,j) =a_xkhv(i,k,j) +(1.0 -sign(1.0, xkhv(i,k,j) -mix_upper_bound* &
5606 mlen_v*mlen_v/dt))*0.5*1.0*a_Tmpv1
5607 a_mlen_v =a_mlen_v +(1.0 +sign(1.0, xkhv(i,k,j) -mix_upper_bound*mlen_v* &
5608 mlen_v/dt))*0.5*(mix_upper_bound*mlen_v +mix_upper_bound*mlen_v)/dt*a_Tmpv1
5610 a_Tmpv1 =a_xkhv(i,k,j)
5612 a_xkmv(i,k,j) =a_xkmv(i,k,j) +a_Tmpv1/pr
5613 a_pr =a_pr -xkmv(i,k,j)/(pr*pr)*a_Tmpv1
5615 a_Tmpv1 =a_xkhh(i,k,j)
5617 a_xkhh(i,k,j) =a_xkhh(i,k,j) +(1.0 -sign(1.0, xkhh(i,k,j) -mix_upper_bound* &
5618 mlen_h*mlen_h/dt))*0.5*1.0*a_Tmpv1
5619 a_mlen_h =a_mlen_h +(1.0 +sign(1.0, xkhh(i,k,j) -mix_upper_bound*mlen_h* &
5620 mlen_h/dt))*0.5*(mix_upper_bound*mlen_h +mix_upper_bound*mlen_h)/dt*a_Tmpv1
5622 a_Tmpv1 =a_xkhh(i,k,j)
5624 a_xkmh(i,k,j) =a_xkmh(i,k,j) +a_Tmpv1/pr
5625 a_pr =a_pr -xkmh(i,k,j)/(pr*pr)*a_Tmpv1
5627 xkmv(i,k,j) =Tmpv4016(i,k,j)
5629 a_Tmpv1 =a_xkmv(i,k,j)
5631 a_xkmv(i,k,j) =a_xkmv(i,k,j) +(1.0 -sign(1.0, xkmv(i,k,j) -mix_upper_bound* &
5632 mlen_v*mlen_v/dt))*0.5*1.0*a_Tmpv1
5633 a_mlen_v =a_mlen_v +(1.0 +sign(1.0, xkmv(i,k,j) -mix_upper_bound*mlen_v* &
5634 mlen_v/dt))*0.5*(mix_upper_bound*mlen_v +mix_upper_bound*mlen_v)/dt*a_Tmpv1
5636 xkmv(i,k,j) =Tmpv4015(i,k,j)
5638 a_Tmpv4 =a_xkmv(i,k,j)
5640 a_Tmpv3 =(1.0 +sign(1.0, Tmpv4014(i,k,j) -1.0E-6*mlen_v*mlen_v))*0.5*a_Tmpv4
5641 a_mlen_v =a_mlen_v +(1.0 -sign(1.0, Tmpv4014(i,k,j) -1.0E-6*mlen_v*mlen_v)) &
5642 *0.5*(1.0E-6*mlen_v +1.0E-6*mlen_v)*a_Tmpv4
5643 a_Tmpv2 =tmp*a_Tmpv3
5644 a_tmp =a_tmp +Tmpv4012(i,k,j)*a_Tmpv3
5645 a_Tmpv1 =mlen_v*a_Tmpv2
5646 a_mlen_v =a_mlen_v +Tmpv4011(i,k,j)*a_Tmpv2
5647 a_c_s =a_c_s +2.0*c_s*mlen_v*a_Tmpv1
5648 a_mlen_v =a_mlen_v +c_s*c_s*a_Tmpv1
5650 xkmh(i,k,j) =Tmpv4010(i,k,j)
5652 a_Tmpv1 =a_xkmh(i,k,j)
5654 a_xkmh(i,k,j) =a_xkmh(i,k,j) +(1.0 -sign(1.0, xkmh(i,k,j) -mix_upper_bound* &
5655 mlen_h*mlen_h/dt))*0.5*1.0*a_Tmpv1
5656 a_mlen_h =a_mlen_h +(1.0 +sign(1.0, xkmh(i,k,j) -mix_upper_bound*mlen_h* &
5657 mlen_h/dt))*0.5*(mix_upper_bound*mlen_h +mix_upper_bound*mlen_h)/dt*a_Tmpv1
5659 xkmh(i,k,j) =Tmpv409(i,k,j)
5661 a_Tmpv4 =a_xkmh(i,k,j)
5663 a_Tmpv3 =(1.0 +sign(1.0, Tmpv408(i,k,j) -1.0E-6*mlen_h*mlen_h))*0.5*a_Tmpv4
5664 a_mlen_h =a_mlen_h +(1.0 -sign(1.0, Tmpv408(i,k,j) -1.0E-6*mlen_h*mlen_h)) &
5665 *0.5*(1.0E-6*mlen_h +1.0E-6*mlen_h)*a_Tmpv4
5666 a_Tmpv2 =tmp*a_Tmpv3
5667 a_tmp =a_tmp +Tmpv406(i,k,j)*a_Tmpv3
5668 a_Tmpv1 =mlen_h*a_Tmpv2
5669 a_mlen_h =a_mlen_h +Tmpv405(i,k,j)*a_Tmpv2
5670 a_c_s =a_c_s +2.0*c_s*mlen_h*a_Tmpv1
5671 a_mlen_h =a_mlen_h +c_s*c_s*a_Tmpv1
5673 ! tmp =Tmpv404(i,k,j)
5677 a_tmp =0.5*1.0*tmp**(0.5 -1)*a_tmp
5682 ! tmp =Tmpv403(i,k,j)
5685 ! (1.0 +(-1.0)*sign(1.0, 0. -Tmpv402(i,k,j)))*0.5* =a_tmp
5686 a_Tmpv2 =(1.0 +(-1.0)*sign(1.0, 0. -Tmpv402(i,k,j)))*0.5*a_tmp
5688 a_def2(i,k,j) =a_def2(i,k,j) +a_Tmpv2
5690 a_BN2(i,k,j) =a_BN2(i,k,j) +a_Tmpv1/pr
5691 a_pr =a_pr -BN2(i,k,j)/(pr*pr)*a_Tmpv1
5693 a_rdzw(i,k,j) =a_rdzw(i,k,j) -1./(rdzw(i,k,j)*rdzw(i,k,j))*a_mlen_v
5703 DO j =j_end, j_start, -1
5705 DO i =i_end, i_start, -1
5706 deltas =Tmpv4017(i,k,j)
5707 tmp =Tmpv4020(i,k,j)
5709 a_Tmpv1 =a_xkhv(i,k,j)
5711 a_xkhv(i,k,j) =a_xkhv(i,k,j) +(1.0 -sign(1.0, xkhv(i,k,j) -mix_upper_bound/ &
5712 rdzw(i,k,j)/rdzw(i,k,j)/dt))*0.5*1.0*a_Tmpv1
5713 a_rdzw(i,k,j) =a_rdzw(i,k,j) +(1.0 +sign(1.0, xkhv(i,k,j) -mix_upper_bound/ &
5714 rdzw(i,k,j)/rdzw(i,k,j)/dt))*0.5*(-mix_upper_bound/(rdzw(i,k,j)*rdzw(i,k,j)) &
5715 *rdzw(i,k,j) -mix_upper_bound/rdzw(i,k,j))/(rdzw(i,k,j)*rdzw(i,k,j))/dt*a_Tmpv1
5716 a_Tmpv1 =a_xkhv(i,k,j)
5718 a_xkmv(i,k,j) =a_xkmv(i,k,j) +a_Tmpv1/pr
5719 a_pr =a_pr -xkmv(i,k,j)/(pr*pr)*a_Tmpv1
5720 a_xkhh(i,k,j) =(1.0 -(1.0)*sign(1.0, xkhh(i,k,j) -mix_upper_bound*dx/msftx(i,j) &
5721 *dy/msfty(i,j)/dt))*0.5*a_xkhh(i,k,j)
5722 a_Tmpv1 =a_xkhh(i,k,j)
5724 a_xkmh(i,k,j) =a_xkmh(i,k,j) +a_Tmpv1/pr
5725 a_pr =a_pr -xkmh(i,k,j)/(pr*pr)*a_Tmpv1
5727 xkmv(i,k,j) =Tmpv4028(i,k,j)
5729 a_Tmpv1 =a_xkmv(i,k,j)
5731 a_xkmv(i,k,j) =a_xkmv(i,k,j) +(1.0 -sign(1.0, xkmv(i,k,j) -mix_upper_bound/ &
5732 rdzw(i,k,j)/rdzw(i,k,j)/dt))*0.5*1.0*a_Tmpv1
5733 a_rdzw(i,k,j) =a_rdzw(i,k,j) +(1.0 +sign(1.0, xkmv(i,k,j) -mix_upper_bound/ &
5734 rdzw(i,k,j)/rdzw(i,k,j)/dt))*0.5*(-mix_upper_bound/(rdzw(i,k,j)*rdzw(i,k,j)) &
5735 *rdzw(i,k,j) -mix_upper_bound/rdzw(i,k,j))/(rdzw(i,k,j)*rdzw(i,k,j))/dt*a_Tmpv1
5737 xkmv(i,k,j) =Tmpv4027(i,k,j)
5739 a_xkmh(i,k,j) =a_xkmh(i,k,j) +a_xkmv(i,k,j)
5742 xkmh(i,k,j) =Tmpv4026(i,k,j)
5744 a_xkmh(i,k,j) =(1.0 -(1.0)*sign(1.0, xkmh(i,k,j) -mix_upper_bound*dx/msftx(i,j) &
5745 *dy/msfty(i,j)/dt))*0.5*a_xkmh(i,k,j)
5747 xkmh(i,k,j) =Tmpv4025(i,k,j)
5749 a_Tmpv4 =a_xkmh(i,k,j)
5751 a_Tmpv3 =(1.0 +sign(1.0, Tmpv4024(i,k,j) -1.0E-6*deltas*deltas))*0.5*a_Tmpv4
5752 a_deltas =a_deltas +(1.0 -sign(1.0, Tmpv4024(i,k,j) -1.0E-6*deltas*deltas)) &
5753 *0.5*(1.0E-6*deltas +1.0E-6*deltas)*a_Tmpv4
5754 a_Tmpv2 =tmp*a_Tmpv3
5755 a_tmp =a_tmp +Tmpv4022(i,k,j)*a_Tmpv3
5756 a_Tmpv1 =deltas*a_Tmpv2
5757 a_deltas =a_deltas +Tmpv4021(i,k,j)*a_Tmpv2
5758 a_c_s =a_c_s +2.0*c_s*deltas*a_Tmpv1
5759 a_deltas =a_deltas +c_s*c_s*a_Tmpv1
5761 tmp =Tmpv4019(i,k,j)
5764 a_tmp =0.5*1.0*tmp**(0.5 -1)*a_tmp
5770 ! (1.0 +(-1.0)*sign(1.0, 0. -Tmpv4018(i,k,j)))*0.5* =a_tmp
5771 a_Tmpv2 =(1.0 +(-1.0)*sign(1.0, 0. -Tmpv4018(i,k,j)))*0.5*a_tmp
5773 a_def2(i,k,j) =a_def2(i,k,j) +a_Tmpv2
5775 a_BN2(i,k,j) =a_BN2(i,k,j) +a_Tmpv1/pr
5776 a_pr =a_pr -BN2(i,k,j)/(pr*pr)*a_Tmpv1
5778 a_rdzw(i,k,j) =a_rdzw(i,k,j) -dx/msftx(i,j)*dy/msfty(i,j)/(rdzw(i,k,j) &
5779 *rdzw(i,k,j))*0.33333333*(dx/msftx(i,j)*dy/msfty(i,j)/rdzw(i,k,j))**(0.33333333 -1)*a_deltas
5791 DO j =j_end, j_start, -1
5793 tmp =Keep_Lpb16_tmp(j)
5796 DO i =i_start, i_end
5797 Tmpv001 =defor23(i,k+1,j) +defor23(i,k,j)
5798 Tmpv002 =Tmpv001 +defor23(i,k+1,j+1)
5799 Tmpv003 =Tmpv002 +defor23(i,k,j+1)
5800 Tmpv004 =0.25*Tmpv003
5804 Tmpv001 =def2(i,k,j) +tmp*tmp
5805 def2(i,k,j) =Tmpv001
5811 DO i =i_end, i_start, -1
5812 a_Tmpv1 =a_def2(i,k,j)
5814 a_def2(i,k,j) =a_def2(i,k,j) +a_Tmpv1
5815 a_tmp =a_tmp +2.0*tmp*a_Tmpv1
5821 a_Tmpv3 =0.25*a_Tmpv4
5823 a_defor23(i,k,j+1) =a_defor23(i,k,j+1) +a_Tmpv3
5825 a_defor23(i,k+1,j+1) =a_defor23(i,k+1,j+1) +a_Tmpv2
5826 a_defor23(i,k+1,j) =a_defor23(i,k+1,j) +a_Tmpv1
5827 a_defor23(i,k,j) =a_defor23(i,k,j) +a_Tmpv1
5834 DO j =j_end, j_start, -1
5836 tmp =Keep_Lpb15_tmp(j)
5839 DO i =i_start, i_end
5840 Tmpv001 =defor13(i,k+1,j) +defor13(i,k,j)
5841 Tmpv002 =Tmpv001 +defor13(i+1,k+1,j)
5842 Tmpv003 =Tmpv002 +defor13(i+1,k,j)
5843 Tmpv004 =0.25*Tmpv003
5847 Tmpv001 =def2(i,k,j) +tmp*tmp
5848 def2(i,k,j) =Tmpv001
5854 DO i =i_end, i_start, -1
5855 a_Tmpv1 =a_def2(i,k,j)
5857 a_def2(i,k,j) =a_def2(i,k,j) +a_Tmpv1
5858 a_tmp =a_tmp +2.0*tmp*a_Tmpv1
5864 a_Tmpv3 =0.25*a_Tmpv4
5866 a_defor13(i+1,k,j) =a_defor13(i+1,k,j) +a_Tmpv3
5868 a_defor13(i+1,k+1,j) =a_defor13(i+1,k+1,j) +a_Tmpv2
5869 a_defor13(i,k+1,j) =a_defor13(i,k+1,j) +a_Tmpv1
5870 a_defor13(i,k,j) =a_defor13(i,k,j) +a_Tmpv1
5877 DO j =j_end, j_start, -1
5880 DO i =i_start, i_end
5881 Tmpv001 =defor12(i,k,j) +defor12(i,k,j+1)
5882 Tmpv002 =Tmpv001 +defor12(i+1,k,j)
5883 Tmpv003 =Tmpv002 +defor12(i+1,k,j+1)
5884 Tmpv004 =0.25*Tmpv003
5888 Tmpv001 =def2(i,k,j) +tmp*tmp
5889 def2(i,k,j) =Tmpv001
5895 DO i =i_end, i_start, -1
5896 a_Tmpv1 =a_def2(i,k,j)
5898 a_def2(i,k,j) =a_def2(i,k,j) +a_Tmpv1
5899 a_tmp =a_tmp +2.0*tmp*a_Tmpv1
5905 a_Tmpv3 =0.25*a_Tmpv4
5907 a_defor12(i+1,k,j+1) =a_defor12(i+1,k,j+1) +a_Tmpv3
5909 a_defor12(i+1,k,j) =a_defor12(i+1,k,j) +a_Tmpv2
5910 a_defor12(i,k,j) =a_defor12(i,k,j) +a_Tmpv1
5911 a_defor12(i,k,j+1) =a_defor12(i,k,j+1) +a_Tmpv1
5918 DO j =j_end, j_start, -1
5921 ! DO i =i_start, i_end
5922 ! Tmpv001 =defor11(i,k,j)*defor11(i,k,j) +defor22(i,k,j)*defor22(i,k,j)
5923 ! Tmpv002 =Tmpv001 +defor33(i,k,j)*defor33(i,k,j)
5924 ! Tmpv003 =0.5*Tmpv002
5925 ! def2(i,k,j) =Tmpv003
5931 DO i =i_end, i_start, -1
5932 a_Tmpv3 =a_def2(i,k,j)
5934 a_Tmpv2 =0.5*a_Tmpv3
5936 a_defor33(i,k,j) =a_defor33(i,k,j) +2.0*defor33(i,k,j)*a_Tmpv2
5937 a_defor11(i,k,j) =a_defor11(i,k,j) +2.0*defor11(i,k,j)*a_Tmpv1
5938 a_defor22(i,k,j) =a_defor22(i,k,j) +2.0*defor22(i,k,j)*a_Tmpv1
5947 ! c_s =config_flags%c_s
5950 ! a_config_flags%c_s =a_config_flags%c_s +a_c_s
5956 ! IF( config_flags%periodic_x ) THEN
5957 ! i_end =min(ite, ide-1)
5960 ! IF( config_flags%periodic_x ) THEN
5968 ! IF( config_flags%periodic_x ) THEN
5972 ! IF( config_flags%periodic_x ) THEN
5980 ! IF( config_flags%open_ye .or. config_flags%specified .or. config_flags%nested) THEN
5981 ! j_end =min(jde-2, jte)
5984 ! IF( config_flags%open_ye .or. config_flags%specified .or. &
5985 ! config_flags%nested) THEN
5993 ! IF( config_flags%open_ys .or. config_flags%specified .or. config_flags%nested) THEN
5994 ! j_start =max(jds+1, jts)
5997 ! IF( config_flags%open_ys .or. config_flags%specified .or. &
5998 ! config_flags%nested) THEN
6006 ! IF( config_flags%open_xe .or. config_flags%specified .or. config_flags%nested) THEN
6007 ! i_end =min(ide-2, ite)
6010 ! IF( config_flags%open_xe .or. config_flags%specified .or. &
6011 ! config_flags%nested) THEN
6019 ! IF( config_flags%open_xs .or. config_flags%specified .or. config_flags%nested) THEN
6020 ! i_start =max(ids+1, its)
6023 ! IF( config_flags%open_xs .or. config_flags%specified .or. &
6024 ! config_flags%nested) THEN
6029 ! ktf =min(kte, kde-1)
6031 ! i_end =min(ite, ide-1)
6033 ! j_end =min(jte, jde-1)
6035 END SUBROUTINE a_smag_km
6037 ! Generated by TAPENADE (INRIA, Tropics team)
6038 ! Tapenade 3.10 (r5363) - 9 Sep 2014 09:54
6040 ! Differentiation of smag2d_km in reverse (adjoint) mode:
6041 ! gradient of useful results: defor11 defor12 zx zy xkmh
6042 ! defor22 xkmv rdzw xkhh xkhv
6043 ! with respect to varying inputs: defor11 defor12 zx zy xkmh
6044 ! defor22 xkmv rdzw xkhh xkhv
6045 ! RW status of diff variables: defor11:incr defor12:incr zx:incr
6046 ! zy:incr xkmh:in-out defor22:incr xkmv:in-out rdzw:incr
6047 ! xkhh:in-out xkhv:in-out
6048 SUBROUTINE A_SMAG2D_KM(config_flags, xkmh, xkmhb, xkmv, xkmvb, xkhh, &
6049 & xkhhb, xkhv, xkhvb, defor11, defor11b, defor22, defor22b, defor12, &
6050 & defor12b, rdzw, rdzwb, dx, dy, msftx, msfty, zx, zxb, zy, zyb, ids, &
6051 & ide, jds, jde, kds, kde, ims, ime, jms, jme, kms, kme, its, ite, jts, &
6054 TYPE(GRID_CONFIG_REC_TYPE), INTENT(IN) :: config_flags
6055 INTEGER, INTENT(IN) :: ids, ide, jds, jde, kds, kde, ims, ime, jms, &
6056 & jme, kms, kme, its, ite, jts, jte, kts, kte
6057 REAL, INTENT(IN) :: dx, dy
6058 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(IN) :: rdzw, zx, zy
6059 REAL, DIMENSION(ims:ime, kms:kme, jms:jme) :: rdzwb, zxb, zyb
6060 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: xkmh, &
6062 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: xkmhb
6063 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(IN) :: defor11, &
6065 REAL, DIMENSION(ims:ime, kms:kme, jms:jme) :: defor11b, defor22b, &
6067 REAL, DIMENSION(ims:ime, jms:jme), INTENT(IN) :: msftx, msfty
6069 INTEGER :: i_start, i_end, j_start, j_end, ktf, i, j, k
6070 REAL :: deltas, tmp, pr, mlen_h, c_s
6072 REAL :: dxm, dym, tmpzx, tmpzy, alpha, def_limit
6073 REAL :: tmpzxb, tmpzyb, alphab
6074 REAL, DIMENSION(its:ite, kts:kte, jts:jte) :: def2
6075 REAL, DIMENSION(its:ite, kts:kte, jts:jte) :: def2b
6077 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: xkhhb
6078 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: xkhvb
6079 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: xkmvb
6106 IF (kte .GT. kde - 1) THEN
6112 IF (ite .GT. ide - 1) THEN
6118 IF (jte .GT. jde - 1) THEN
6123 IF ((config_flags%open_xs .OR. config_flags%specified) .OR. &
6124 & config_flags%nested) THEN
6125 IF (ids + 1 .LT. its) THEN
6131 IF ((config_flags%open_xe .OR. config_flags%specified) .OR. &
6132 & config_flags%nested) THEN
6133 IF (ide - 2 .GT. ite) THEN
6139 IF ((config_flags%open_ys .OR. config_flags%specified) .OR. &
6140 & config_flags%nested) THEN
6141 IF (jds + 1 .LT. jts) THEN
6147 IF ((config_flags%open_ye .OR. config_flags%specified) .OR. &
6148 & config_flags%nested) THEN
6149 IF (jde - 2 .GT. jte) THEN
6155 IF (config_flags%periodic_x) i_start = its
6156 IF (config_flags%periodic_x) THEN
6157 IF (ite .GT. ide - 1) THEN
6164 c_s = config_flags%c_s
6168 def2(i, k, j) = 0.25*((defor11(i, k, j)-defor22(i, k, j))*(&
6169 & defor11(i, k, j)-defor22(i, k, j)))
6171 tmp = 0.25*(defor12(i, k, j)+defor12(i, k, j+1)+defor12(i+1, k, &
6172 & j)+defor12(i+1, k, j+1))
6173 def2(i, k, j) = def2(i, k, j) + tmp*tmp
6181 CALL PUSHREAL8(mlen_h)
6182 mlen_h = SQRT(dx/msftx(i, j)*dy/msfty(i, j))
6184 tmp = SQRT(def2(i, k, j))
6185 ! xkmh(i,k,j)=max(c_s*c_s*mlen_h*mlen_h*tmp, 1.0E-6*mlen_h*mlen_h )
6186 xkmh(i, k, j) = c_s*c_s*mlen_h*mlen_h*tmp
6187 IF (xkmh(i, k, j) .GT. 10.*mlen_h) THEN
6188 xkmh(i, k, j) = 10.*mlen_h
6189 CALL PUSHCONTROL1B(0)
6191 CALL PUSHCONTROL1B(1)
6192 xkmh(i, k, j) = xkmh(i, k, j)
6194 xkhh(i, k, j) = xkmh(i, k, j)/pr
6195 IF (config_flags%diff_opt .EQ. 2) THEN
6196 ! jd: reduce diffusion coefficient by slope factor (modified by JB August 2014)
6197 dxm = dx/msftx(i, j)
6198 dym = dy/msfty(i, j)
6199 IF (zx(i, k, j) .GE. 0.0_8) THEN
6200 CALL PUSHREAL8(abs0)
6202 CALL PUSHCONTROL1B(1)
6204 CALL PUSHREAL8(abs0)
6206 CALL PUSHCONTROL1B(0)
6208 IF (zx(i+1, k, j) .GE. 0.0_8) THEN
6209 CALL PUSHREAL8(abs2)
6210 abs2 = zx(i+1, k, j)
6211 CALL PUSHCONTROL1B(1)
6213 CALL PUSHREAL8(abs2)
6214 abs2 = -zx(i+1, k, j)
6215 CALL PUSHCONTROL1B(0)
6217 IF (zx(i, k+1, j) .GE. 0.0_8) THEN
6218 CALL PUSHREAL8(abs4)
6219 abs4 = zx(i, k+1, j)
6220 CALL PUSHCONTROL1B(1)
6222 CALL PUSHREAL8(abs4)
6223 abs4 = -zx(i, k+1, j)
6224 CALL PUSHCONTROL1B(0)
6226 IF (zx(i+1, k+1, j) .GE. 0.0_8) THEN
6227 CALL PUSHREAL8(abs6)
6228 abs6 = zx(i+1, k+1, j)
6229 CALL PUSHCONTROL1B(0)
6231 CALL PUSHREAL8(abs6)
6232 abs6 = -zx(i+1, k+1, j)
6233 CALL PUSHCONTROL1B(1)
6235 tmpzx = 0.25*(abs0+abs2+abs4+abs6)*rdzw(i, k, j)*dxm
6236 IF (zy(i, k, j) .GE. 0.0_8) THEN
6237 CALL PUSHREAL8(abs1)
6239 CALL PUSHCONTROL1B(1)
6241 CALL PUSHREAL8(abs1)
6243 CALL PUSHCONTROL1B(0)
6245 IF (zy(i, k, j+1) .GE. 0.0_8) THEN
6246 CALL PUSHREAL8(abs3)
6247 abs3 = zy(i, k, j+1)
6248 CALL PUSHCONTROL1B(1)
6250 CALL PUSHREAL8(abs3)
6251 abs3 = -zy(i, k, j+1)
6252 CALL PUSHCONTROL1B(0)
6254 IF (zy(i, k+1, j) .GE. 0.0_8) THEN
6255 CALL PUSHREAL8(abs5)
6256 abs5 = zy(i, k+1, j)
6257 CALL PUSHCONTROL1B(1)
6259 CALL PUSHREAL8(abs5)
6260 abs5 = -zy(i, k+1, j)
6261 CALL PUSHCONTROL1B(0)
6263 IF (zy(i, k+1, j+1) .GE. 0.0_8) THEN
6264 CALL PUSHREAL8(abs7)
6265 abs7 = zy(i, k+1, j+1)
6266 CALL PUSHCONTROL1B(0)
6268 CALL PUSHREAL8(abs7)
6269 abs7 = -zy(i, k+1, j+1)
6270 CALL PUSHCONTROL1B(1)
6272 tmpzy = 0.25*(abs1+abs3+abs5+abs7)*rdzw(i, k, j)*dym
6273 x1 = SQRT(tmpzx*tmpzx + tmpzy*tmpzy)
6274 IF (x1 .LT. 1.0) THEN
6275 CALL PUSHREAL8(alpha)
6277 CALL PUSHCONTROL1B(0)
6279 CALL PUSHREAL8(alpha)
6281 CALL PUSHCONTROL1B(1)
6283 IF (10.0/mlen_h .LT. 1.e-3) THEN
6286 def_limit = 10.0/mlen_h
6288 IF (tmp .GT. def_limit) THEN
6289 CALL PUSHCONTROL1B(0)
6291 CALL PUSHCONTROL1B(1)
6293 CALL PUSHCONTROL1B(1)
6295 CALL PUSHCONTROL1B(0)
6301 DO j=j_end,j_start,-1
6303 DO i=i_end,i_start,-1
6304 CALL POPCONTROL1B(branch)
6305 IF (branch .NE. 0) THEN
6306 xkmhb(i, k, j) = xkmhb(i, k, j) + xkhhb(i, k, j)/pr
6307 xkhhb(i, k, j) = 0.0_8
6308 CALL POPCONTROL1B(branch)
6309 IF (branch .EQ. 0) THEN
6310 tempb6 = xkmhb(i, k, j)/alpha**2
6311 alphab = -(xkmh(i, k, j)*2*tempb6/alpha)
6312 xkmhb(i, k, j) = tempb6
6314 alphab = -(xkmh(i, k, j)*xkmhb(i, k, j)/alpha**2)
6315 xkmhb(i, k, j) = xkmhb(i, k, j)/alpha
6317 CALL POPCONTROL1B(branch)
6318 IF (branch .EQ. 0) THEN
6319 CALL POPREAL8(alpha)
6322 CALL POPREAL8(alpha)
6325 dxm = dx/msftx(i, j)
6326 dym = dy/msfty(i, j)
6327 tmpzx = 0.25*(abs0+abs2+abs4+abs6)*rdzw(i, k, j)*dxm
6328 tmpzy = 0.25*(abs1+abs3+abs5+abs7)*rdzw(i, k, j)*dym
6329 IF (tmpzx**2 + tmpzy**2 .EQ. 0.0_8) THEN
6332 tempb3 = x1b/(2.0*SQRT(tmpzx**2+tmpzy**2))
6334 tmpzxb = 2*tmpzx*tempb3
6335 tmpzyb = 2*tmpzy*tempb3
6336 tempb4 = dym*0.25*tmpzyb
6337 tempb5 = rdzw(i, k, j)*tempb4
6342 rdzwb(i, k, j) = rdzwb(i, k, j) + (abs1+abs3+abs5+abs7)*tempb4
6343 CALL POPCONTROL1B(branch)
6344 IF (branch .EQ. 0) THEN
6346 zyb(i, k+1, j+1) = zyb(i, k+1, j+1) + abs7b
6349 zyb(i, k+1, j+1) = zyb(i, k+1, j+1) - abs7b
6351 CALL POPCONTROL1B(branch)
6352 IF (branch .EQ. 0) THEN
6354 zyb(i, k+1, j) = zyb(i, k+1, j) - abs5b
6357 zyb(i, k+1, j) = zyb(i, k+1, j) + abs5b
6359 CALL POPCONTROL1B(branch)
6360 IF (branch .EQ. 0) THEN
6362 zyb(i, k, j+1) = zyb(i, k, j+1) - abs3b
6365 zyb(i, k, j+1) = zyb(i, k, j+1) + abs3b
6367 CALL POPCONTROL1B(branch)
6368 IF (branch .EQ. 0) THEN
6370 zyb(i, k, j) = zyb(i, k, j) - abs1b
6373 zyb(i, k, j) = zyb(i, k, j) + abs1b
6375 tempb1 = dxm*0.25*tmpzxb
6376 tempb2 = rdzw(i, k, j)*tempb1
6381 rdzwb(i, k, j) = rdzwb(i, k, j) + (abs0+abs2+abs4+abs6)*tempb1
6382 CALL POPCONTROL1B(branch)
6383 IF (branch .EQ. 0) THEN
6385 zxb(i+1, k+1, j) = zxb(i+1, k+1, j) + abs6b
6388 zxb(i+1, k+1, j) = zxb(i+1, k+1, j) - abs6b
6390 CALL POPCONTROL1B(branch)
6391 IF (branch .EQ. 0) THEN
6393 zxb(i, k+1, j) = zxb(i, k+1, j) - abs4b
6396 zxb(i, k+1, j) = zxb(i, k+1, j) + abs4b
6398 CALL POPCONTROL1B(branch)
6399 IF (branch .EQ. 0) THEN
6401 zxb(i+1, k, j) = zxb(i+1, k, j) - abs2b
6404 zxb(i+1, k, j) = zxb(i+1, k, j) + abs2b
6406 CALL POPCONTROL1B(branch)
6407 IF (branch .EQ. 0) THEN
6409 zxb(i, k, j) = zxb(i, k, j) - abs0b
6412 zxb(i, k, j) = zxb(i, k, j) + abs0b
6415 xkhvb(i, k, j) = 0.0_8
6416 xkmhb(i, k, j) = xkmhb(i, k, j) + xkhhb(i, k, j)/pr
6417 xkhhb(i, k, j) = 0.0_8
6418 xkmvb(i, k, j) = 0.0_8
6419 CALL POPCONTROL1B(branch)
6420 IF (branch .EQ. 0) xkmhb(i, k, j) = 0.0_8
6421 tmpb = mlen_h**2*c_s**2*xkmhb(i, k, j)
6422 xkmhb(i, k, j) = 0.0_8
6424 IF (.NOT.def2(i, k, j) .EQ. 0.0_8) def2b(i, k, j) = def2b(i, k, &
6425 & j) + tmpb/(2.0*SQRT(def2(i, k, j)))
6426 CALL POPREAL8(mlen_h)
6430 DO j=j_end,j_start,-1
6432 DO i=i_end,i_start,-1
6433 tmpb = 2*tmp*def2b(i, k, j)
6436 defor12b(i, k, j) = defor12b(i, k, j) + tempb
6437 defor12b(i, k, j+1) = defor12b(i, k, j+1) + tempb
6438 defor12b(i+1, k, j) = defor12b(i+1, k, j) + tempb
6439 defor12b(i+1, k, j+1) = defor12b(i+1, k, j+1) + tempb
6440 tempb0 = 0.25*2*(defor11(i, k, j)-defor22(i, k, j))*def2b(i, k, &
6442 defor11b(i, k, j) = defor11b(i, k, j) + tempb0
6443 defor22b(i, k, j) = defor22b(i, k, j) - tempb0
6444 def2b(i, k, j) = 0.0_8
6448 END SUBROUTINE A_SMAG2D_KM
6450 SUBROUTINE a_phy_bc(config_flags,div,a_div,defor11,a_defor11,defor22, &
6451 a_defor22,defor33,a_defor33,defor12,a_defor12,defor13,a_defor13,defor23, &
6452 a_defor23,xkmh,a_xkmh,xkmv,a_xkmv,xkhh,a_xkhh,xkhv,a_xkhv,tke,a_tke, &
6453 RUBLTEN,a_RUBLTEN,RVBLTEN,a_RVBLTEN,RUCUTEN,a_RUCUTEN,RVCUTEN,a_RVCUTEN,RUSHTEN,a_RUSHTEN,RVSHTEN,a_RVSHTEN, &
6454 ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms, &
6455 kme,ips,ipe,jps,jpe,kps,kpe,its,ite,jts,jte,kts,kte)
6459 TYPE(grid_config_rec_type) :: config_flags
6460 INTEGER :: ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,ips,ipe,jps,jpe,kps,kpe, &
6461 its,ite,jts,jte,kts,kte
6462 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: RUBLTEN,a_RUBLTEN,RVBLTEN,a_RVBLTEN, &
6463 RUCUTEN,a_RUCUTEN,RVCUTEN,a_RVCUTEN,RUSHTEN,a_RUSHTEN,RVSHTEN,a_RVSHTEN, &
6464 defor11,a_defor11,defor22,a_defor22,defor33,a_defor33,defor12,a_defor12, &
6465 defor13,a_defor13,defor23,a_defor23,xkmh,a_xkmh,xkmv,a_xkmv,xkhh,a_xkhh, &
6466 xkhv,a_xkhv,tke,a_tke,div,a_div
6469 IF(config_flags%diff_opt .eq. 2) THEN
6471 CALL a_set_physical_bc3d( a_defor23 , 'f', config_flags, &
6472 ids, ide, jds, jde, kds, kde, &
6473 ims, ime, jms, jme, kms, kme, &
6474 ips, ipe, jps, jpe, kps, kpe, &
6475 its, ite, jts, jte, kts, kte )
6477 CALL a_set_physical_bc3d( a_defor13 , 'e', config_flags, &
6478 ids, ide, jds, jde, kds, kde, &
6479 ims, ime, jms, jme, kms, kme, &
6480 ips, ipe, jps, jpe, kps, kpe, &
6481 its, ite, jts, jte, kts, kte )
6483 CALL a_set_physical_bc3d( a_defor12 , 'd', config_flags, &
6484 ids, ide, jds, jde, kds, kde, &
6485 ims, ime, jms, jme, kms, kme, &
6486 ips, ipe, jps, jpe, kps, kpe, &
6487 its, ite, jts, jte, kts, kte )
6489 CALL a_set_physical_bc3d( a_defor33 , 't', config_flags, &
6490 ids, ide, jds, jde, kds, kde, &
6491 ims, ime, jms, jme, kms, kme, &
6492 ips, ipe, jps, jpe, kps, kpe, &
6493 its, ite, jts, jte, kts, kte )
6495 CALL a_set_physical_bc3d( a_defor22 , 't', config_flags, &
6496 ids, ide, jds, jde, kds, kde, &
6497 ims, ime, jms, jme, kms, kme, &
6498 ips, ipe, jps, jpe, kps, kpe, &
6499 its, ite, jts, jte, kts, kte )
6501 CALL a_set_physical_bc3d( a_defor11 , 't', config_flags, &
6502 ids, ide, jds, jde, kds, kde, &
6503 ims, ime, jms, jme, kms, kme, &
6504 ips, ipe, jps, jpe, kps, kpe, &
6505 its, ite, jts, jte, kts, kte )
6507 CALL a_set_physical_bc3d( a_div , 't', config_flags, &
6508 ids, ide, jds, jde, kds, kde, &
6509 ims, ime, jms, jme, kms, kme, &
6510 ips, ipe, jps, jpe, kps, kpe, &
6511 its, ite, jts, jte, kts, kte )
6513 CALL a_set_physical_bc3d( a_xkhv , 't', config_flags, &
6514 ids, ide, jds, jde, kds, kde, &
6515 ims, ime, jms, jme, kms, kme, &
6516 ips, ipe, jps, jpe, kps, kpe, &
6517 its, ite, jts, jte, kts, kte )
6519 CALL a_set_physical_bc3d( a_xkmv , 't', config_flags, &
6520 ids, ide, jds, jde, kds, kde, &
6521 ims, ime, jms, jme, kms, kme, &
6522 ips, ipe, jps, jpe, kps, kpe, &
6523 its, ite, jts, jte, kts, kte )
6527 CALL a_set_physical_bc3d( a_xkhh , 't', config_flags, &
6528 ids, ide, jds, jde, kds, kde, &
6529 ims, ime, jms, jme, kms, kme, &
6530 ips, ipe, jps, jpe, kps, kpe, &
6531 its, ite, jts, jte, kts, kte )
6533 CALL a_set_physical_bc3d( a_xkmh , 't', config_flags, &
6534 ids, ide, jds, jde, kds, kde, &
6535 ims, ime, jms, jme, kms, kme, &
6536 ips, ipe, jps, jpe, kps, kpe, &
6537 its, ite, jts, jte, kts, kte )
6539 IF(config_flags%shcu_physics .GT. 0) THEN
6541 CALL a_set_physical_bc3d( a_RVSHTEN , 't', config_flags, &
6542 ids, ide, jds, jde, kds, kde, &
6543 ims, ime, jms, jme, kms, kme, &
6544 ips, ipe, jps, jpe, kps, kpe, &
6545 its, ite, jts, jte, kts, kte )
6547 CALL a_set_physical_bc3d( a_RUSHTEN , 't', config_flags, &
6548 ids, ide, jds, jde, kds, kde, &
6549 ims, ime, jms, jme, kms, kme, &
6550 ips, ipe, jps, jpe, kps, kpe, &
6551 its, ite, jts, jte, kts, kte )
6555 IF(config_flags%cu_physics .GT. 0) THEN
6557 CALL a_set_physical_bc3d( a_RVCUTEN , 't', config_flags, &
6558 ids, ide, jds, jde, kds, kde, &
6559 ims, ime, jms, jme, kms, kme, &
6560 ips, ipe, jps, jpe, kps, kpe, &
6561 its, ite, jts, jte, kts, kte )
6563 CALL a_set_physical_bc3d( a_RUCUTEN , 't', config_flags, &
6564 ids, ide, jds, jde, kds, kde, &
6565 ims, ime, jms, jme, kms, kme, &
6566 ips, ipe, jps, jpe, kps, kpe, &
6567 its, ite, jts, jte, kts, kte )
6571 IF(config_flags%bl_pbl_physics .GT. 0) THEN
6573 CALL a_set_physical_bc3d( a_RVBLTEN , 't', config_flags, &
6574 ids, ide, jds, jde, kds, kde, &
6575 ims, ime, jms, jme, kms, kme, &
6576 ips, ipe, jps, jpe, kps, kpe, &
6577 its, ite, jts, jte, kts, kte )
6579 CALL a_set_physical_bc3d( a_RUBLTEN , 't', config_flags, &
6580 ids, ide, jds, jde, kds, kde, &
6581 ims, ime, jms, jme, kms, kme, &
6582 ips, ipe, jps, jpe, kps, kpe, &
6583 its, ite, jts, jte, kts, kte )
6587 END SUBROUTINE a_phy_bc
6589 SUBROUTINE a_tke_km(config_flags,xkmh,a_xkmh,xkmv,a_xkmv,xkhh,a_xkhh,xkhv, &
6590 a_xkhv,bn2,a_bn2,tke,a_tke,p8w,a_p8w,t8w,a_t8w,theta,a_theta,rdz,a_rdz, &
6591 rdzw,a_rdzw,dx,dy,dt,isotropic,mix_upper_bound,msftx,msfty,ids,ide,jds,jde,kds,kde, &
6592 ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
6594 !PART I: DECLARATION OF VARIABLES
6598 INTEGER :: K0_ADJ,K1_ADJ,K2_ADJ,K3_ADJ
6599 TYPE(grid_config_rec_type) :: config_flags
6600 INTEGER :: ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte
6601 INTEGER :: isotropic
6603 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: tke,a_tke,p8w,a_p8w,t8w,a_t8w,theta, &
6604 a_theta,rdz,a_rdz,rdzw,a_rdzw,bn2,a_bn2
6605 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: xkmh,a_xkmh,xkmv,a_xkmv,xkhh,a_xkhh, &
6607 REAL :: mix_upper_bound
6608 REAL,DIMENSION(ims:ime,jms:jme) :: msftx,msfty
6609 REAL,DIMENSION(its:ite,kts:kte,jts:jte) :: l_scale,a_l_scale
6610 REAL,DIMENSION(its:ite,kts:kte,jts:jte) :: dthrdn,a_dthrdn
6611 REAL :: deltas,a_deltas,tmp,a_tmp,mlen_s,a_mlen_s,mlen_h,a_mlen_h,mlen_v, &
6612 a_mlen_v,tmpdz,a_tmpdz,thetasfc,a_thetasfc,thetatop,a_thetatop,minkx, &
6613 a_minkx,pr_inv,a_pr_inv,pr_inv_h,a_pr_inv_h,pr_inv_v,a_pr_inv_v,c_k,a_c_k
6614 INTEGER :: i_start,i_end,j_start,j_end,ktf,i,j,k
6615 REAL,PARAMETER :: tke_seed_value =1.e-06
6617 REAL,PARAMETER :: epsilon =1.e-10
6619 ! Remarked by Ning Pan, 2010-08-13
6620 ! REAL,DIMENSION(max(jds+1,jts):min(jde-2,jte)) :: Keep_Lpb16_tmpdz
6621 ! REAL,DIMENSION(max(jds+1,jts):min(jde-2,jte)) :: Keep_Lpb18_tmpdz
6622 REAL :: a_Tmpv1,Tmpv001,a_Tmpv2,Tmpv002,a_Tmpv3,Tmpv003,a_Tmpv4,Tmpv004
6623 REAL,ALLOCATABLE,DIMENSION(:) :: Tmpv200
6624 REAL,ALLOCATABLE,DIMENSION(:) :: Tmpv201
6625 REAL,ALLOCATABLE,DIMENSION(:,:) :: Tmpv300
6626 REAL,ALLOCATABLE,DIMENSION(:,:) :: Tmpv301
6627 REAL,ALLOCATABLE,DIMENSION(:,:,:) :: &
6629 Tmpv401, Tmpv402, Tmpv403, Tmpv404, Tmpv405, Tmpv406, Tmpv407, Tmpv408, Tmpv409, Tmpv4010, &
6630 Tmpv4011, Tmpv4012, Tmpv4013, Tmpv4014, Tmpv4015, Tmpv4016, Tmpv4017, Tmpv4018, Tmpv4019, Tmpv4020, &
6631 Tmpv4021, Tmpv4022, Tmpv4023, Tmpv4024, Tmpv4025, Tmpv4026, Tmpv4027, Tmpv4028, Tmpv4029, Tmpv4030, &
6635 ALLOCATE (Tmpv200(its:min(ite,ide-1)))
6636 ALLOCATE (Tmpv201(its:min(ite,ide-1)))
6637 ALLOCATE (Tmpv300(its:min(ite,ide-1),kts+1:min(kte,kde-1)-1))
6638 ALLOCATE (Tmpv301(its:min(ite,ide-1),kts+1:min(kte,kde-1)-1))
6639 ALLOCATE (Tmpv400(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)))
6640 ALLOCATE (Tmpv401(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)))
6641 ALLOCATE (Tmpv402(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)))
6642 ALLOCATE (Tmpv403(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)))
6643 ALLOCATE (Tmpv404(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)))
6644 ALLOCATE (Tmpv405(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)))
6645 ALLOCATE (Tmpv406(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)))
6646 ALLOCATE (Tmpv407(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)))
6647 ALLOCATE (Tmpv408(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)))
6648 ALLOCATE (Tmpv409(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)))
6649 ALLOCATE (Tmpv4010(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)))
6650 ALLOCATE (Tmpv4011(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)))
6651 ALLOCATE (Tmpv4012(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)))
6652 ALLOCATE (Tmpv4013(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)))
6653 ALLOCATE (Tmpv4014(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)))
6654 ALLOCATE (Tmpv4015(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)))
6655 ALLOCATE (Tmpv4016(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)))
6656 ALLOCATE (Tmpv4017(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)))
6657 ALLOCATE (Tmpv4018(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)))
6658 ALLOCATE (Tmpv4019(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)))
6659 ALLOCATE (Tmpv4020(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)))
6660 ALLOCATE (Tmpv4021(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)))
6661 ALLOCATE (Tmpv4022(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)))
6662 ALLOCATE (Tmpv4023(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)))
6663 ALLOCATE (Tmpv4024(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)))
6664 ALLOCATE (Tmpv4025(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)))
6665 ALLOCATE (Tmpv4026(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)))
6666 ALLOCATE (Tmpv4027(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)))
6667 ALLOCATE (Tmpv4028(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)))
6668 ALLOCATE (Tmpv4029(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)))
6669 ALLOCATE (Tmpv4030(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)))
6670 ALLOCATE (Tmpv4031(its:min(ite,ide-1),kts:min(kte,kde-1),max(jds+1,jts):min(jde-2,jte)))
6671 !PART II: CALCULATIONS OF B. S. TRAJECTORY
6674 ktf = MIN( kte, kde-1 )
6676 i_end = MIN( ite, ide-1 )
6678 j_end = MIN( jte, jde-1 )
6681 IF ( config_flags%open_xs .OR. config_flags%specified .OR. &
6682 config_flags%nested) i_start = MAX( ids+1, its )
6687 IF ( config_flags%open_xe .OR. config_flags%specified .OR. &
6688 config_flags%nested) i_end = MIN( ide-2, ite )
6693 IF ( config_flags%open_ys .OR. config_flags%specified .OR. &
6694 config_flags%nested) j_start = MAX( jds+1, jts )
6699 IF ( config_flags%open_ye .OR. config_flags%specified .OR. &
6700 config_flags%nested) j_end = MIN( jde-2, jte)
6705 IF ( config_flags%periodic_x ) i_start = its
6710 IF ( config_flags%periodic_x ) i_end = MIN( ite, ide-1 )
6713 c_k = config_flags%c_k
6717 IF (config_flags%isfflx .eq. 0) THEN
6718 IF ((config_flags%diff_opt .eq. 2) .and. (config_flags%bl_pbl_physics .eq. 0)) THEN
6719 IF( (config_flags%tke_drag_coefficient .lt. epsilon) .and. &
6720 (config_flags%tke_heat_flux .lt. epsilon) ) THEN
6721 tke_seed = tke_seed_value
6724 !tke_drag_coefficient and tke_heat_flux are irrelevant here
6725 tke_seed = tke_seed_value
6730 DO j = j_start, j_end
6733 DO i = i_start, i_end
6734 tmpdz = 1.0/rdz(i,k+1,j) + 1.0/rdz(i,k,j)
6735 dthrdn(i,k,j) = ( theta(i,k+1,j) - theta(i,k-1,j) ) / tmpdz
6745 DO j = j_start, j_end
6747 ! Keep_Lpb16_tmpdz(j) =tmpdz ! Remarked by Ning Pan, 2010-08-13
6749 DO i = i_start, i_end
6750 tmpdz = 1.0/rdzw(i,k+1,j) + 1.0/rdzw(i,k,j)
6751 thetasfc = T8w(i,kts,j) / ( p8w(i,k,j) / p1000mb )**( R_d / Cp )
6752 dthrdn(i,k,j) = ( theta(i,k+1,j) - thetasfc ) / tmpdz
6761 DO j = j_start, j_end
6763 ! Keep_Lpb18_tmpdz(j) =tmpdz ! Remarked by Ning Pan, 2010-08-13
6765 DO i = i_start, i_end
6766 tmpdz = 1.0 / rdz(i,k,j) + 0.5 / rdzw(i,k,j)
6767 thetatop = T8w(i,kde,j) / ( p8w(i,kde,j) / p1000mb )**( R_d / Cp )
6768 dthrdn(i,k,j) = ( thetatop - theta(i,k-1,j) ) / tmpdz
6776 ! IF ( isotropic .EQ. 0 ) THEN
6778 ! DO j = j_start, j_end
6780 ! DO i = i_start, i_end
6781 ! mlen_h = SQRT( dx/msftx(i,j) * dy/msfty(i,j) )
6782 ! tmp = SQRT( MAX( tke(i,k,j), tke_seed ) )
6783 ! deltas = 1.0 / rdzw(i,k,j)
6785 ! IF ( dthrdn(i,k,j) .GT. 0.) THEN
6787 ! mlen_s = 0.76 * tmp / ( ABS( g / theta(i,k,j) * dthrdn(i,k,j) ) )**0.5
6788 ! mlen_v = MIN( mlen_v, mlen_s )
6790 ! xkmh(i,k,j) = MAX( c_k * tmp * mlen_h, 1.0E-6 * mlen_h * mlen_h )
6791 ! xkmh(i,k,j) = MIN( xkmh(i,k,j), mix_upper_bound * mlen_h *mlen_h / dt )
6792 ! xkmv(i,k,j) = MAX( c_k * tmp * mlen_v, 1.0E-6 * deltas * deltas )
6793 ! xkmv(i,k,j) = MIN( xkmv(i,k,j), mix_upper_bound * deltas *deltas / dt )
6794 ! pr_inv_h = 1./prandtl
6795 ! pr_inv_v = 1.0 + 2.0 * mlen_v / deltas
6796 ! xkhh(i,k,j) = xkmh(i,k,j) * pr_inv_h
6797 ! xkhv(i,k,j) = xkmv(i,k,j) * pr_inv_v
6802 ! CALL calc_l_scale( config_flags, tke, BN2, l_scale, &
6803 ! i_start, i_end, ktf, j_start, j_end, &
6804 ! dx, dy, rdzw, msftx, msfty, &
6805 ! ids, ide, jds, jde, kds, kde, &
6806 ! ims, ime, jms, jme, kms, kme, &
6807 ! its, ite, jts, jte, kts, kte )
6809 ! DO j = j_start, j_end
6811 ! DO i = i_start, i_end
6812 ! tmp = SQRT( MAX( tke(i,k,j), tke_seed ) )
6813 ! deltas = ( dx/msftx(i,j) * dy/msfty(i,j) / rdzw(i,k,j) )**0.33333333
6814 ! xkmh(i,k,j) = c_k * tmp * l_scale(i,k,j)
6815 ! xkmh(i,k,j) = MIN( mix_upper_bound * dx/msftx(i,j) * dy/msfty(i,j) &
6816 ! / dt, xkmh(i,k,j) )
6817 ! xkmv(i,k,j) = c_k * tmp * l_scale(i,k,j)
6818 ! xkmv(i,k,j) = MIN( mix_upper_bound / rdzw(i,k,j) / rdzw(i,k,j) / dt , xkmv(i,k,j) )
6819 ! pr_inv = 1.0 + 2.0 * l_scale(i,k,j) / deltas
6820 ! xkhh(i,k,j) = MIN( mix_upper_bound * dx/msftx(i,j) * dy/msfty(i,j) &
6821 ! / dt, xkmh(i,k,j) * pr_inv )
6822 ! xkhv(i,k,j) = MIN( mix_upper_bound / rdzw(i,k,j) / rdzw(i,k,j) &
6823 ! / dt, xkmv(i,k,j) * pr_inv )
6830 !PART III: INITIALIZATION OF LOCAL ADJOINT PERTURBATIONS
6835 a_l_scale(K0_ADJ,K1_ADJ,K2_ADJ) =0.0
6843 a_dthrdn(K0_ADJ,K1_ADJ,K2_ADJ) =0.0
6862 !PART IV: REVERSE/BACKWARD ACCUMULATIONS
6869 IF( isotropic .EQ. 0 ) THEN
6870 DO j =j_start, j_end
6872 DO i =i_start, i_end
6873 mlen_h =sqrt(dx/msftx(i,j)*dy/msfty(i,j))
6874 Tmpv400(i,k,j) =mlen_h
6876 tmp =sqrt(max(tke(i,k,j), tke_seed))
6879 deltas =1.0/rdzw(i,k,j)
6880 Tmpv402(i,k,j) =deltas
6883 ! Tmpv403(i,k,j) =mlen_v ! Remarked by Ning Pan, 2010-08-13
6885 IF( dthrdn(i,k,j) .GT. 0.) THEN
6886 Tmpv001 =g/theta(i,k,j)*dthrdn(i,k,j)
6887 Tmpv404(i,k,j) =Tmpv001
6888 Tmpv002 =abs(Tmpv404(i,k,j))
6889 Tmpv405(i,k,j) =Tmpv002
6890 Tmpv003 =Tmpv405(i,k,j)**0.5
6891 Tmpv406(i,k,j) =Tmpv003
6892 Tmpv004 =0.76*tmp/Tmpv406(i,k,j)
6895 !REVISED AND ADDED BY WALLS
6896 Tmpv4020(i,k,j) =mlen_s
6897 Tmpv407(i,k,j) =mlen_v
6899 Tmpv001 =min(mlen_v, mlen_s)
6905 Tmpv408(i,k,j) =Tmpv001
6906 Tmpv002 =Tmpv408(i,k,j)*mlen_h
6907 Tmpv409(i,k,j) =Tmpv002
6908 Tmpv4010(i,k,j) =Tmpv409(i,k,j)
6909 Tmpv003 =max(Tmpv4010(i,k,j), 1.0E-6*mlen_h*mlen_h)
6910 xkmh(i,k,j) =Tmpv003
6911 Tmpv4011(i,k,j) =xkmh(i,k,j)
6913 Tmpv001 =min(xkmh(i,k,j), mix_upper_bound*mlen_h*mlen_h/dt)
6914 xkmh(i,k,j) =Tmpv001
6915 Tmpv4012(i,k,j) =xkmh(i,k,j)
6917 Tmpv403(i,k,j) =mlen_v ! Added by Ning Pan, 2010-08-13
6919 Tmpv4013(i,k,j) =Tmpv001
6920 Tmpv002 =Tmpv4013(i,k,j)*mlen_v
6921 Tmpv4014(i,k,j) =Tmpv002
6922 Tmpv4015(i,k,j) =Tmpv4014(i,k,j)
6923 Tmpv003 =max(Tmpv4015(i,k,j), 1.0E-6*deltas*deltas)
6924 xkmv(i,k,j) =Tmpv003
6925 Tmpv4016(i,k,j) =xkmv(i,k,j)
6927 Tmpv001 =min(xkmv(i,k,j), mix_upper_bound*deltas*deltas/dt)
6928 xkmv(i,k,j) =Tmpv001
6929 Tmpv4017(i,k,j) =xkmv(i,k,j)
6931 pr_inv_h =1./prandtl
6932 Tmpv4018(i,k,j) =pr_inv_h
6934 Tmpv001 =2.0*mlen_v/deltas
6935 Tmpv002 =1.0 +Tmpv001
6937 Tmpv4019(i,k,j) =pr_inv_v
6939 Tmpv001 =xkmh(i,k,j)*pr_inv_h
6940 xkhh(i,k,j) =Tmpv001
6942 Tmpv001 =xkmv(i,k,j)*pr_inv_v
6943 xkhv(i,k,j) =Tmpv001
6951 CALL calc_l_scale(config_flags,tke,BN2,l_scale,i_start,i_end,ktf,j_start,j_end,dx, &
6952 dy,rdzw,msftx,msfty,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
6953 DO j =j_start, j_end
6955 DO i =i_start, i_end
6956 tmp =sqrt(max(tke(i,k,j), tke_seed))
6957 Tmpv4020(i,k,j) =tmp
6959 deltas =(dx/msftx(i,j)*dy/msfty(i,j)/rdzw(i,k,j))**0.33333333
6960 Tmpv4021(i,k,j) =deltas
6963 Tmpv4022(i,k,j) =Tmpv001
6964 Tmpv002 =Tmpv4022(i,k,j)*l_scale(i,k,j)
6965 ! Tmpv4023(i,k,j) =xkmh(i,k,j) ! Remarked by Ning Pan, 2010-08-13
6966 xkmh(i,k,j) =Tmpv002
6968 Tmpv4024(i,k,j) =xkmh(i,k,j)
6969 xkmh(i,k,j) =min(mix_upper_bound*dx/msftx(i,j)*dy/msfty(i,j)/dt, xkmh(i,k,j))
6972 Tmpv4025(i,k,j) =Tmpv001
6973 Tmpv002 =Tmpv4025(i,k,j)*l_scale(i,k,j)
6974 ! Tmpv4026(i,k,j) =xkmv(i,k,j) ! Remarked by Ning Pan, 2010-08-13
6975 xkmv(i,k,j) =Tmpv002
6977 Tmpv4027(i,k,j) =xkmv(i,k,j)
6978 xkmv(i,k,j) =min(mix_upper_bound/rdzw(i,k,j)/rdzw(i,k,j)/dt, xkmv(i,k,j))
6980 Tmpv001 =2.0*l_scale(i,k,j)/deltas
6981 Tmpv002 =1.0 +Tmpv001
6983 Tmpv4028(i,k,j) =pr_inv
6985 Tmpv001 =xkmh(i,k,j)*pr_inv
6986 Tmpv4029(i,k,j) =Tmpv001
6987 xkhh(i,k,j) =min(mix_upper_bound*dx/msftx(i,j)*dy/msfty(i,j)/dt, Tmpv4029(i,k,j))
6989 Tmpv001 =xkmv(i,k,j)*pr_inv
6990 Tmpv4030(i,k,j) =Tmpv001
6991 xkhv(i,k,j) =min(mix_upper_bound/rdzw(i,k,j)/rdzw(i,k,j)/dt, Tmpv4030(i,k,j))
6998 IF( isotropic .EQ. 0 ) THEN
7000 DO j =j_end, j_start, -1
7002 DO i =i_end, i_start, -1
7004 mlen_h =Tmpv400(i,k,j)
7006 deltas =Tmpv402(i,k,j)
7007 mlen_v =Tmpv403(i,k,j)
7009 pr_inv_v =Tmpv4019(i,k,j)
7010 pr_inv_h =Tmpv4018(i,k,j)
7011 xkmv(i,k,j) =Tmpv4017(i,k,j)
7012 xkmh(i,k,j) =Tmpv4012(i,k,j)
7014 a_Tmpv1 =a_xkhv(i,k,j)
7016 a_xkmv(i,k,j) =a_xkmv(i,k,j) +pr_inv_v*a_Tmpv1
7017 a_pr_inv_v =a_pr_inv_v +xkmv(i,k,j)*a_Tmpv1
7019 a_Tmpv1 =a_xkhh(i,k,j)
7021 a_xkmh(i,k,j) =a_xkmh(i,k,j) +pr_inv_h*a_Tmpv1
7022 a_pr_inv_h =a_pr_inv_h +xkmh(i,k,j)*a_Tmpv1
7027 a_mlen_v =a_mlen_v +2.0/deltas*a_Tmpv1
7028 a_deltas =a_deltas -2.0*mlen_v/(deltas*deltas)*a_Tmpv1
7032 xkmv(i,k,j) =Tmpv4016(i,k,j)
7034 a_Tmpv1 =a_xkmv(i,k,j)
7036 a_xkmv(i,k,j) =a_xkmv(i,k,j) +(1.0 -sign(1.0, xkmv(i,k,j) -mix_upper_bound* &
7037 deltas*deltas/dt))*0.5*1.0*a_Tmpv1
7038 a_deltas =a_deltas +(1.0 +sign(1.0, xkmv(i,k,j) -mix_upper_bound*deltas* &
7039 deltas/dt))*0.5*(mix_upper_bound*deltas +mix_upper_bound*deltas)/dt*a_Tmpv1
7041 a_Tmpv3 =a_xkmv(i,k,j)
7043 a_Tmpv2 =(1.0 +sign(1.0, Tmpv4015(i,k,j) -1.0E-6*deltas*deltas))*0.5*a_Tmpv3
7044 a_deltas =a_deltas +(1.0 -sign(1.0, Tmpv4015(i,k,j) -1.0E-6*deltas*deltas)) &
7045 *0.5*(1.0E-6*deltas +1.0E-6*deltas)*a_Tmpv3
7046 a_Tmpv1 =mlen_v*a_Tmpv2
7047 a_mlen_v =a_mlen_v +Tmpv4013(i,k,j)*a_Tmpv2
7048 a_c_k =a_c_k +tmp*a_Tmpv1
7049 a_tmp =a_tmp +c_k*a_Tmpv1
7051 xkmh(i,k,j) =Tmpv4011(i,k,j)
7053 a_Tmpv1 =a_xkmh(i,k,j)
7055 a_xkmh(i,k,j) =a_xkmh(i,k,j) +(1.0 -sign(1.0, xkmh(i,k,j) -mix_upper_bound* &
7056 mlen_h*mlen_h/dt))*0.5*1.0*a_Tmpv1
7057 a_mlen_h =a_mlen_h +(1.0 +sign(1.0, xkmh(i,k,j) -mix_upper_bound*mlen_h* &
7058 mlen_h/dt))*0.5*(mix_upper_bound*mlen_h +mix_upper_bound*mlen_h)/dt*a_Tmpv1
7060 a_Tmpv3 =a_xkmh(i,k,j)
7062 a_Tmpv2 =(1.0 +sign(1.0, Tmpv4010(i,k,j) -1.0E-6*mlen_h*mlen_h))*0.5*a_Tmpv3
7063 a_mlen_h =a_mlen_h +(1.0 -sign(1.0, Tmpv4010(i,k,j) -1.0E-6*mlen_h*mlen_h)) &
7064 *0.5*(1.0E-6*mlen_h +1.0E-6*mlen_h)*a_Tmpv3
7065 a_Tmpv1 =mlen_h*a_Tmpv2
7066 a_mlen_h =a_mlen_h +Tmpv408(i,k,j)*a_Tmpv2
7067 a_c_k =a_c_k +tmp*a_Tmpv1
7068 a_tmp =a_tmp +c_k*a_Tmpv1
7070 IF( dthrdn(i,k,j) .GT. 0.) THEN
7072 !REVISED AND ADDED BY WALLS
7073 mlen_s =Tmpv4020(i,k,j)
7074 mlen_v =Tmpv407(i,k,j)
7079 a_mlen_v =a_mlen_v +(1.0 -sign(1.0, mlen_v -mlen_s))*0.5*1.0*a_Tmpv1
7080 a_mlen_s =a_mlen_s +(1.0 +sign(1.0, mlen_v -mlen_s))*0.5*1.0*a_Tmpv1
7084 a_tmp =a_tmp +0.76/Tmpv406(i,k,j)*a_Tmpv4
7085 a_Tmpv3 =-0.76*tmp/(Tmpv406(i,k,j)*Tmpv406(i,k,j))*a_Tmpv4
7086 a_Tmpv2 =0.5*Tmpv405(i,k,j)**(0.5 -1)*a_Tmpv3
7087 a_Tmpv1 =sign(1.0, Tmpv404(i,k,j))*a_Tmpv2
7088 a_theta(i,k,j) =a_theta(i,k,j) -g/(theta(i,k,j)*theta(i,k,j))*dthrdn(i,k,j)*a_Tmpv1
7089 a_dthrdn(i,k,j) =a_dthrdn(i,k,j) +g/theta(i,k,j)*a_Tmpv1
7091 !MOVE LINES TO ABOVE
7094 ! a_mlen_v =a_mlen_v +(1.0 -sign(1.0, mlen_v -mlen_s))*0.5*1.0*a_Tmpv1
7095 ! a_mlen_s =a_mlen_s +(1.0 +sign(1.0, mlen_v -mlen_s))*0.5*1.0*a_Tmpv1
7099 ! mlen_v =Tmpv403(i,k,j)
7101 a_deltas =a_deltas +a_mlen_v
7104 ! deltas =Tmpv402(i,k,j)
7106 a_rdzw(i,k,j) =a_rdzw(i,k,j) -1.0/(rdzw(i,k,j)*rdzw(i,k,j))*a_deltas
7109 ! tmp =Tmpv401(i,k,j)
7111 a_tke(i,k,j) =a_tke(i,k,j) +g_Sqrt((1.0 +(1.0)*sign(1.0, tke(i,k,j) &
7112 -tke_seed))*0.5, max(tke(i,k,j), tke_seed))*a_tmp
7115 ! mlen_h =Tmpv400(i,k,j)
7124 DO j =j_end, j_start, -1
7126 DO i =i_end, i_start, -1
7127 tmp =Tmpv4020(i,k,j)
7128 deltas =Tmpv4021(i,k,j)
7129 pr_inv =Tmpv4028(i,k,j)
7132 ! (1.0 -(-1.0)*sign(1.0, mix_upper_bound/rdzw(i,k,j)/rdzw(i,k,j)/dt -Tmpv4030(i,k,j) &
7133 ! ))*0.5* =a_xkhv(i,k,j)
7135 a_Tmpv2 =a_xkhv(i,k,j)
7137 a_rdzw(i,k,j) =a_rdzw(i,k,j) +(1.0 -sign(1.0, mix_upper_bound/rdzw(i,k,j) &
7138 /rdzw(i,k,j)/dt -Tmpv4030(i,k,j)))*0.5*(-mix_upper_bound/(rdzw(i,k,j)*rdzw(i,k,j)) &
7139 *rdzw(i,k,j) -mix_upper_bound/rdzw(i,k,j))/(rdzw(i,k,j)*rdzw(i,k,j))/dt*a_Tmpv2
7140 a_Tmpv1 =(1.0 +sign(1.0, mix_upper_bound/rdzw(i,k,j)/rdzw(i,k,j)/dt -Tmpv4030(i, &
7142 a_xkmv(i,k,j) =a_xkmv(i,k,j) +pr_inv*a_Tmpv1
7143 a_pr_inv =a_pr_inv +xkmv(i,k,j)*a_Tmpv1
7145 ! (1.0 -(-1.0)*sign(1.0, mix_upper_bound*dx/msftx(i,j)*dy/msfty(i,j)/dt -Tmpv4029(i, &
7146 ! k,j)))*0.5* =a_xkhh(i,k,j)
7147 a_Tmpv1 =(1.0 -(-1.0)*sign(1.0, mix_upper_bound*dx/msftx(i,j)*dy/msfty(i,j)/dt -Tmpv4029(i, &
7148 k,j)))*0.5*a_xkhh(i,k,j)
7150 a_xkmh(i,k,j) =a_xkmh(i,k,j) +pr_inv*a_Tmpv1
7151 a_pr_inv =a_pr_inv +xkmh(i,k,j)*a_Tmpv1
7156 a_l_scale(i,k,j) =a_l_scale(i,k,j) +2.0/deltas*a_Tmpv1
7157 a_deltas =a_deltas -2.0*l_scale(i,k,j)/(deltas*deltas)*a_Tmpv1
7159 xkmv(i,k,j) =Tmpv4027(i,k,j)
7161 a_Tmpv1 =a_xkmv(i,k,j)
7163 a_rdzw(i,k,j) =a_rdzw(i,k,j) +(1.0 -sign(1.0, mix_upper_bound/rdzw(i,k,j) &
7164 /rdzw(i,k,j)/dt -xkmv(i,k,j)))*0.5*(-mix_upper_bound/(rdzw(i,k,j)*rdzw(i,k,j)) &
7165 *rdzw(i,k,j) -mix_upper_bound/rdzw(i,k,j))/(rdzw(i,k,j)*rdzw(i,k,j))/dt*a_Tmpv1
7166 a_xkmv(i,k,j) =a_xkmv(i,k,j) +(1.0 +sign(1.0, mix_upper_bound/rdzw(i,k,j) &
7167 /rdzw(i,k,j)/dt -xkmv(i,k,j)))*0.5*1.0*a_Tmpv1
7169 ! xkmv(i,k,j) =Tmpv4026(i,k,j) ! Remarked by Ning Pan, 2010-08-13
7171 a_Tmpv2 =a_xkmv(i,k,j)
7173 a_Tmpv1 =l_scale(i,k,j)*a_Tmpv2
7174 a_l_scale(i,k,j) =a_l_scale(i,k,j) +Tmpv4025(i,k,j)*a_Tmpv2
7175 a_c_k =a_c_k +tmp*a_Tmpv1
7176 a_tmp =a_tmp +c_k*a_Tmpv1
7178 xkmh(i,k,j) =Tmpv4024(i,k,j)
7180 a_xkmh(i,k,j) =(1.0 -(-1.0)*sign(1.0, mix_upper_bound*dx/msftx(i,j) &
7181 *dy/msfty(i,j)/dt -xkmh(i,k,j)))*0.5*a_xkmh(i,k,j)
7183 ! xkmh(i,k,j) =Tmpv4023(i,k,j) ! Remarked by Ning Pan, 2010-08-13
7185 a_Tmpv2 =a_xkmh(i,k,j)
7187 a_Tmpv1 =l_scale(i,k,j)*a_Tmpv2
7188 a_l_scale(i,k,j) =a_l_scale(i,k,j) +Tmpv4022(i,k,j)*a_Tmpv2
7189 a_c_k =a_c_k +tmp*a_Tmpv1
7190 a_tmp =a_tmp +c_k*a_Tmpv1
7192 a_rdzw(i,k,j) =a_rdzw(i,k,j) -dx/msftx(i,j)*dy/msfty(i,j)/(rdzw(i,k,j) &
7193 *rdzw(i,k,j))*0.33333333*(dx/msftx(i,j)*dy/msfty(i,j)/rdzw(i,k,j))**(0.33333333 -1)*a_deltas
7196 a_tke(i,k,j) =a_tke(i,k,j) +g_Sqrt((1.0 +(1.0)*sign(1.0, tke(i,k,j) &
7197 -tke_seed))*0.5, max(tke(i,k,j), tke_seed))*a_tmp
7204 CALL a_calc_l_scale(config_flags,tke,a_tke,BN2,a_BN2,l_scale,a_l_scale, &
7205 i_start,i_end,ktf,j_start,j_end,dx,dy,rdzw,a_rdzw,msftx,msfty,ids,ide,jds,jde,kds, &
7206 kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
7217 DO j =j_end, j_start, -1
7219 ! tmpdz =Keep_Lpb18_tmpdz(j) ! Remarked by Ning Pan, 2010-08-13
7221 DO i =i_start, i_end
7222 tmpdz =1.0/rdz(i,k,j)+0.5/rdzw(i,k,j)
7225 Tmpv001 =T8w(i,kde,j)/(p8w(i,kde,j)/p1000mb)**(R_d/Cp)
7228 Tmpv001 =thetatop -theta(i,k-1,j)
7230 ! Remarked by Ning Pan, 2010-08-13
7231 ! Tmpv002 =Tmpv201(i)/tmpdz
7232 ! dthrdn(i,k,j) =Tmpv002
7236 DO i =i_end, i_start, -1
7239 a_Tmpv2 =a_dthrdn(i,k,j)
7240 a_dthrdn(i,k,j) =0.0
7241 a_Tmpv1 =a_Tmpv2/tmpdz
7242 a_tmpdz =a_tmpdz -Tmpv201(i)/(tmpdz*tmpdz)*a_Tmpv2
7243 a_thetatop =a_thetatop +a_Tmpv1
7244 a_theta(i,k-1,j) =a_theta(i,k-1,j) -a_Tmpv1
7247 a_T8w(i,kde,j) =a_T8w(i,kde,j) +a_Tmpv1/(p8w(i,kde,j)/p1000mb)**(R_d/Cp)
7248 a_p8w(i,kde,j) =a_p8w(i,kde,j) -(R_d/Cp)*1.0/p1000mb*(p8w(i,kde,j)/p1000mb) &
7249 **((R_d/Cp) -1)*T8w(i,kde,j)/((p8w(i,kde,j)/p1000mb)**(R_d/Cp)*(p8w(i,kde,j)/p1000mb) &
7254 a_rdz(i,k,j) =a_rdz(i,k,j) -1.0/(rdz(i,k,j)*rdz(i,k,j))*a_Tmpv1
7255 a_rdzw(i,k,j) =a_rdzw(i,k,j) -0.5/(rdzw(i,k,j)*rdzw(i,k,j))*a_Tmpv1
7269 DO j =j_end, j_start, -1
7271 ! tmpdz =Keep_Lpb16_tmpdz(j) ! Remarked by Ning Pan, 2010-08-13
7273 DO i =i_start, i_end
7274 tmpdz =1.0/rdzw(i,k+1,j) + 1.0/rdzw(i,k,j)
7277 Tmpv001 =T8w(i,kts,j)/(p8w(i,k,j)/p1000mb)**(R_d/Cp)
7280 Tmpv001 =theta(i,k+1,j) -thetasfc
7282 ! Remarked by Ning Pan, 2010-08-13
7283 ! Tmpv002 =Tmpv201(i)/tmpdz
7284 ! dthrdn(i,k,j) =Tmpv002
7288 DO i =i_end, i_start, -1
7291 a_Tmpv2 =a_dthrdn(i,k,j)
7292 a_dthrdn(i,k,j) =0.0
7293 a_Tmpv1 =a_Tmpv2/tmpdz
7294 a_tmpdz =a_tmpdz -Tmpv201(i)/(tmpdz*tmpdz)*a_Tmpv2
7295 a_theta(i,k+1,j) =a_theta(i,k+1,j) +a_Tmpv1
7296 a_thetasfc =a_thetasfc -a_Tmpv1
7299 a_T8w(i,kts,j) =a_T8w(i,kts,j) +a_Tmpv1/(p8w(i,k,j)/p1000mb)**(R_d/Cp)
7300 a_p8w(i,k,j) =a_p8w(i,k,j) -(R_d/Cp)*1.0/p1000mb*(p8w(i,k,j)/p1000mb) &
7301 **((R_d/Cp) -1)*T8w(i,kts,j)/((p8w(i,k,j)/p1000mb)**(R_d/Cp)*(p8w(i,k,j)/p1000mb) &
7304 !BIG ERRORS, ADDED BY WALLS
7305 !BIG ERRORS, ADDED BY WALLS
7306 !BIG ERRORS, ADDED BY WALLS
7307 Tmpv001 =(rdzw(i,k+1,j)+rdzw(i,k,j))
7311 a_Tmpv1 =-(1.0)*a_Tmpv2/(Tmpv001*Tmpv001)
7312 !hcl a_rdzw(i,k+1,j) =a_rdzw(i,k+1,j) +a_Tmpv1
7313 !hcl a_rdzw(i,k,j) =a_rdzw(i,k,j) +a_Tmpv1
7314 a_rdzw(i,k+1,j) =a_rdzw(i,k+1,j) - a_tmpv2/(rdzw(i,k+1,j)*rdzw(i,k+1,j))
7315 a_rdzw(i,k,j) =a_rdzw(i,k,j) - a_tmpv2/(rdzw(i,k,j)*rdzw(i,k,j))
7325 DO j =j_end, j_start, -1
7328 DO i =i_start, i_end
7329 tmpdz = 1.0/rdz(i,k+1,j) + 1.0/rdz(i,k,j)
7332 Tmpv001 =theta(i,k+1,j) -theta(i,k-1,j)
7333 Tmpv301(i,k) =Tmpv001
7334 ! Remarked by Ning Pan, 2010-08-13
7335 ! Tmpv002 =Tmpv301(i,k)/tmpdz
7336 ! dthrdn(i,k,j) =Tmpv002
7341 DO k =ktf-1, kts+1, -1
7342 DO i =i_end, i_start, -1
7345 a_Tmpv2 =a_dthrdn(i,k,j)
7346 a_dthrdn(i,k,j) =0.0
7347 a_Tmpv1 =a_Tmpv2/tmpdz
7348 a_tmpdz =a_tmpdz -Tmpv301(i,k)/(tmpdz*tmpdz)*a_Tmpv2
7349 a_theta(i,k+1,j) =a_theta(i,k+1,j) +a_Tmpv1
7350 a_theta(i,k-1,j) =a_theta(i,k-1,j) -a_Tmpv1
7352 !BIG ERRORS, ADDED BY WALLS
7353 !BIG ERRORS, ADDED BY WALLS
7354 !BIG ERRORS, ADDED BY WALLS
7355 Tmpv001 =(rdz(i,k+1,j)+rdz(i,k,j))
7359 a_Tmpv1 =-(1.0)*a_Tmpv2/(Tmpv001*Tmpv001)
7360 !hcl a_rdz(i,k+1,j) =a_rdz(i,k+1,j) +a_Tmpv1
7361 !hcl a_rdz(i,k,j) =a_rdz(i,k,j) +a_Tmpv1
7362 a_rdz(i,k+1,j) =a_rdz(i,k+1,j) - a_tmpv2/(rdz(i,k+1,j)*rdz(i,k+1,j))
7363 a_rdz(i,k,j) =a_rdz(i,k,j) - a_tmpv2/(rdz(i,k,j)*rdz(i,k,j))
7372 ! IF( (config_flags%tke_drag_coefficient .gt. epsilon) .or. (config_flags%tke_heat_flux .gt. epsilon) ) THEN
7376 ! IF( (config_flags%tke_drag_coefficient .gt. epsilon) .or. &
7377 ! (config_flags%tke_heat_flux .gt. epsilon) ) THEN
7382 ! c_k =config_flags%c_k
7384 ! tke_seed =tke_seed_value
7387 ! a_config_flags%c_k =a_config_flags%c_k +a_c_k
7392 ! IF( config_flags%periodic_x ) THEN
7393 ! i_end =min(ite, ide-1)
7396 ! IF( config_flags%periodic_x ) THEN
7404 ! IF( config_flags%periodic_x ) THEN
7408 ! IF( config_flags%periodic_x ) THEN
7416 ! IF( config_flags%open_ye .OR. config_flags%specified .OR. config_flags%nested) THEN
7417 ! j_end =min(jde-2, jte)
7420 ! IF( config_flags%open_ye .OR. config_flags%specified .OR. &
7421 ! config_flags%nested) THEN
7429 ! IF( config_flags%open_ys .OR. config_flags%specified .OR. config_flags%nested) THEN
7430 ! j_start =max(jds+1, jts)
7433 ! IF( config_flags%open_ys .OR. config_flags%specified .OR. &
7434 ! config_flags%nested) THEN
7442 ! IF( config_flags%open_xe .OR. config_flags%specified .OR. config_flags%nested) THEN
7443 ! i_end =min(ide-2, ite)
7446 ! IF( config_flags%open_xe .OR. config_flags%specified .OR. &
7447 ! config_flags%nested) THEN
7455 ! IF( config_flags%open_xs .OR. config_flags%specified .OR. config_flags%nested) THEN
7456 ! i_start =max(ids+1, its)
7459 ! IF( config_flags%open_xs .OR. config_flags%specified .OR. &
7460 ! config_flags%nested) THEN
7465 ! ktf =min(kte, kde-1)
7467 ! i_end =min(ite, ide-1)
7469 ! j_end =min(jte, jde-1)
7471 DEALLOCATE ( Tmpv200, Tmpv201, Tmpv300, Tmpv301, &
7473 Tmpv401, Tmpv402, Tmpv403, Tmpv404, Tmpv405, Tmpv406, Tmpv407, Tmpv408, Tmpv409, Tmpv4010, &
7474 Tmpv4011, Tmpv4012, Tmpv4013, Tmpv4014, Tmpv4015, Tmpv4016, Tmpv4017, Tmpv4018, Tmpv4019, Tmpv4020, &
7475 Tmpv4021, Tmpv4022, Tmpv4023, Tmpv4024, Tmpv4025, Tmpv4026, Tmpv4027, Tmpv4028, Tmpv4029, Tmpv4030, &
7478 END SUBROUTINE a_tke_km
7480 SUBROUTINE a_tke_rhs(tendency,a_tendency,BN2,a_BN2,config_flags,defor11, &
7481 a_defor11,defor22,a_defor22,defor33,a_defor33,defor12,a_defor12,defor13, &
7482 a_defor13,defor23,a_defor23,u,a_u,v,a_v,w,a_w,div,a_div,tke,a_tke,mu, &
7483 a_mu,c1,c2,theta,a_theta,p,a_p,p8w,a_p8w,t8w,a_t8w,z,a_z,fnm,fnp,cf1,cf2,cf3, &
7484 msftx,msfty,xkmh,a_xkmh,xkmv,a_xkmv,xkhv,a_xkhv,rdx,rdy,dx,dy,dt,zx,a_zx,zy, &
7485 a_zy,rdz,a_rdz,rdzw,a_rdzw,dn,dnw,isotropic,hfx,a_hfx,qfx,a_qfx,qv,a_qv, &
7486 ust,a_ust,rho,a_rho,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts, &
7489 !PART I: DECLARATION OF VARIABLES
7493 INTEGER :: K0_ADJ,K1_ADJ,K2_ADJ,K3_ADJ
7494 TYPE(grid_config_rec_type) :: config_flags
7495 INTEGER :: ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte
7496 INTEGER :: isotropic
7497 REAL :: cf1,cf2,cf3,dt,rdx,rdy,dx,dy
7498 REAL,DIMENSION(kms:kme) :: fnm,fnp,dnw,dn
7499 REAL,DIMENSION(ims:ime,jms:jme) :: msftx,msfty
7500 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: tendency,a_tendency
7501 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: defor11,a_defor11,defor22,a_defor22, &
7502 defor33,a_defor33,defor12,a_defor12,defor13,a_defor13,defor23,a_defor23,div, &
7503 a_div,BN2,a_BN2,tke,a_tke,xkmh,a_xkmh,xkmv,a_xkmv,xkhv,a_xkhv,zx,a_zx, &
7504 zy,a_zy,u,a_u,v,a_v,w,a_w,theta,a_theta,p,a_p,p8w,a_p8w,t8w,a_t8w,z, &
7505 a_z,rdz,a_rdz,rdzw,a_rdzw
7506 REAL,DIMENSION(ims:ime,jms:jme) :: mu,a_mu
7507 real, dimension(kms:kme) :: c1, c2
7508 REAL,DIMENSION(ims:ime,jms:jme) :: hfx,a_hfx,ust,a_ust,qfx,a_qfx
7509 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: qv,a_qv,rho,a_rho
7510 INTEGER :: i,j,k,ktf,i_start,i_end,j_start,j_end
7512 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: Keep_Lpb0_tendency
7513 INTEGER :: IX1,IX2,IX3
7515 REAL :: a_Tmpv1,Tmpv001,a_Tmpv2,Tmpv002,a_Tmpv3,Tmpv003
7516 REAL,DIMENSION(its:min(ite,ide-1),kts:min(kte,kde-1)) :: Tmpv300
7517 REAL,DIMENSION(its:min(ite,ide-1),kts:min(kte,kde-1)) :: Tmpv301
7518 REAL,DIMENSION(jms:jme,kms:kme,ims:ime) :: Tmpv400
7519 REAL,DIMENSION(jms:jme,kms:kme,ims:ime) :: Tmpv401
7520 REAL,DIMENSION(jms:jme,kms:kme,ims:ime) :: Tmpv402
7522 REAL, DIMENSION( ims:ime, kms:kme, jms:jme ) &
7523 :: tke_buoy_tend, tke_shear_tend
7525 REAL, DIMENSION( ims:ime, kms:kme, jms:jme ) &
7528 REAL, DIMENSION( ims:ime, kms:kme, jms:jme ) &
7531 REAL, DIMENSION( ims:ime, kms:kme, jms:jme ) &
7534 REAL, DIMENSION( ims:ime, jms:jme ) &
7537 !PART II: CALCULATIONS OF B. S. TRAJECTORY
7540 ! Remarked by Ning Pan, 2010-08-13
7544 ! Keep_Lpb0_tendency(IX1,IX2,IX3) =tendency(IX1,IX2,IX3)
7549 CALL tke_shear( tendency, config_flags, &
7550 defor11, defor22, defor33, &
7551 defor12, defor13, defor23, &
7552 u, v, w, tke, ust, mu, &
7554 cf1, cf2, cf3, msftx, msfty, &
7556 rdx, rdy, zx, zy, rdz, rdzw, dnw, dn, &
7557 ids, ide, jds, jde, kds, kde, &
7558 ims, ime, jms, jme, kms, kme, &
7559 its, ite, jts, jte, kts, kte )
7560 CALL tke_buoyancy( tendency, config_flags, mu, &
7562 tke, xkhv, BN2, theta, dt, &
7563 hfx, qfx, qv, rho, &
7565 ids, ide, jds, jde, kds, kde, &
7566 ims, ime, jms, jme, kms, kme, &
7567 its, ite, jts, jte, kts, kte )
7568 CALL tke_dissip( tendency, config_flags, mu, c1, c2, &
7569 tke, bn2, theta, p8w, t8w, z, &
7570 dx, dy,rdz, rdzw, isotropic, &
7572 hpbl, dlk, l_scale, &
7573 ids, ide, jds, jde, kds, kde, &
7574 ims, ime, jms, jme, kms, kme, &
7575 its, ite, jts, jte, kts, kte )
7576 ktf = MIN( kte, kde-1 )
7578 i_end = MIN( ite, ide-1 )
7580 j_end = MIN( jte, jde-1 )
7583 IF ( config_flags%open_xs .or. config_flags%specified .or. &
7584 config_flags%nested) i_start = MAX(ids+1,its)
7589 IF ( config_flags%open_xe .or. config_flags%specified .or. &
7590 config_flags%nested) i_end = MIN(ide-2,ite)
7595 IF ( config_flags%open_ys .or. config_flags%specified .or. &
7596 config_flags%nested) j_start = MAX(jds+1,jts)
7601 IF ( config_flags%open_ye .or. config_flags%specified .or. &
7602 config_flags%nested) j_end = MIN(jde-2,jte)
7607 IF ( config_flags%periodic_x ) i_start = its
7612 IF ( config_flags%periodic_x ) i_end = MIN( ite, ide-1 )
7615 ! DO j = j_start, j_end
7618 ! DO i = i_start, i_end
7619 ! tendency(i,k,j) = max( tendency(i,k,j), -mu(i,j) * max( 0.0 , tke(i,k,j) ) / dt )
7625 !PART IV: REVERSE/BACKWARD ACCUMULATIONS
7628 DO j =j_end, j_start, -1
7630 ! Remarks removed by Ning Pan, 2010-08-13
7632 DO i =i_start, i_end
7633 Tmpv001 =-mu(i,j)*max(0.0, tke(i,k,j))
7635 Tmpv300(i,k) =Tmpv002
7636 Tmpv301(i,k) =Tmpv300(i,k)
7637 ! Tmpv003 =max(tendency(i,k,j), Tmpv301(i,k))
7638 ! tendency(i,k,j) =Tmpv003
7640 ! Remarks removed by Ning Pan, 2010-08-13
7645 DO i =i_end, i_start, -1
7646 a_Tmpv3 =a_tendency(i,k,j)
7647 a_tendency(i,k,j) =0.0
7648 a_tendency(i,k,j) =a_tendency(i,k,j) +(1.0 +sign(1.0, tendency(i,k,j) &
7649 -Tmpv301(i,k)))*0.5*1.0*a_Tmpv3
7650 a_Tmpv2 =(1.0 -sign(1.0, tendency(i,k,j) -Tmpv301(i,k)))*0.5*a_Tmpv3
7652 a_mu(i,j) =a_mu(i,j) -max(0.0, tke(i,k,j))*a_Tmpv1
7653 a_tke(i,k,j) =a_tke(i,k,j) -mu(i,j)*(1.0 +(-1.0)*sign(1.0, 0.0 -tke(i,k,j))) &
7662 ! IF( config_flags%periodic_x ) THEN
7663 ! i_end =min(ite, ide-1)
7666 ! IF( config_flags%periodic_x ) THEN
7674 ! IF( config_flags%periodic_x ) THEN
7678 ! IF( config_flags%periodic_x ) THEN
7686 ! IF( config_flags%open_ye .or. config_flags%specified .or. config_flags%nested) THEN
7687 ! j_end =min(jde-2, jte)
7690 ! IF( config_flags%open_ye .or. config_flags%specified .or. &
7691 ! config_flags%nested) THEN
7699 ! IF( config_flags%open_ys .or. config_flags%specified .or. config_flags%nested) THEN
7700 ! j_start =max(jds+1, jts)
7703 ! IF( config_flags%open_ys .or. config_flags%specified .or. &
7704 ! config_flags%nested) THEN
7712 ! IF( config_flags%open_xe .or. config_flags%specified .or. config_flags%nested) THEN
7713 ! i_end =min(ide-2, ite)
7716 ! IF( config_flags%open_xe .or. config_flags%specified .or. &
7717 ! config_flags%nested) THEN
7725 ! IF( config_flags%open_xs .or. config_flags%specified .or. config_flags%nested) THEN
7726 ! i_start =max(ids+1, its)
7729 ! IF( config_flags%open_xs .or. config_flags%specified .or. &
7730 ! config_flags%nested) THEN
7735 ! Remarked by Ning Pan, 2010-08-13
7739 ! tendency(IX1,IX2,IX3) =Keep_Lpb0_tendency(IX1,IX2,IX3)
7747 ! Tmpv400(IX1,IX2,IX3) =tendency(IX1,IX2,IX3)
7752 ! CALL tke_shear(tendency,config_flags,defor11,defor22,defor33,defor12,defor13, &
7753 ! defor23,u,v,w,tke,ust,mu,fnm,fnp,cf1,cf2,cf3,msftx,msfty,xkmh,xkmv,rdx,rdy,zx,zy,rdz, &
7754 ! rdzw,dnw,dn,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
7759 ! Tmpv401(IX1,IX2,IX3) =tendency(IX1,IX2,IX3)
7764 ! CALL tke_buoyancy(tendency,config_flags,mu,tke,xkhv,BN2,theta,dt,hfx,qfx,qv,rho, &
7765 ! ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
7770 ! Tmpv402(IX1,IX2,IX3) =tendency(IX1,IX2,IX3)
7775 ! CALL tke_dissip(tendency,config_flags,mu,tke,bn2,theta,p8w,t8w,z,dx,dy,rdz,rdzw, &
7776 ! isotropic,msftx,msfty,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts, &
7779 ! ktf =min(kte, kde-1)
7781 ! i_end =min(ite, ide-1)
7783 ! j_end =min(jte, jde-1)
7788 ! tendency(IX1,IX2,IX3) =Tmpv402(IX1,IX2,IX3)
7793 CALL a_tke_dissip(tendency,a_tendency,config_flags,mu,a_mu,tke,a_tke,bn2, &
7794 a_bn2,theta,a_theta,p8w,a_p8w,t8w,a_t8w,z,a_z,dx,dy,rdz,a_rdz,rdzw, &
7795 a_rdzw,isotropic,msftx,msfty,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its, &
7796 ite,jts,jte,kts,kte)
7798 ! Remarked by Ning Pan, 2010-08-13
7802 ! tendency(IX1,IX2,IX3) =Tmpv401(IX1,IX2,IX3)
7807 CALL a_tke_buoyancy(tendency,a_tendency,config_flags,mu,a_mu,tke,a_tke, &
7808 xkhv,a_xkhv,BN2,a_BN2,theta,a_theta,dt,hfx,a_hfx,qfx,a_qfx,qv,a_qv,rho, &
7809 a_rho,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
7811 ! Remarked by Ning Pan, 2010-08-13
7815 ! tendency(IX1,IX2,IX3) =Tmpv400(IX1,IX2,IX3)
7820 CALL a_tke_shear(tendency,a_tendency,config_flags,defor11,a_defor11,defor22, &
7821 a_defor22,defor33,a_defor33,defor12,a_defor12,defor13,a_defor13,defor23, &
7822 a_defor23,u,a_u,v,a_v,w,a_w,tke,a_tke,ust,a_ust,mu,a_mu,fnm,fnp,cf1, &
7823 cf2,cf3,msftx,msfty,xkmh,a_xkmh,xkmv,a_xkmv,rdx,rdy,zx,a_zx,zy,a_zy,rdz, &
7824 a_rdz,rdzw,a_rdzw,dnw,dn,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite, &
7827 END SUBROUTINE a_tke_rhs
7829 SUBROUTINE a_calc_l_scale(config_flags,tke,a_tke,BN2,a_BN2,l_scale,a_l_scale, &
7830 i_start,i_end,ktf,j_start,j_end,dx,dy,rdzw,a_rdzw,msftx,msfty,ids,ide,jds,jde,kds, &
7831 kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
7833 !PART I: DECLARATION OF VARIABLES
7837 INTEGER :: K0_ADJ,K1_ADJ,K2_ADJ,K3_ADJ
7838 TYPE(grid_config_rec_type) :: config_flags
7839 INTEGER :: i_start,i_end,ktf,j_start,j_end,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme, &
7840 kms,kme,its,ite,jts,jte,kts,kte
7841 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: BN2,a_BN2,tke,a_tke,rdzw,a_rdzw
7843 REAL,DIMENSION(its:ite,kts:kte,jts:jte) :: l_scale,a_l_scale
7844 REAL,DIMENSION(ims:ime,jms:jme) :: msftx,msfty
7846 REAL :: deltas,a_deltas,tmp,a_tmp
7848 REAL :: a_Tmpv1,Tmpv001
7849 REAL,DIMENSION(i_start:i_end,kts:ktf) :: Tmpv300
7850 REAL,DIMENSION(i_start:i_end,kts:ktf) :: Tmpv301,Tmpv302,Tmpv303 ! Added by Ning Pan, 2010-08-12
7854 !PART II: CALCULATIONS OF B. S. TRAJECTORY
7857 ! DO j = j_start, j_end
7861 ! DO i = i_start, i_end
7862 ! deltas = ( dx/msftx(i,j) * dy/msfty(i,j) / rdzw(i,k,j) )**0.33333333
7863 ! l_scale(i,k,j) = deltas
7864 ! IF ( BN2(i,k,j) .gt. 1.0e-6 ) THEN
7866 ! tmp = SQRT( MAX( tke(i,k,j), 1.0e-6 ) )
7867 ! l_scale(i,k,j) = 0.76 * tmp / SQRT( BN2(i,k,j) )
7868 ! l_scale(i,k,j) = MIN( l_scale(i,k,j), deltas)
7869 ! l_scale(i,k,j) = MAX( l_scale(i,k,j), 0.001 * deltas )
7876 !PART III: INITIALIZATION OF LOCAL ADJOINT PERTURBATIONS
7881 !PART IV: REVERSE/BACKWARD ACCUMULATIONS
7884 DO j =j_end, j_start, -1
7887 DO i =i_start, i_end
7888 deltas =(dx/msftx(i,j)*dy/msfty(i,j)/rdzw(i,k,j))**0.33333333
7889 Tmpv301(i,k) = deltas ! Added by Ning Pan, 2010-08-13
7891 l_scale(i,k,j) =deltas
7893 IF( BN2(i,k,j) .gt. 1.0e-6 ) THEN
7894 ! Revised by Ning Pan, 2010-08-12
7896 ! tmp =sqrt(max(tke(i,k,j), 1.0e-6))
7897 tmp =sqrt(max(tke(i,k,j), 1.0e-6))
7900 Tmpv001 =0.76*tmp/sqrt(BN2(i,k,j))
7901 l_scale(i,k,j) =Tmpv001
7903 Tmpv302(i,k) = l_scale(i,k,j) ! Added by Ning Pan, 2010-08-12
7904 Tmpv001 =min(l_scale(i,k,j), deltas)
7905 l_scale(i,k,j) =Tmpv001
7907 ! Remarked by Ning Pan, 2010-08-13
7908 ! Tmpv001 =max(l_scale(i,k,j), 0.001*deltas)
7909 ! l_scale(i,k,j) =Tmpv001
7916 DO i =i_end, i_start, -1
7918 IF( BN2(i,k,j) .gt. 1.0e-6 ) THEN
7920 deltas = Tmpv301(i,k) ! Added by Ning Pan, 2010-08-13
7921 a_Tmpv1 =a_l_scale(i,k,j)
7922 a_l_scale(i,k,j) =0.0
7923 a_l_scale(i,k,j) =a_l_scale(i,k,j) +(1.0 +sign(1.0, l_scale(i,k,j) &
7924 -0.001*deltas))*0.5*1.0*a_Tmpv1
7925 a_deltas =a_deltas +(1.0 -sign(1.0, l_scale(i,k,j) -0.001*deltas))*0.5*0.001*a_Tmpv1
7926 l_scale(i,k,j) = Tmpv302(i,k) ! Added by Ning Pan, 2010-08-12
7927 a_Tmpv1 =a_l_scale(i,k,j)
7928 a_l_scale(i,k,j) =0.0
7929 a_l_scale(i,k,j) =a_l_scale(i,k,j) +(1.0 -sign(1.0, l_scale(i,k,j) -deltas)) &
7931 a_deltas =a_deltas +(1.0 +sign(1.0, l_scale(i,k,j) -deltas))*0.5*1.0*a_Tmpv1
7932 tmp =Tmpv300(i,k) ! Added by Ning Pan, 2010-08-12
7933 a_Tmpv1 =a_l_scale(i,k,j)
7934 a_l_scale(i,k,j) =0.0
7935 a_tmp =a_tmp +0.76/sqrt(BN2(i,k,j))*a_Tmpv1
7936 a_BN2(i,k,j) =a_BN2(i,k,j) -g_Sqrt(1.0, BN2(i,k,j))*0.76*tmp/(sqrt(BN2(i,k, &
7937 j))*sqrt(BN2(i,k,j)))*a_Tmpv1
7939 ! tmp =Tmpv300(i,k) ! Remarked by Ning Pan, 2010-08-12
7941 a_tke(i,k,j) =a_tke(i,k,j) +g_Sqrt((1.0 +(1.0)*sign(1.0, tke(i,k,j) &
7942 -1.0e-6))*0.5, max(tke(i,k,j), 1.0e-6))*a_tmp
7946 a_deltas =a_deltas +a_l_scale(i,k,j)
7947 a_l_scale(i,k,j) =0.0
7948 a_rdzw(i,k,j) =a_rdzw(i,k,j) -dx/msftx(i,j)*dy/msfty(i,j)/(rdzw(i,k,j) &
7949 *rdzw(i,k,j))*0.33333333*(dx/msftx(i,j)*dy/msfty(i,j)/rdzw(i,k,j))**(0.33333333 -1)*a_deltas
7956 END SUBROUTINE a_calc_l_scale
7958 SUBROUTINE a_tke_buoyancy(tendency,a_tendency,config_flags,mu,a_mu,tke,a_tke, &
7959 xkhv,a_xkhv,BN2,a_BN2,theta,a_theta,dt,hfx,a_hfx,qfx,a_qfx,qv,a_qv,rho, &
7960 a_rho,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
7962 !PART I: DECLARATION OF VARIABLES
7966 INTEGER :: K0_ADJ,K1_ADJ,K2_ADJ,K3_ADJ
7967 TYPE(grid_config_rec_type) :: config_flags
7968 INTEGER :: ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte
7970 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: tendency,a_tendency
7971 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: xkhv,a_xkhv,tke,a_tke,BN2,a_BN2, &
7973 REAL,DIMENSION(ims:ime,jms:jme) :: mu,a_mu
7974 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: qv,a_qv,rho,a_rho
7975 REAL,DIMENSION(ims:ime,jms:jme) :: hfx,a_hfx,qfx,a_qfx
7976 INTEGER :: i,j,k,ktf
7977 INTEGER :: i_start,i_end,j_start,j_end
7978 REAL :: heat_flux,a_heat_flux,heat_flux0,a_heat_flux0
7981 REAL :: a_Tmpv1,Tmpv001,a_Tmpv2,Tmpv002,a_Tmpv3,Tmpv003,a_Tmpv4,Tmpv004, &
7982 a_Tmpv5,Tmpv005,a_Tmpv6,Tmpv006
7983 REAL,DIMENSION(its:min(ite,ide-1),min0(kts+1,max(jds+1,jts)):max0(min(kte,kde-1) &
7984 ,min(jde-2,jte))) :: Tmpv300
7985 REAL,DIMENSION(its:min(ite,ide-1),max(jds+1,jts):min(jde-2,jte)) :: Tmpv301
7986 REAL,DIMENSION(its:min(ite,ide-1),max(jds+1,jts):min(jde-2,jte)) :: Tmpv302
7987 REAL,DIMENSION(its:min(ite,ide-1),max(jds+1,jts):min(jde-2,jte)) :: Tmpv303
7988 REAL,DIMENSION(its:min(ite,ide-1),max(jds+1,jts):min(jde-2,jte)) :: Tmpv304
7989 REAL,DIMENSION(its:min(ite,ide-1),max(jds+1,jts):min(jde-2,jte)) :: Tmpv305
7991 !PART II: CALCULATIONS OF B. S. TRAJECTORY
7994 ktf = MIN( kte, kde-1 )
7996 i_end = MIN( ite, ide-1 )
7998 j_end = MIN( jte, jde-1 )
8001 IF ( config_flags%open_xs .OR. config_flags%specified .OR. &
8002 config_flags%nested ) i_start = MAX( ids+1, its )
8007 IF ( config_flags%open_xe .OR. config_flags%specified .OR. &
8008 config_flags%nested ) i_end = MIN( ide-2, ite )
8013 IF ( config_flags%open_ys .OR. config_flags%specified .OR. &
8014 config_flags%nested ) j_start = MAX( jds+1, jts )
8019 IF ( config_flags%open_ye .OR. config_flags%specified .OR. &
8020 config_flags%nested ) j_end = MIN( jde-2, jte )
8025 IF ( config_flags%periodic_x ) i_start = its
8030 IF ( config_flags%periodic_x ) i_end = MIN( ite, ide-1 )
8033 DO j = j_start, j_end
8036 DO i = i_start, i_end
8037 tendency(i,k,j) = tendency(i,k,j) - mu(i,j) * xkhv(i,k,j) * BN2(i,k,j)
8046 ! hflux: SELECT CASE( config_flags%isfflx )
8049 ! heat_flux0 = config_flags%tke_heat_flux
8052 ! DO j = j_start, j_end
8053 ! DO i = i_start, i_end
8054 ! heat_flux = heat_flux0
8055 ! tendency(i,k,j)= tendency(i,k,j) - &
8056 ! mu(i,j)*((xkhv(i,k,j)*BN2(i,k,j))- (g/theta(i,k,j))*heat_flux)/2.
8062 ! DO j = j_start, j_end
8063 ! DO i = i_start, i_end
8064 ! cpm = cp * (1. + 0.8*qv(i,k,j))
8065 ! heat_flux = (hfx(i,j)/cpm)/rho(i,k,j)
8066 ! tendency(i,k,j)= tendency(i,k,j) - &
8067 ! mu(i,j)*((xkhv(i,k,j)*BN2(i,k,j))- (g/theta(i,k,j))*heat_flux)/2.
8071 ! CALL wrf_error_fatal( 'isfflx value invalid for diff_opt=2' )
8075 !PART III: INITIALIZATION OF LOCAL ADJOINT PERTURBATIONS
8078 ! a_heat_flux0 =0.0 ! Remarked by Ning Pan, 2010-08-12
8081 !PART IV: REVERSE/BACKWARD ACCUMULATIONS
8085 SELECT CASE (config_flags%isfflx)
8087 heat_flux0 =config_flags%tke_heat_flux
8090 DO j =j_start, j_end
8091 DO i =i_start, i_end
8092 ! Revised by Ning Pan, 2010-08-12
8093 ! Tmpv300(i,j) =heat_flux
8094 ! heat_flux =heat_flux0
8095 heat_flux =heat_flux0
8096 Tmpv300(i,j) =heat_flux
8098 Tmpv001 =xkhv(i,k,j)*BN2(i,k,j)
8099 Tmpv002 =(g/theta(i,k,j))*heat_flux
8100 Tmpv003 =Tmpv001 -Tmpv002
8101 Tmpv301(i,j) =Tmpv003
8102 ! Remarked by Ning Pan, 2010-08-12
8103 ! Tmpv004 =mu(i,j)*Tmpv301(i,j)
8104 ! Tmpv005 =Tmpv004/2.
8105 ! Tmpv006 =tendency(i,k,j) -Tmpv005
8106 ! tendency(i,k,j) =Tmpv006
8112 DO j =j_start, j_end
8113 DO i =i_start, i_end
8114 ! Revised by Ning Pan, 2010-08-12
8116 ! cpm =cp*(1. +0.8*qv(i,k,j))
8117 cpm =cp*(1. +0.8*qv(i,k,j))
8120 Tmpv001 =hfx(i,j)/cpm
8121 Tmpv303(i,j) =Tmpv001
8122 Tmpv002 =Tmpv303(i,j)/rho(i,k,j)
8123 ! Revised by Ning Pan, 2010-08-12
8124 ! Tmpv304(i,j) =heat_flux
8125 ! heat_flux =Tmpv002
8127 Tmpv304(i,j) =heat_flux
8129 Tmpv001 =xkhv(i,k,j)*BN2(i,k,j)
8130 Tmpv002 =(g/theta(i,k,j))*heat_flux
8131 Tmpv003 =Tmpv001 -Tmpv002
8132 Tmpv305(i,j) =Tmpv003
8133 Tmpv004 =mu(i,j)*Tmpv305(i,j)
8135 Tmpv006 =tendency(i,k,j) -Tmpv005
8136 tendency(i,k,j) =Tmpv006
8141 CALL wrf_error_fatal('isfflx value invalid for diff_opt=2')
8143 ! Revised by Ning Pan, 2010-08-12
8147 SELECT CASE (config_flags%isfflx)
8151 DO j =j_end, j_start, -1
8152 DO i =i_end, i_start, -1
8153 heat_flux =Tmpv300(i,j) ! Added by Ning Pan, 2010-08-12
8154 a_Tmpv6 =a_tendency(i,k,j)
8155 a_tendency(i,k,j) =0.0
8156 a_tendency(i,k,j) =a_tendency(i,k,j) +a_Tmpv6
8159 a_mu(i,j) =a_mu(i,j) +Tmpv301(i,j)*a_Tmpv4
8160 a_Tmpv3 =mu(i,j)*a_Tmpv4
8163 a_theta(i,k,j) =a_theta(i,k,j) -g/(theta(i,k,j)*theta(i,k,j))*heat_flux*a_Tmpv2
8164 a_heat_flux =a_heat_flux +(g/theta(i,k,j))*a_Tmpv2
8165 a_xkhv(i,k,j) =a_xkhv(i,k,j) +BN2(i,k,j)*a_Tmpv1
8166 a_BN2(i,k,j) =a_BN2(i,k,j) +xkhv(i,k,j)*a_Tmpv1
8168 ! heat_flux =Tmpv300(i,j) ! Remarked by Ning Pan, 2010-08-12
8170 ! a_heat_flux0 =a_heat_flux0 +a_heat_flux ! Remarked by Ning Pan, 2010-08-12
8174 ! Remarked by Ning Pan, 2010-08-12
8175 ! a_config_flags%tke_heat_flux =a_config_flags%tke_heat_flux +a_heat_flux0
8180 DO j =j_end, j_start, -1
8181 DO i =i_end, i_start, -1
8182 ! Added by Ning Pan, 2010-08-12
8184 heat_flux =Tmpv304(i,j)
8186 a_Tmpv6 =a_tendency(i,k,j)
8187 a_tendency(i,k,j) =0.0
8188 a_tendency(i,k,j) =a_tendency(i,k,j) +a_Tmpv6
8191 a_mu(i,j) =a_mu(i,j) +Tmpv305(i,j)*a_Tmpv4
8192 a_Tmpv3 =mu(i,j)*a_Tmpv4
8195 a_theta(i,k,j) =a_theta(i,k,j) -g/(theta(i,k,j)*theta(i,k,j))*heat_flux*a_Tmpv2
8196 a_heat_flux =a_heat_flux +(g/theta(i,k,j))*a_Tmpv2
8197 a_xkhv(i,k,j) =a_xkhv(i,k,j) +BN2(i,k,j)*a_Tmpv1
8198 a_BN2(i,k,j) =a_BN2(i,k,j) +xkhv(i,k,j)*a_Tmpv1
8200 ! heat_flux =Tmpv304(i,j) ! Remarked by Ning Pan, 2010-08-12
8202 a_Tmpv2 =a_heat_flux
8204 a_Tmpv1 =a_Tmpv2/rho(i,k,j)
8205 a_rho(i,k,j) =a_rho(i,k,j) -Tmpv303(i,j)/(rho(i,k,j)*rho(i,k,j))*a_Tmpv2
8206 a_hfx(i,j) =a_hfx(i,j) +a_Tmpv1/cpm
8207 a_cpm =a_cpm -hfx(i,j)/(cpm*cpm)*a_Tmpv1
8209 ! cpm =Tmpv302(i,j) ! Remarked by Ning Pan, 2010-08-12
8211 a_qv(i,k,j) =a_qv(i,k,j) +cp*0.8*a_cpm
8218 ! Revised by Ning Pan, 2010-08-12
8219 ! CALL a_wrf_error_fatal('isfflx value invalid for diff_opt=2')
8220 CALL wrf_error_fatal('isfflx value invalid for diff_opt=2')
8222 ! Revised by Ning Pan, 2010-08-12
8229 DO j =j_end, j_start, -1
8232 DO i =i_start, i_end
8233 Tmpv001 =mu(i,j)*xkhv(i,k,j)
8234 Tmpv300(i,k) =Tmpv001
8235 ! Remarked by Ning Pan, 2010-08-12
8236 ! Tmpv002 =Tmpv300(i,k)*BN2(i,k,j)
8237 ! Tmpv003 =tendency(i,k,j) -Tmpv002
8238 ! tendency(i,k,j) =Tmpv003
8243 DO k =ktf, kts+1, -1
8244 DO i =i_end, i_start, -1
8245 a_Tmpv3 =a_tendency(i,k,j)
8246 a_tendency(i,k,j) =0.0
8247 a_tendency(i,k,j) =a_tendency(i,k,j) +a_Tmpv3
8249 a_Tmpv1 =BN2(i,k,j)*a_Tmpv2
8250 a_BN2(i,k,j) =a_BN2(i,k,j) +Tmpv300(i,k)*a_Tmpv2
8251 a_mu(i,j) =a_mu(i,j) +xkhv(i,k,j)*a_Tmpv1
8252 a_xkhv(i,k,j) =a_xkhv(i,k,j) +mu(i,j)*a_Tmpv1
8260 ! IF( config_flags%periodic_x ) THEN
8261 ! i_end =min(ite, ide-1)
8264 ! IF( config_flags%periodic_x ) THEN
8272 ! IF( config_flags%periodic_x ) THEN
8276 ! IF( config_flags%periodic_x ) THEN
8284 ! IF( config_flags%open_ye .OR. config_flags%specified .OR. config_flags%nested ) THEN
8285 ! j_end =min(jde-2, jte)
8288 ! IF( config_flags%open_ye .OR. config_flags%specified .OR. &
8289 ! config_flags%nested ) THEN
8297 ! IF( config_flags%open_ys .OR. config_flags%specified .OR. config_flags%nested ) THEN
8298 ! j_start =max(jds+1, jts)
8301 ! IF( config_flags%open_ys .OR. config_flags%specified .OR. &
8302 ! config_flags%nested ) THEN
8310 ! IF( config_flags%open_xe .OR. config_flags%specified .OR. config_flags%nested ) THEN
8311 ! i_end =min(ide-2, ite)
8314 ! IF( config_flags%open_xe .OR. config_flags%specified .OR. &
8315 ! config_flags%nested ) THEN
8323 ! IF( config_flags%open_xs .OR. config_flags%specified .OR. config_flags%nested ) THEN
8324 ! i_start =max(ids+1, its)
8327 ! IF( config_flags%open_xs .OR. config_flags%specified .OR. &
8328 ! config_flags%nested ) THEN
8333 ! ktf =min(kte, kde-1)
8335 ! i_end =min(ite, ide-1)
8337 ! j_end =min(jte, jde-1)
8339 END SUBROUTINE a_tke_buoyancy
8341 SUBROUTINE a_tke_dissip(tendency,a_tendency,config_flags,mu,a_mu,tke,a_tke, &
8342 bn2,a_bn2,theta,a_theta,p8w,a_p8w,t8w,a_t8w,z,a_z,dx,dy,rdz,a_rdz,rdzw, &
8343 a_rdzw,isotropic,msftx,msfty,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its, &
8344 ite,jts,jte,kts,kte)
8346 !PART I: DECLARATION OF VARIABLES
8350 INTEGER :: K0_ADJ,K1_ADJ,K2_ADJ,K3_ADJ
8351 TYPE(grid_config_rec_type) :: config_flags
8352 INTEGER :: ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte
8353 INTEGER :: isotropic
8355 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: tendency,a_tendency
8356 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: tke,a_tke,bn2,a_bn2,theta,a_theta, &
8357 p8w,a_p8w,t8w,a_t8w,z,a_z,rdz,a_rdz,rdzw,a_rdzw
8358 REAL,DIMENSION(ims:ime,jms:jme) :: mu,a_mu
8359 REAL,DIMENSION(ims:ime,jms:jme) :: msftx,msfty
8360 REAL,DIMENSION(its:ite,kts:kte,jts:jte) :: dthrdn,a_dthrdn
8361 REAL,DIMENSION(its:ite,kts:kte,jts:jte) :: l_scale,a_l_scale
8362 REAL,DIMENSION(its:ite) :: sumtke,a_sumtke,sumtkez,a_sumtkez
8363 INTEGER :: i,j,k,ktf,i_start,i_end,j_start,j_end
8364 REAL :: disp_len,a_disp_len,deltas,a_deltas,coefc,a_coefc,tmpdz,a_tmpdz, &
8365 len_s,a_len_s,thetasfc,a_thetasfc,thetatop,a_thetatop,len_0,a_len_0,tketmp, &
8366 a_tketmp,tmp,a_tmp,ce1,a_ce1,ce2,a_ce2,c_k,a_c_k
8368 REAL :: a_Tmpv1,Tmpv001,a_Tmpv2,Tmpv002,a_Tmpv3,Tmpv003,a_Tmpv4,Tmpv004
8369 REAL,DIMENSION(its:min(ite,ide-1),kts:min(kte,kde-1)) :: Tmpv300
8370 REAL,DIMENSION(its:min(ite,ide-1),kts:min(kte,kde-1)) :: Tmpv301
8371 REAL,DIMENSION(its:min(ite,ide-1),kts:min(kte,kde-1)) :: Tmpv302
8372 REAL,DIMENSION(its:min(ite,ide-1),kts:min(kte,kde-1)) :: Tmpv303
8373 REAL,DIMENSION(its:min(ite,ide-1),kts:min(kte,kde-1)) :: Tmpv304
8374 REAL,DIMENSION(its:min(ite,ide-1),kts:min(kte,kde-1)) :: Tmpv305
8375 REAL,DIMENSION(its:min(ite,ide-1),kts:min(kte,kde-1)) :: Tmpv306
8377 !PART II: CALCULATIONS OF B. S. TRAJECTORY
8380 c_k = config_flags%c_k
8381 ce1 = ( c_k / 0.10 ) * 0.19
8382 ce2 = max( 0.0 , 0.93 - ce1 )
8383 ktf = MIN( kte, kde-1 )
8385 i_end = MIN(ite,ide-1)
8387 j_end = MIN(jte,jde-1)
8390 IF ( config_flags%open_xs .OR. config_flags%specified .OR. &
8391 config_flags%nested) i_start = MAX( ids+1, its )
8396 IF ( config_flags%open_xe .OR. config_flags%specified .OR. &
8397 config_flags%nested) i_end = MIN( ide-2, ite )
8402 IF ( config_flags%open_ys .OR. config_flags%specified .OR. &
8403 config_flags%nested) j_start = MAX( jds+1, jts )
8408 IF ( config_flags%open_ye .OR. config_flags%specified .OR. &
8409 config_flags%nested) j_end = MIN( jde-2, jte )
8414 IF ( config_flags%periodic_x ) i_start = its
8419 IF ( config_flags%periodic_x ) i_end = MIN( ite, ide-1 )
8422 CALL calc_l_scale( config_flags, tke, BN2, l_scale, &
8423 i_start, i_end, ktf, j_start, j_end, &
8424 dx, dy, rdzw, msftx, msfty, &
8425 ids, ide, jds, jde, kds, kde, &
8426 ims, ime, jms, jme, kms, kme, &
8427 its, ite, jts, jte, kts, kte )
8430 ! DO j = j_start, j_end
8433 ! DO i = i_start, i_end
8434 ! deltas = ( dx/msftx(i,j) * dy/msfty(i,j) / rdzw(i,k,j) )**0.33333333
8435 ! tketmp = MAX( tke(i,k,j), 1.0e-6 )
8436 ! IF ( k .eq. kts .or. k .eq. ktf ) then
8440 ! coefc = ce1 + ce2 * l_scale(i,k,j) / deltas
8442 ! tendency(i,k,j) = tendency(i,k,j) - &
8443 ! mu(i,j) * coefc * tketmp**1.5 / l_scale(i,k,j)
8449 !PART III: INITIALIZATION OF LOCAL ADJOINT PERTURBATIONS
8451 ! Remarked by Ning Pan, 2010-08-12
8452 ! Do K2_ADJ =jts, jte
8453 ! Do K1_ADJ =kts, kte
8454 ! Do K0_ADJ =its, ite
8455 ! a_dthrdn(K0_ADJ,K1_ADJ,K2_ADJ) =0.0
8463 a_l_scale(K0_ADJ,K1_ADJ,K2_ADJ) =0.0
8468 ! Remarked by Ning Pan, 2010-08-12
8469 ! Do K0_ADJ =its, ite
8470 ! a_sumtke(K0_ADJ) =0.0
8473 ! Do K0_ADJ =its, ite
8474 ! a_sumtkez(K0_ADJ) =0.0
8480 ! Remarked by Ning Pan, 2010-08-12
8487 ! Remarked by Ning Pan, 2010-08-12
8493 !PART IV: REVERSE/BACKWARD ACCUMULATIONS
8496 DO j =j_end, j_start, -1
8498 ! Revised by Ning Pan, 2010-08-12
8500 ! DO i =i_start, i_end
8502 DO i =i_end, i_start, -1
8503 ! Tmpv300(i,k) =deltas
8504 deltas =(dx/msftx(i,j)*dy/msfty(i,j)/rdzw(i,k,j))**0.33333333
8506 ! Tmpv301(i,k) =tketmp
8507 tketmp =max(tke(i,k,j), 1.0e-6)
8509 IF( k .eq. kts .or. k .eq. ktf ) THEN
8510 ! Tmpv302(i,k) =coefc
8514 Tmpv001 =ce2*l_scale(i,k,j)
8515 Tmpv303(i,k) =Tmpv001
8516 Tmpv002 =Tmpv303(i,k)/deltas
8517 Tmpv003 =ce1 +Tmpv002
8518 ! Tmpv304(i,k) =coefc
8522 Tmpv001 =mu(i,j)*coefc
8523 Tmpv305(i,k) =Tmpv001
8524 Tmpv002 =Tmpv305(i,k)*tketmp**1.5
8525 Tmpv306(i,k) =Tmpv002
8526 ! Remarked by Ning Pan, 2010-08-12
8527 ! Tmpv003 =Tmpv306(i,k)/l_scale(i,k,j)
8528 ! Tmpv004 =tendency(i,k,j) -Tmpv003
8529 ! tendency(i,k,j) =Tmpv004
8531 ! Remarked by Ning Pan, 2010-08-12
8535 ! Remarked by Ning Pan, 2010-08-12
8536 ! DO k =ktf, kts, -1
8537 ! DO i =i_end, i_start, -1
8538 a_Tmpv4 =a_tendency(i,k,j)
8539 a_tendency(i,k,j) =0.0
8540 a_tendency(i,k,j) =a_tendency(i,k,j) +a_Tmpv4
8542 a_Tmpv2 =a_Tmpv3/l_scale(i,k,j)
8543 a_l_scale(i,k,j) =a_l_scale(i,k,j) -Tmpv306(i,k)/(l_scale(i,k,j) &
8544 *l_scale(i,k,j))*a_Tmpv3
8545 a_Tmpv1 =tketmp**1.5*a_Tmpv2
8546 a_tketmp =a_tketmp +1.5*1.0*tketmp**(1.5 -1)*Tmpv305(i,k)*a_Tmpv2
8547 a_mu(i,j) =a_mu(i,j) +coefc*a_Tmpv1
8548 a_coefc =a_coefc +mu(i,j)*a_Tmpv1
8550 IF( k .eq. kts .or. k .eq. ktf ) THEN
8552 ! coefc =Tmpv302(i,k)
8558 ! coefc =Tmpv304(i,k)
8562 ! a_ce1 =a_ce1 +a_Tmpv3 ! Remarked by Ning Pan, 2010-08-12
8564 a_Tmpv1 =a_Tmpv2/deltas
8565 a_deltas =a_deltas -Tmpv303(i,k)/(deltas*deltas)*a_Tmpv2
8566 ! a_ce2 =a_ce2 +l_scale(i,k,j)*a_Tmpv1 ! Remarked by Ning Pan, 2010-08-12
8567 a_l_scale(i,k,j) =a_l_scale(i,k,j) +ce2*a_Tmpv1
8571 ! tketmp =Tmpv301(i,k)
8573 a_tke(i,k,j) =a_tke(i,k,j) +(1.0 +(1.0)*sign(1.0, tke(i,k,j) -1.0e-6))*0.5*a_tketmp
8576 ! deltas =Tmpv300(i,k)
8578 a_rdzw(i,k,j) =a_rdzw(i,k,j) -dx/msftx(i,j)*dy/msfty(i,j)/(rdzw(i,k,j) &
8579 *rdzw(i,k,j))*0.33333333*(dx/msftx(i,j)*dy/msfty(i,j)/rdzw(i,k,j))**(0.33333333 -1)*a_deltas
8587 ! CALL calc_l_scale(config_flags,tke,BN2,l_scale,i_start,i_end,ktf,j_start,j_end,dx, &
8588 ! dy,rdzw,msftx,msfty,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
8590 CALL a_calc_l_scale(config_flags,tke,a_tke,BN2,a_BN2,l_scale,a_l_scale, &
8591 i_start,i_end,ktf,j_start,j_end,dx,dy,rdzw,a_rdzw,msftx,msfty,ids,ide,jds,jde,kds, &
8592 kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
8596 ! IF( config_flags%periodic_x ) THEN
8597 ! i_end =min(ite, ide-1)
8600 ! IF( config_flags%periodic_x ) THEN
8608 ! IF( config_flags%periodic_x ) THEN
8612 ! IF( config_flags%periodic_x ) THEN
8620 ! IF( config_flags%open_ye .OR. config_flags%specified .OR. config_flags%nested) THEN
8621 ! j_end =min(jde-2, jte)
8624 ! IF( config_flags%open_ye .OR. config_flags%specified .OR. &
8625 ! config_flags%nested) THEN
8633 ! IF( config_flags%open_ys .OR. config_flags%specified .OR. config_flags%nested) THEN
8634 ! j_start =max(jds+1, jts)
8637 ! IF( config_flags%open_ys .OR. config_flags%specified .OR. &
8638 ! config_flags%nested) THEN
8646 ! IF( config_flags%open_xe .OR. config_flags%specified .OR. config_flags%nested) THEN
8647 ! i_end =min(ide-2, ite)
8650 ! IF( config_flags%open_xe .OR. config_flags%specified .OR. &
8651 ! config_flags%nested) THEN
8659 ! IF( config_flags%open_xs .OR. config_flags%specified .OR. config_flags%nested) THEN
8660 ! i_start =max(ids+1, its)
8663 ! IF( config_flags%open_xs .OR. config_flags%specified .OR. &
8664 ! config_flags%nested) THEN
8669 ! c_k =config_flags%c_k
8671 ! ce1 =(c_k/0.10)*0.19
8673 ! ce2 =max(0.0, 0.93 -ce1)
8675 ! ktf =min(kte, kde-1)
8677 ! i_end =min(ite, ide-1)
8679 ! j_end =min(jte, jde-1)
8681 ! Remarked by Ning Pan, 2010-08-12
8682 ! a_ce1 =a_ce1 +(-1.0 +(--1.0)*sign(1.0, 0.0 -0.93 -ce1))*0.5*a_ce2
8684 ! a_c_k =a_c_k +1.0/0.10*0.19*a_ce1
8686 ! a_config_flags%c_k =a_config_flags%c_k +a_c_k
8689 END SUBROUTINE a_tke_dissip
8691 SUBROUTINE a_tke_shear(tendency,a_tendency,config_flags,defor11,a_defor11, &
8692 defor22,a_defor22,defor33,a_defor33,defor12,a_defor12,defor13,a_defor13, &
8693 defor23,a_defor23,u,a_u,v,a_v,w,a_w,tke,a_tke,ust,a_ust,mu,a_mu,fnm, &
8694 fnp,cf1,cf2,cf3,msftx,msfty,xkmh,a_xkmh,xkmv,a_xkmv,rdx,rdy,zx,a_zx,zy,a_zy, &
8695 rdz,a_rdz,rdzw,a_rdzw,dn,dnw,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its, &
8696 ite,jts,jte,kts,kte)
8698 !PART I: DECLARATION OF VARIABLES
8702 INTEGER :: K0_ADJ,K1_ADJ,K2_ADJ,K3_ADJ
8703 TYPE(grid_config_rec_type) :: config_flags
8704 INTEGER :: ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte
8705 REAL :: cf1,cf2,cf3,rdx,rdy
8706 REAL,DIMENSION(kms:kme) :: fnm,fnp,dn,dnw
8707 REAL,DIMENSION(ims:ime,jms:jme) :: msftx,msfty
8708 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: tendency,a_tendency
8709 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: defor11,a_defor11,defor22,a_defor22, &
8710 defor33,a_defor33,defor12,a_defor12,defor13,a_defor13,defor23,a_defor23,tke, &
8711 a_tke,xkmh,a_xkmh,xkmv,a_xkmv,zx,a_zx,zy,a_zy,u,a_u,v,a_v,w,a_w,rdz, &
8713 REAL,DIMENSION(ims:ime,jms:jme) :: mu,a_mu
8714 REAL,DIMENSION(ims:ime,jms:jme) :: ust,a_ust
8715 INTEGER :: i,j,k,ktf,ktes1,ktes2,i_start,i_end,j_start,j_end,is_ext,ie_ext,js_ext,je_ext
8717 REAL,DIMENSION(its-1:ite+1,kts:kte,jts-1:jte+1) :: avg,a_avg,titau,a_titau,tmp2,a_tmp2
8718 REAL,DIMENSION(its:ite,kts:kte,jts:jte) :: titau12,a_titau12,tmp1,a_tmp1,zxavg, &
8719 a_zxavg,zyavg,a_zyavg
8720 REAL :: absU,a_absU,cd0,a_cd0,Cd,a_Cd
8722 ! REAL,DIMENSION(1) :: Keep_Lpb29_absU
8723 ! REAL,DIMENSION(1) :: Keep_Lpb29_Cd
8724 REAL :: a_Tmpv1,Tmpv001,a_Tmpv2,Tmpv002,a_Tmpv3,Tmpv003,a_Tmpv4,Tmpv004, &
8725 a_Tmpv5,Tmpv005,a_Tmpv6,Tmpv006,a_Tmpv7,Tmpv007,a_Tmpv8,Tmpv008,a_Tmpv9,Tmpv009
8726 REAL,DIMENSION(its:min(ite,ide-1),min0(kts,max(jds+1,jts)):max0(min(kte,kde-1) &
8727 ,min(jde-2,jte))) :: Tmpv300
8728 REAL,DIMENSION(its:min(ite,ide-1),max(jds+1,jts):min(jde-2,jte)) :: Tmpv301
8729 REAL,DIMENSION(its:min(ite,ide-1),max(jds+1,jts):min(jde-2,jte)) :: Tmpv302
8730 REAL,DIMENSION(its:min(ite,ide-1),max(jds+1,jts):min(jde-2,jte)) :: Tmpv303
8731 REAL,DIMENSION(its:min(ite,ide-1),max(jds+1,jts):min(jde-2,jte)) :: Tmpv304
8732 REAL,DIMENSION(its:min(ite,ide-1),max(jds+1,jts):min(jde-2,jte)) :: Tmpv305
8733 REAL,DIMENSION(its:min(ite,ide-1),max(jds+1,jts):min(jde-2,jte)) :: Tmpv306
8734 REAL,DIMENSION(its:min(ite,ide-1),max(jds+1,jts):min(jde-2,jte)) :: Tmpv307
8735 REAL,DIMENSION(its:min(ite,ide-1),max(jds+1,jts):min(jde-2,jte)) :: Tmpv308
8736 REAL,DIMENSION(its:min(ite,ide-1),max(jds+1,jts):min(jde-2,jte)) :: Tmpv309
8737 REAL,DIMENSION(its:min(ite,ide-1),max(jds+1,jts):min(jde-2,jte)) :: Tmpv3010
8738 REAL,DIMENSION(its:min(ite,ide-1),max(jds+1,jts):min(jde-2,jte)) :: Tmpv3011
8739 REAL,DIMENSION(its:min(ite,ide-1),max(jds+1,jts):min(jde-2,jte)) :: Tmpv3012
8740 REAL,DIMENSION(its:min(ite,ide-1),max(jds+1,jts):min(jde-2,jte)) :: Tmpv3013
8741 REAL,DIMENSION(its:min(ite,ide-1),max(jds+1,jts):min(jde-2,jte)) :: Tmpv3014
8742 REAL,DIMENSION(its:min(ite,ide-1),max(jds+1,jts):min(jde-2,jte)) :: Tmpv3015
8743 REAL,DIMENSION(its:min(ite,ide-1),max(jds+1,jts):min(jde-2,jte)) :: Tmpv3016
8744 REAL,DIMENSION(its:min(ite,ide-1),max(jds+1,jts):min(jde-2,jte)) :: Tmpv3017
8745 REAL,DIMENSION(its:min(ite,ide-1),max(jds+1,jts):min(jde-2,jte)) :: Tmpv3018
8746 REAL,DIMENSION(its:min(ite,ide-1),max(jds+1,jts):min(jde-2,jte)) :: Tmpv3019
8750 !PART II: CALCULATIONS OF B. S. TRAJECTORY
8753 ktf = MIN( kte, kde-1 )
8757 i_end = MIN( ite, ide-1 )
8759 j_end = MIN( jte, jde-1 )
8762 IF ( config_flags%open_xs .OR. config_flags%specified .OR. &
8763 config_flags%nested ) i_start = MAX( ids+1, its )
8768 IF ( config_flags%open_xe .OR. config_flags%specified .OR. &
8769 config_flags%nested ) i_end = MIN( ide-2, ite )
8774 IF ( config_flags%open_ys .OR. config_flags%specified .OR. &
8775 config_flags%nested ) j_start = MAX( jds+1, jts )
8780 IF ( config_flags%open_ye .OR. config_flags%specified .OR. &
8781 config_flags%nested ) j_end = MIN( jde-2, jte )
8786 IF ( config_flags%periodic_x ) i_start = its
8791 IF ( config_flags%periodic_x ) i_end = MIN( ite, ide-1 )
8793 ! Remarked by Ning Pan, 2010-08-12 : LPB[12]-[28]
8795 ! DO j = j_start, j_end
8798 ! DO i = i_start, i_end
8799 ! zxavg(i,k,j) = 0.25 * ( zx(i,k ,j) + zx(i+1,k ,j) + &
8800 ! zx(i,k+1,j) + zx(i+1,k+1,j) )
8801 ! zyavg(i,k,j) = 0.25 * ( zy(i,k ,j) + zy(i,k ,j+1) + &
8802 ! zy(i,k+1,j) + zy(i,k+1,j+1) )
8809 ! DO j = j_start, j_end
8812 ! DO i = i_start, i_end
8813 ! tendency(i,k,j) = tendency(i,k,j) + 0.5 * &
8814 ! mu(i,j) * xkmh(i,k,j) * ( ( defor11(i,k,j) )**2 )
8821 ! DO j = j_start, j_end
8824 ! DO i = i_start, i_end
8825 ! tendency(i,k,j) = tendency(i,k,j) + 0.5 * &
8826 ! mu(i,j) * xkmh(i,k,j) * ( ( defor22(i,k,j) )**2 )
8833 ! DO j = j_start, j_end
8836 ! DO i = i_start, i_end
8837 ! tendency(i,k,j) = tendency(i,k,j) + 0.5 * &
8838 ! mu(i,j) * xkmv(i,k,j) * ( ( defor33(i,k,j) )**2 )
8845 ! DO j = j_start, j_end
8848 ! DO i = i_start, i_end
8849 ! avg(i,k,j) = 0.25 * &
8850 ! ( ( defor12(i ,k,j)**2 ) + ( defor12(i ,k,j+1)**2 ) + &
8851 ! ( defor12(i+1,k,j)**2 ) + ( defor12(i+1,k,j+1)**2 ) )
8858 ! DO j = j_start, j_end
8861 ! DO i = i_start, i_end
8862 ! tendency(i,k,j) = tendency(i,k,j) + mu(i,j) * xkmh(i,k,j) * avg(i,k,j)
8869 ! DO j = j_start, j_end
8872 ! DO i = i_start, i_end+1
8873 ! tmp2(i,k,j) = defor13(i,k,j)
8880 ! DO j = j_start, j_end
8882 ! DO i = i_start, i_end+1
8883 ! tmp2(i,kts ,j) = 0.0
8884 ! tmp2(i,ktf+1,j) = 0.0
8890 ! DO j = j_start, j_end
8893 ! DO i = i_start, i_end
8894 ! avg(i,k,j) = 0.25 * &
8895 ! ( ( tmp2(i ,k+1,j)**2 ) + ( tmp2(i ,k,j)**2 ) + &
8896 ! ( tmp2(i+1,k+1,j)**2 ) + ( tmp2(i+1,k,j)**2 ) )
8903 ! DO j = j_start, j_end
8906 ! DO i = i_start, i_end
8907 ! tendency(i,k,j) = tendency(i,k,j) + mu(i,j) * xkmv(i,k,j) * avg(i,k,j)
8917 ! uflux: SELECT CASE( config_flags%isfflx )
8920 ! cd0 = config_flags%tke_drag_coefficient
8922 ! DO j = j_start, j_end
8923 ! DO i = i_start, i_end
8924 ! absU=0.5*sqrt((u(i,k,j)+u(i+1,k,j))**2+(v(i,k,j)+v(i,k,j+1))**2)
8926 ! tendency(i,k,j) = tendency(i,k,j) + &
8927 ! mu(i,j)*( (u(i,k,j)+u(i+1,k,j))*0.5* &
8928 ! Cd*absU*(defor13(i,kts+1,j)+defor13(i+1,kts+1,j))*0.5 )
8933 ! DO j = j_start, j_end
8934 ! DO i = i_start, i_end
8935 ! absU=0.5*sqrt((u(i,k,j)+u(i+1,k,j))**2+(v(i,k,j)+v(i,k,j+1))**2)+epsilon
8936 ! Cd = (ust(i,j)**2)/(absU**2)
8937 ! tendency(i,k,j) = tendency(i,k,j) + &
8938 ! mu(i,j)*( (u(i,k,j)+u(i+1,k,j))*0.5* &
8939 ! Cd*absU*(defor13(i,kts+1,j)+defor13(i+1,kts+1,j))*0.5 )
8943 ! CALL wrf_error_fatal( 'isfflx value invalid for diff_opt=2' )
8948 ! DO j = j_start, j_end+1
8951 ! DO i = i_start, i_end
8952 ! tmp2(i,k,j) = defor23(i,k,j)
8959 ! DO j = j_start, j_end+1
8961 ! DO i = i_start, i_end
8962 ! tmp2(i,kts, j) = 0.0
8963 ! tmp2(i,ktf+1,j) = 0.0
8969 ! DO j = j_start, j_end
8972 ! DO i = i_start, i_end
8973 ! avg(i,k,j) = 0.25 * &
8974 ! ( ( tmp2(i,k+1,j )**2 ) + ( tmp2(i,k,j )**2) + &
8975 ! ( tmp2(i,k+1,j+1)**2 ) + ( tmp2(i,k,j+1)**2) )
8982 ! DO j = j_start, j_end
8985 ! DO i = i_start, i_end
8986 ! tendency(i,k,j) = tendency(i,k,j) + mu(i,j) * xkmv(i,k,j) * avg(i,k,j)
8996 ! ! Keep_Lpb29_absU(1) =absU
8997 ! ! Keep_Lpb29_Cd(1) =Cd
8999 ! vflux: SELECT CASE( config_flags%isfflx )
9002 ! cd0 = config_flags%tke_drag_coefficient
9004 ! DO j = j_start, j_end
9005 ! DO i = i_start, i_end
9006 ! absU=0.5*sqrt((u(i,k,j)+u(i+1,k,j))**2+(v(i,k,j)+v(i,k,j+1))**2)
9008 ! tendency(i,k,j) = tendency(i,k,j) + &
9009 ! mu(i,j)*( (v(i,k,j)+v(i,k,j+1))*0.5* &
9010 ! Cd*absU*(defor23(i,kts+1,j)+defor23(i,kts+1,j+1))*0.5 )
9015 ! DO j = j_start, j_end
9016 ! DO i = i_start, i_end
9017 ! absU=0.5*sqrt((u(i,k,j)+u(i+1,k,j))**2+(v(i,k,j)+v(i,k,j+1))**2)+epsilon
9018 ! Cd = (ust(i,j)**2)/(absU**2)
9019 ! tendency(i,k,j) = tendency(i,k,j) + &
9020 ! mu(i,j)*( (v(i,k,j)+v(i,k,j+1))*0.5* &
9021 ! Cd*absU*(defor23(i,kts+1,j)+defor23(i,kts+1,j+1))*0.5 )
9025 ! CALL wrf_error_fatal( 'isfflx value invalid for diff_opt=2' )
9029 !PART III: INITIALIZATION OF LOCAL ADJOINT PERTURBATIONS
9033 Do K2_ADJ =jts-1, jte+1
9035 Do K0_ADJ =its-1, ite+1
9036 a_avg(K0_ADJ,K1_ADJ,K2_ADJ) =0.0
9041 Do K2_ADJ =jts-1, jte+1
9043 Do K0_ADJ =its-1, ite+1
9044 a_titau(K0_ADJ,K1_ADJ,K2_ADJ) =0.0
9049 Do K2_ADJ =jts-1, jte+1
9051 Do K0_ADJ =its-1, ite+1
9052 a_tmp2(K0_ADJ,K1_ADJ,K2_ADJ) =0.0
9060 a_titau12(K0_ADJ,K1_ADJ,K2_ADJ) =0.0
9068 a_tmp1(K0_ADJ,K1_ADJ,K2_ADJ) =0.0
9076 a_zxavg(K0_ADJ,K1_ADJ,K2_ADJ) =0.0
9084 a_zyavg(K0_ADJ,K1_ADJ,K2_ADJ) =0.0
9090 ! a_cd0 =0.0 ! Remarked by Ning Pan, 2010-08-12
9093 !PART IV: REVERSE/BACKWARD ACCUMULATIONS
9095 K=KTS ! Added by Ning Pan, 2010-08-12
9097 ! absU =Keep_Lpb29_absU(1)
9098 ! Cd =Keep_Lpb29_Cd(1)
9100 SELECT CASE (config_flags%isfflx)
9102 cd0 =config_flags%tke_drag_coefficient
9104 DO j =j_start, j_end
9105 DO i =i_start, i_end
9106 Tmpv001 =u(i,k,j) +u(i+1,k,j)
9107 Tmpv300(i,j) =Tmpv001
9108 Tmpv002 =Tmpv300(i,j)**2
9109 Tmpv003 =v(i,k,j) +v(i,k,j+1)
9110 Tmpv301(i,j) =Tmpv003
9111 Tmpv004 =Tmpv301(i,j)**2
9112 Tmpv005 =Tmpv002 +Tmpv004
9113 Tmpv302(i,j) =Tmpv005
9114 Tmpv006 =sqrt(Tmpv302(i,j))
9115 Tmpv007 =0.5*Tmpv006
9116 ! Revised by Ning Pan, 2010-08-12
9117 ! Tmpv303(i,j) =absU
9122 ! Revised by Ning Pan, 2010-08-12
9128 Tmpv001 =v(i,k,j) +v(i,k,j+1)
9129 Tmpv002 =Tmpv001*0.5
9130 Tmpv305(i,j) =Tmpv002
9131 Tmpv003 =Tmpv305(i,j)*Cd
9132 Tmpv306(i,j) =Tmpv003
9133 Tmpv004 =Tmpv306(i,j)*absU
9134 Tmpv005 =defor23(i,kts+1,j) +defor23(i,kts+1,j+1)
9135 Tmpv307(i,j) =Tmpv004
9136 Tmpv308(i,j) =Tmpv005
9137 Tmpv006 =Tmpv307(i,j)*Tmpv308(i,j)
9138 Tmpv007 =Tmpv006*0.5
9139 Tmpv309(i,j) =Tmpv007
9140 ! Remarked by Ning Pan, 2010-08-12
9141 ! Tmpv008 =mu(i,j)*Tmpv309(i,j)
9142 ! Tmpv009 =tendency(i,k,j) +Tmpv008
9143 ! tendency(i,k,j) =Tmpv009
9148 DO j =j_start, j_end
9149 DO i =i_start, i_end
9150 Tmpv001 =u(i,k,j) +u(i+1,k,j)
9151 Tmpv3010(i,j) =Tmpv001
9152 Tmpv002 =Tmpv3010(i,j)**2
9153 Tmpv003 =v(i,k,j) +v(i,k,j+1)
9154 Tmpv3011(i,j) =Tmpv003
9155 Tmpv004 =Tmpv3011(i,j)**2
9156 Tmpv005 =Tmpv002 +Tmpv004
9157 Tmpv3012(i,j) =Tmpv005
9158 Tmpv006 =sqrt(Tmpv3012(i,j))
9159 Tmpv007 =0.5*Tmpv006
9160 Tmpv008 =Tmpv007 +epsilon
9161 ! Revised by Ning Pan, 2010-08-12
9162 ! Tmpv3013(i,j) =absU
9167 Tmpv001 =(ust(i,j)**2)/(absU**2)
9168 ! Revised by Ning Pan, 2010-08-12
9174 Tmpv001 =v(i,k,j) +v(i,k,j+1)
9175 Tmpv002 =Tmpv001*0.5
9176 Tmpv3015(i,j) =Tmpv002
9177 Tmpv003 =Tmpv3015(i,j)*Cd
9178 Tmpv3016(i,j) =Tmpv003
9179 Tmpv004 =Tmpv3016(i,j)*absU
9180 Tmpv005 =defor23(i,kts+1,j) +defor23(i,kts+1,j+1)
9181 Tmpv3017(i,j) =Tmpv004
9182 Tmpv3018(i,j) =Tmpv005
9183 Tmpv006 =Tmpv3017(i,j)*Tmpv3018(i,j)
9184 Tmpv007 =Tmpv006*0.5
9185 Tmpv3019(i,j) =Tmpv007
9186 ! Remarked by Ning Pan, 2010-08-12
9187 ! Tmpv008 =mu(i,j)*Tmpv3019(i,j)
9188 ! Tmpv009 =tendency(i,k,j) +Tmpv008
9189 ! tendency(i,k,j) =Tmpv009
9194 CALL wrf_error_fatal('isfflx value invalid for diff_opt=2')
9196 ! Revised by Ning Pan, 2010-08-12
9200 SELECT CASE (config_flags%isfflx)
9204 DO j =j_end, j_start, -1
9205 DO i =i_end, i_start, -1
9206 ! Added by Ning Pan, 2010-08-12
9210 a_Tmpv9 =a_tendency(i,k,j)
9211 a_tendency(i,k,j) =0.0
9212 a_tendency(i,k,j) =a_tendency(i,k,j) +a_Tmpv9
9214 a_mu(i,j) =a_mu(i,j) +Tmpv309(i,j)*a_Tmpv8
9215 a_Tmpv7 =mu(i,j)*a_Tmpv8
9216 a_Tmpv6 =0.5*a_Tmpv7
9217 a_Tmpv4 =Tmpv308(i,j)*a_Tmpv6
9218 a_Tmpv5 =Tmpv307(i,j)*a_Tmpv6
9219 a_defor23(i,kts+1,j) =a_defor23(i,kts+1,j) +a_Tmpv5
9220 a_defor23(i,kts+1,j+1) =a_defor23(i,kts+1,j+1) +a_Tmpv5
9221 a_Tmpv3 =absU*a_Tmpv4
9222 a_absU =a_absU +Tmpv306(i,j)*a_Tmpv4
9224 a_Cd =a_Cd +Tmpv305(i,j)*a_Tmpv3
9225 a_Tmpv1 =0.5*a_Tmpv2
9226 a_v(i,k,j) =a_v(i,k,j) +a_Tmpv1
9227 a_v(i,k,j+1) =a_v(i,k,j+1) +a_Tmpv1
9229 ! Cd =Tmpv304(i,j) ! Remarked by Ning Pan, 2010-08-12
9231 ! a_cd0 =a_cd0 +a_Cd ! ! Remarked by Ning Pan, 2010-08-12
9234 ! absU =Tmpv303(i,j) ! Remarked by Ning Pan, 2010-08-12
9238 a_Tmpv6 =0.5*a_Tmpv7
9239 a_Tmpv5 =g_Sqrt(1.0, Tmpv302(i,j))*a_Tmpv6
9242 a_Tmpv3 =2.0*Tmpv301(i,j)*a_Tmpv4
9243 a_v(i,k,j) =a_v(i,k,j) +a_Tmpv3
9244 a_v(i,k,j+1) =a_v(i,k,j+1) +a_Tmpv3
9245 a_Tmpv1 =2.0*Tmpv300(i,j)*a_Tmpv2
9246 a_u(i,k,j) =a_u(i,k,j) +a_Tmpv1
9247 a_u(i+1,k,j) =a_u(i+1,k,j) +a_Tmpv1
9250 ! Remarked by Ning Pan, 2010-08-12
9251 ! a_config_flags%tke_drag_coefficient =a_config_flags%tke_drag_coefficient +a_cd0
9256 DO j =j_end, j_start, -1
9257 DO i =i_end, i_start, -1
9258 ! Added by Ning Pan, 2010-08-12
9262 a_Tmpv9 =a_tendency(i,k,j)
9263 a_tendency(i,k,j) =0.0
9264 a_tendency(i,k,j) =a_tendency(i,k,j) +a_Tmpv9
9266 a_mu(i,j) =a_mu(i,j) +Tmpv3019(i,j)*a_Tmpv8
9267 a_Tmpv7 =mu(i,j)*a_Tmpv8
9268 a_Tmpv6 =0.5*a_Tmpv7
9269 a_Tmpv4 =Tmpv3018(i,j)*a_Tmpv6
9270 a_Tmpv5 =Tmpv3017(i,j)*a_Tmpv6
9271 a_defor23(i,kts+1,j) =a_defor23(i,kts+1,j) +a_Tmpv5
9272 a_defor23(i,kts+1,j+1) =a_defor23(i,kts+1,j+1) +a_Tmpv5
9273 a_Tmpv3 =absU*a_Tmpv4
9274 a_absU =a_absU +Tmpv3016(i,j)*a_Tmpv4
9276 a_Cd =a_Cd +Tmpv3015(i,j)*a_Tmpv3
9277 a_Tmpv1 =0.5*a_Tmpv2
9278 a_v(i,k,j) =a_v(i,k,j) +a_Tmpv1
9279 a_v(i,k,j+1) =a_v(i,k,j+1) +a_Tmpv1
9281 ! Cd =Tmpv3014(i,j) ! Remarked by Ning Pan, 2010-08-12
9285 a_ust(i,j) =a_ust(i,j) +2.0*ust(i,j)/(absU**2)*a_Tmpv1
9286 a_absU =a_absU -2.0*absU*(ust(i,j)**2)/((absU**2)*(absU**2))*a_Tmpv1
9288 ! absU =Tmpv3013(i,j) ! Remarked by Ning Pan, 2010-08-12
9293 a_Tmpv6 =0.5*a_Tmpv7
9294 a_Tmpv5 =g_Sqrt(1.0, Tmpv3012(i,j))*a_Tmpv6
9297 a_Tmpv3 =2.0*Tmpv3011(i,j)*a_Tmpv4
9298 a_v(i,k,j) =a_v(i,k,j) +a_Tmpv3
9299 a_v(i,k,j+1) =a_v(i,k,j+1) +a_Tmpv3
9300 a_Tmpv1 =2.0*Tmpv3010(i,j)*a_Tmpv2
9301 a_u(i,k,j) =a_u(i,k,j) +a_Tmpv1
9302 a_u(i+1,k,j) =a_u(i+1,k,j) +a_Tmpv1
9308 ! Revised by Ning Pan, 2010-08-12
9309 ! CALL a_wrf_error_fatal('isfflx value invalid for diff_opt=2')
9310 CALL wrf_error_fatal('isfflx value invalid for diff_opt=2')
9312 ! Revised by Ning Pan, 2010-08-12
9319 ! Added by Ning Pan, 2010-08-12: LPB[24]-[26]
9321 DO j = j_start, j_end+1
9324 DO i = i_start, i_end
9325 tmp2(i,k,j) = defor23(i,k,j)
9332 DO j = j_start, j_end+1
9334 DO i = i_start, i_end
9335 tmp2(i,kts, j) = 0.0
9336 tmp2(i,ktf+1,j) = 0.0
9342 DO j = j_start, j_end
9345 DO i = i_start, i_end
9346 avg(i,k,j) = 0.25 * &
9347 ( ( tmp2(i,k+1,j )**2 ) + ( tmp2(i,k,j )**2) + &
9348 ( tmp2(i,k+1,j+1)**2 ) + ( tmp2(i,k,j+1)**2) )
9355 DO j =j_end, j_start, -1
9358 DO i =i_start, i_end
9359 Tmpv001 =mu(i,j)*xkmv(i,k,j)
9360 Tmpv300(i,k) =Tmpv001
9361 ! Remarked by Ning Pan, 2010-08-12
9362 ! Tmpv002 =Tmpv300(i,k)*avg(i,k,j)
9363 ! Tmpv003 =tendency(i,k,j) +Tmpv002
9364 ! tendency(i,k,j) =Tmpv003
9370 DO i =i_end, i_start, -1
9371 a_Tmpv3 =a_tendency(i,k,j)
9372 a_tendency(i,k,j) =0.0
9373 a_tendency(i,k,j) =a_tendency(i,k,j) +a_Tmpv3
9375 a_Tmpv1 =avg(i,k,j)*a_Tmpv2
9376 a_avg(i,k,j) =a_avg(i,k,j) +Tmpv300(i,k)*a_Tmpv2
9377 a_mu(i,j) =a_mu(i,j) +xkmv(i,k,j)*a_Tmpv1
9378 a_xkmv(i,k,j) =a_xkmv(i,k,j) +mu(i,j)*a_Tmpv1
9385 DO j =j_end, j_start, -1
9388 ! DO i =i_start, i_end
9389 ! Tmpv001 =(tmp2(i,k+1,j)**2) +(tmp2(i,k,j)**2)
9390 ! Tmpv002 =Tmpv001 +(tmp2(i,k+1,j+1)**2)
9391 ! Tmpv003 =Tmpv002 +(tmp2(i,k,j+1)**2)
9392 ! Tmpv004 =0.25*Tmpv003
9393 ! avg(i,k,j) =Tmpv004
9399 DO i =i_end, i_start, -1
9400 a_Tmpv4 =a_avg(i,k,j)
9402 a_Tmpv3 =0.25*a_Tmpv4
9404 a_tmp2(i,k,j+1) =a_tmp2(i,k,j+1) +2.0*tmp2(i,k,j+1)*a_Tmpv3
9406 a_tmp2(i,k+1,j+1) =a_tmp2(i,k+1,j+1) +2.0*tmp2(i,k+1,j+1)*a_Tmpv2
9407 a_tmp2(i,k+1,j) =a_tmp2(i,k+1,j) +2.0*tmp2(i,k+1,j)*a_Tmpv1
9408 a_tmp2(i,k,j) =a_tmp2(i,k,j) +2.0*tmp2(i,k,j)*a_Tmpv1
9415 DO j =j_end+1, j_start, -1
9417 ! DO i =i_start, i_end
9418 ! tmp2(i,kts,j) =0.0
9420 ! tmp2(i,ktf+1,j) =0.0
9424 DO i =i_end, i_start, -1
9425 a_tmp2(i,ktf+1,j) =0.0
9426 a_tmp2(i,kts,j) =0.0
9432 DO j =j_end+1, j_start, -1
9435 ! DO i =i_start, i_end
9436 ! tmp2(i,k,j) =defor23(i,k,j)
9441 DO k =ktf, kts+1, -1
9442 DO i =i_end, i_start, -1
9443 a_defor23(i,k,j) =a_defor23(i,k,j) +a_tmp2(i,k,j)
9450 K=KTS ! Added by Ning Pan, 2010-08-12
9453 SELECT CASE (config_flags%isfflx)
9455 cd0 =config_flags%tke_drag_coefficient
9457 DO j =j_start, j_end
9458 DO i =i_start, i_end
9459 Tmpv001 =u(i,k,j) +u(i+1,k,j)
9460 Tmpv300(i,j) =Tmpv001
9461 Tmpv002 =Tmpv300(i,j)**2
9462 Tmpv003 =v(i,k,j) +v(i,k,j+1)
9463 Tmpv301(i,j) =Tmpv003
9464 Tmpv004 =Tmpv301(i,j)**2
9465 Tmpv005 =Tmpv002 +Tmpv004
9466 Tmpv302(i,j) =Tmpv005
9467 Tmpv006 =sqrt(Tmpv302(i,j))
9468 Tmpv007 =0.5*Tmpv006
9469 ! Revised by Ning Pan, 2010-08-12
9470 ! Tmpv303(i,j) =absU
9475 ! Revised by Ning Pan, 2010-08-12
9481 Tmpv001 =u(i,k,j) +u(i+1,k,j)
9482 Tmpv002 =Tmpv001*0.5
9483 Tmpv305(i,j) =Tmpv002
9484 Tmpv003 =Tmpv305(i,j)*Cd
9485 Tmpv306(i,j) =Tmpv003
9486 Tmpv004 =Tmpv306(i,j)*absU
9487 Tmpv005 =defor13(i,kts+1,j) +defor13(i+1,kts+1,j)
9488 Tmpv307(i,j) =Tmpv004
9489 Tmpv308(i,j) =Tmpv005
9490 Tmpv006 =Tmpv307(i,j)*Tmpv308(i,j)
9491 Tmpv007 =Tmpv006*0.5
9492 Tmpv309(i,j) =Tmpv007
9493 ! Remarked by Ning Pan, 2010-08-12
9494 ! Tmpv008 =mu(i,j)*Tmpv309(i,j)
9495 ! Tmpv009 =tendency(i,k,j) +Tmpv008
9496 ! tendency(i,k,j) =Tmpv009
9501 DO j =j_start, j_end
9502 DO i =i_start, i_end
9503 Tmpv001 =u(i,k,j) +u(i+1,k,j)
9504 Tmpv3010(i,j) =Tmpv001
9505 Tmpv002 =Tmpv3010(i,j)**2
9506 Tmpv003 =v(i,k,j) +v(i,k,j+1)
9507 Tmpv3011(i,j) =Tmpv003
9508 Tmpv004 =Tmpv3011(i,j)**2
9509 Tmpv005 =Tmpv002 +Tmpv004
9510 Tmpv3012(i,j) =Tmpv005
9511 Tmpv006 =sqrt(Tmpv3012(i,j))
9512 Tmpv007 =0.5*Tmpv006
9513 Tmpv008 =Tmpv007 +epsilon
9514 ! Revised by Ning Pan, 2010-08-12
9515 ! Tmpv3013(i,j) =absU
9520 Tmpv001 =(ust(i,j)**2)/(absU**2)
9521 ! Revised by Ning Pan, 2010-08-12
9527 Tmpv001 =u(i,k,j) +u(i+1,k,j)
9528 Tmpv002 =Tmpv001*0.5
9529 Tmpv3015(i,j) =Tmpv002
9530 Tmpv003 =Tmpv3015(i,j)*Cd
9531 Tmpv3016(i,j) =Tmpv003
9532 Tmpv004 =Tmpv3016(i,j)*absU
9533 Tmpv005 =defor13(i,kts+1,j) +defor13(i+1,kts+1,j)
9534 Tmpv3017(i,j) =Tmpv004
9535 Tmpv3018(i,j) =Tmpv005
9536 Tmpv006 =Tmpv3017(i,j)*Tmpv3018(i,j)
9537 Tmpv007 =Tmpv006*0.5
9538 Tmpv3019(i,j) =Tmpv007
9539 ! Remarked by Ning Pan, 2010-08-12
9540 ! Tmpv008 =mu(i,j)*Tmpv3019(i,j)
9541 ! Tmpv009 =tendency(i,k,j) +Tmpv008
9542 ! tendency(i,k,j) =Tmpv009
9547 CALL wrf_error_fatal('isfflx value invalid for diff_opt=2')
9549 ! Revised by Ning Pan, 2010-08-12
9553 SELECT CASE (config_flags%isfflx)
9557 DO j =j_end, j_start, -1
9558 DO i =i_end, i_start, -1
9559 ! Added by Ning Pan, 2010-08-12
9563 a_Tmpv9 =a_tendency(i,k,j)
9564 a_tendency(i,k,j) =0.0
9565 a_tendency(i,k,j) =a_tendency(i,k,j) +a_Tmpv9
9567 a_mu(i,j) =a_mu(i,j) +Tmpv309(i,j)*a_Tmpv8
9568 a_Tmpv7 =mu(i,j)*a_Tmpv8
9569 a_Tmpv6 =0.5*a_Tmpv7
9570 a_Tmpv4 =Tmpv308(i,j)*a_Tmpv6
9571 a_Tmpv5 =Tmpv307(i,j)*a_Tmpv6
9572 a_defor13(i,kts+1,j) =a_defor13(i,kts+1,j) +a_Tmpv5
9573 a_defor13(i+1,kts+1,j) =a_defor13(i+1,kts+1,j) +a_Tmpv5
9574 a_Tmpv3 =absU*a_Tmpv4
9575 a_absU =a_absU +Tmpv306(i,j)*a_Tmpv4
9577 a_Cd =a_Cd +Tmpv305(i,j)*a_Tmpv3
9578 a_Tmpv1 =0.5*a_Tmpv2
9579 a_u(i,k,j) =a_u(i,k,j) +a_Tmpv1
9580 a_u(i+1,k,j) =a_u(i+1,k,j) +a_Tmpv1
9582 ! Cd =Tmpv304(i,j) ! Remarked by Ning Pan, 2010-08-12
9584 ! a_cd0 =a_cd0 +a_Cd ! Remarked by Ning Pan, 2010-08-12
9587 ! absU =Tmpv303(i,j) ! Remarked by Ning Pan, 2010-08-12
9591 a_Tmpv6 =0.5*a_Tmpv7
9592 a_Tmpv5 =g_Sqrt(1.0, Tmpv302(i,j))*a_Tmpv6
9595 a_Tmpv3 =2.0*Tmpv301(i,j)*a_Tmpv4
9596 a_v(i,k,j) =a_v(i,k,j) +a_Tmpv3
9597 a_v(i,k,j+1) =a_v(i,k,j+1) +a_Tmpv3
9598 a_Tmpv1 =2.0*Tmpv300(i,j)*a_Tmpv2
9599 a_u(i,k,j) =a_u(i,k,j) +a_Tmpv1
9600 a_u(i+1,k,j) =a_u(i+1,k,j) +a_Tmpv1
9603 ! Remarked by Ning Pan, 2010-08-12
9604 ! a_config_flags%tke_drag_coefficient =a_config_flags%tke_drag_coefficient +a_cd0
9609 DO j =j_end, j_start, -1
9610 DO i =i_end, i_start, -1
9611 ! Added by Ning Pan, 2010-08-12
9615 a_Tmpv9 =a_tendency(i,k,j)
9616 a_tendency(i,k,j) =0.0
9617 a_tendency(i,k,j) =a_tendency(i,k,j) +a_Tmpv9
9619 a_mu(i,j) =a_mu(i,j) +Tmpv3019(i,j)*a_Tmpv8
9620 a_Tmpv7 =mu(i,j)*a_Tmpv8
9621 a_Tmpv6 =0.5*a_Tmpv7
9622 a_Tmpv4 =Tmpv3018(i,j)*a_Tmpv6
9623 a_Tmpv5 =Tmpv3017(i,j)*a_Tmpv6
9624 a_defor13(i,kts+1,j) =a_defor13(i,kts+1,j) +a_Tmpv5
9625 a_defor13(i+1,kts+1,j) =a_defor13(i+1,kts+1,j) +a_Tmpv5
9626 a_Tmpv3 =absU*a_Tmpv4
9627 a_absU =a_absU +Tmpv3016(i,j)*a_Tmpv4
9629 a_Cd =a_Cd +Tmpv3015(i,j)*a_Tmpv3
9630 a_Tmpv1 =0.5*a_Tmpv2
9631 a_u(i,k,j) =a_u(i,k,j) +a_Tmpv1
9632 a_u(i+1,k,j) =a_u(i+1,k,j) +a_Tmpv1
9634 ! Cd =Tmpv3014(i,j) ! Remarked by Ning Pan, 2010-08-12
9638 a_ust(i,j) =a_ust(i,j) +2.0*ust(i,j)/(absU**2)*a_Tmpv1
9639 a_absU =a_absU -2.0*absU*(ust(i,j)**2)/((absU**2)*(absU**2))*a_Tmpv1
9641 ! absU =Tmpv3013(i,j) ! Remarked by Ning Pan, 2010-08-12
9646 a_Tmpv6 =0.5*a_Tmpv7
9647 a_Tmpv5 =g_Sqrt(1.0, Tmpv3012(i,j))*a_Tmpv6
9650 a_Tmpv3 =2.0*Tmpv3011(i,j)*a_Tmpv4
9651 a_v(i,k,j) =a_v(i,k,j) +a_Tmpv3
9652 a_v(i,k,j+1) =a_v(i,k,j+1) +a_Tmpv3
9653 a_Tmpv1 =2.0*Tmpv3010(i,j)*a_Tmpv2
9654 a_u(i,k,j) =a_u(i,k,j) +a_Tmpv1
9655 a_u(i+1,k,j) =a_u(i+1,k,j) +a_Tmpv1
9661 ! Revised by Ning Pan, 2010-08-12
9662 ! CALL a_wrf_error_fatal('isfflx value invalid for diff_opt=2')
9663 CALL wrf_error_fatal('isfflx value invalid for diff_opt=2')
9665 ! Revised by Ning Pan, 2010-08-12
9672 ! Added by Ning Pan, 2010-08-12 : LPB[18]-[20]
9674 DO j = j_start, j_end
9677 DO i = i_start, i_end+1
9678 tmp2(i,k,j) = defor13(i,k,j)
9685 DO j = j_start, j_end
9687 DO i = i_start, i_end+1
9688 tmp2(i,kts ,j) = 0.0
9689 tmp2(i,ktf+1,j) = 0.0
9695 DO j = j_start, j_end
9698 DO i = i_start, i_end
9699 avg(i,k,j) = 0.25 * &
9700 ( ( tmp2(i ,k+1,j)**2 ) + ( tmp2(i ,k,j)**2 ) + &
9701 ( tmp2(i+1,k+1,j)**2 ) + ( tmp2(i+1,k,j)**2 ) )
9708 DO j =j_end, j_start, -1
9711 DO i =i_start, i_end
9712 Tmpv001 =mu(i,j)*xkmv(i,k,j)
9713 Tmpv300(i,k) =Tmpv001
9714 ! Remarked by Ning Pan, 2010-08-12
9715 Tmpv002 =Tmpv300(i,k)*avg(i,k,j)
9716 Tmpv003 =tendency(i,k,j) +Tmpv002
9717 tendency(i,k,j) =Tmpv003
9723 DO i =i_end, i_start, -1
9724 a_Tmpv3 =a_tendency(i,k,j)
9725 a_tendency(i,k,j) =0.0
9726 a_tendency(i,k,j) =a_tendency(i,k,j) +a_Tmpv3
9728 a_Tmpv1 =avg(i,k,j)*a_Tmpv2
9729 a_avg(i,k,j) =a_avg(i,k,j) +Tmpv300(i,k)*a_Tmpv2
9730 a_mu(i,j) =a_mu(i,j) +xkmv(i,k,j)*a_Tmpv1
9731 a_xkmv(i,k,j) =a_xkmv(i,k,j) +mu(i,j)*a_Tmpv1
9738 DO j =j_end, j_start, -1
9741 ! DO i =i_start, i_end
9742 ! Tmpv001 =(tmp2(i,k+1,j)**2) +(tmp2(i,k,j)**2)
9743 ! Tmpv002 =Tmpv001 +(tmp2(i+1,k+1,j)**2)
9744 ! Tmpv003 =Tmpv002 +(tmp2(i+1,k,j)**2)
9745 ! Tmpv004 =0.25*Tmpv003
9746 ! avg(i,k,j) =Tmpv004
9752 DO i =i_end, i_start, -1
9753 a_Tmpv4 =a_avg(i,k,j)
9755 a_Tmpv3 =0.25*a_Tmpv4
9757 a_tmp2(i+1,k,j) =a_tmp2(i+1,k,j) +2.0*tmp2(i+1,k,j)*a_Tmpv3
9759 a_tmp2(i+1,k+1,j) =a_tmp2(i+1,k+1,j) +2.0*tmp2(i+1,k+1,j)*a_Tmpv2
9760 a_tmp2(i,k+1,j) =a_tmp2(i,k+1,j) +2.0*tmp2(i,k+1,j)*a_Tmpv1
9761 a_tmp2(i,k,j) =a_tmp2(i,k,j) +2.0*tmp2(i,k,j)*a_Tmpv1
9768 DO j =j_end, j_start, -1
9770 ! DO i =i_start, i_end+1
9771 ! tmp2(i,kts,j) =0.0
9773 ! tmp2(i,ktf+1,j) =0.0
9777 DO i =i_end+1, i_start, -1
9778 a_tmp2(i,ktf+1,j) =0.0
9779 a_tmp2(i,kts,j) =0.0
9785 DO j =j_end, j_start, -1
9788 ! DO i =i_start, i_end+1
9789 ! tmp2(i,k,j) =defor13(i,k,j)
9794 DO k =ktf, kts+1, -1
9795 DO i =i_end+1, i_start, -1
9796 a_defor13(i,k,j) =a_defor13(i,k,j) +a_tmp2(i,k,j)
9803 ! Added by Ning Pan, 2010-08-12 : LPB[16]
9805 DO j = j_start, j_end
9808 DO i = i_start, i_end
9809 avg(i,k,j) = 0.25 * &
9810 ( ( defor12(i ,k,j)**2 ) + ( defor12(i ,k,j+1)**2 ) + &
9811 ( defor12(i+1,k,j)**2 ) + ( defor12(i+1,k,j+1)**2 ) )
9818 DO j =j_end, j_start, -1
9821 DO i =i_start, i_end
9822 Tmpv001 =mu(i,j)*xkmh(i,k,j)
9823 Tmpv300(i,k) =Tmpv001
9824 ! Remarked by Ning Pan, 2010-08-12
9825 ! Tmpv002 =Tmpv300(i,k)*avg(i,k,j)
9826 ! Tmpv003 =tendency(i,k,j) +Tmpv002
9827 ! tendency(i,k,j) =Tmpv003
9833 DO i =i_end, i_start, -1
9834 a_Tmpv3 =a_tendency(i,k,j)
9835 a_tendency(i,k,j) =0.0
9836 a_tendency(i,k,j) =a_tendency(i,k,j) +a_Tmpv3
9838 a_Tmpv1 =avg(i,k,j)*a_Tmpv2
9839 a_avg(i,k,j) =a_avg(i,k,j) +Tmpv300(i,k)*a_Tmpv2
9840 a_mu(i,j) =a_mu(i,j) +xkmh(i,k,j)*a_Tmpv1
9841 a_xkmh(i,k,j) =a_xkmh(i,k,j) +mu(i,j)*a_Tmpv1
9848 DO j =j_end, j_start, -1
9851 ! DO i =i_start, i_end
9852 ! Tmpv001 =(defor12(i,k,j)**2) +(defor12(i,k,j+1)**2)
9853 ! Tmpv002 =Tmpv001 +(defor12(i+1,k,j)**2)
9854 ! Tmpv003 =Tmpv002 +(defor12(i+1,k,j+1)**2)
9855 ! Tmpv004 =0.25*Tmpv003
9856 ! avg(i,k,j) =Tmpv004
9862 DO i =i_end, i_start, -1
9863 a_Tmpv4 =a_avg(i,k,j)
9865 a_Tmpv3 =0.25*a_Tmpv4
9867 a_defor12(i+1,k,j+1) =a_defor12(i+1,k,j+1) +2.0*defor12(i+1,k,j+1)*a_Tmpv3
9869 a_defor12(i+1,k,j) =a_defor12(i+1,k,j) +2.0*defor12(i+1,k,j)*a_Tmpv2
9870 a_defor12(i,k,j) =a_defor12(i,k,j) +2.0*defor12(i,k,j)*a_Tmpv1
9871 a_defor12(i,k,j+1) =a_defor12(i,k,j+1) +2.0*defor12(i,k,j+1)*a_Tmpv1
9878 DO j =j_end, j_start, -1
9881 DO i =i_start, i_end
9882 Tmpv001 =0.5*mu(i,j)*xkmv(i,k,j)
9883 Tmpv300(i,k) =Tmpv001
9884 ! Remarked by Ning Pan, 2010-08-12
9885 ! Tmpv002 =Tmpv300(i,k)*((defor33(i,k,j))**2)
9886 ! Tmpv003 =tendency(i,k,j) +Tmpv002
9887 ! tendency(i,k,j) =Tmpv003
9893 DO i =i_end, i_start, -1
9894 a_Tmpv3 =a_tendency(i,k,j)
9895 a_tendency(i,k,j) =0.0
9896 a_tendency(i,k,j) =a_tendency(i,k,j) +a_Tmpv3
9898 a_Tmpv1 =((defor33(i,k,j))**2)*a_Tmpv2
9899 a_defor33(i,k,j) =a_defor33(i,k,j) +2.0*(defor33(i,k,j))*Tmpv300(i,k)*a_Tmpv2
9900 a_mu(i,j) =a_mu(i,j) +0.5*xkmv(i,k,j)*a_Tmpv1
9901 a_xkmv(i,k,j) =a_xkmv(i,k,j) +0.5*mu(i,j)*a_Tmpv1
9908 DO j =j_end, j_start, -1
9911 DO i =i_start, i_end
9912 Tmpv001 =0.5*mu(i,j)*xkmh(i,k,j)
9913 Tmpv300(i,k) =Tmpv001
9914 ! Remarked by Ning Pan, 2010-08-12
9915 ! Tmpv002 =Tmpv300(i,k)*((defor22(i,k,j))**2)
9916 ! Tmpv003 =tendency(i,k,j) +Tmpv002
9917 ! tendency(i,k,j) =Tmpv003
9923 DO i =i_end, i_start, -1
9924 a_Tmpv3 =a_tendency(i,k,j)
9925 a_tendency(i,k,j) =0.0
9926 a_tendency(i,k,j) =a_tendency(i,k,j) +a_Tmpv3
9928 a_Tmpv1 =((defor22(i,k,j))**2)*a_Tmpv2
9929 a_defor22(i,k,j) =a_defor22(i,k,j) +2.0*(defor22(i,k,j))*Tmpv300(i,k)*a_Tmpv2
9930 a_mu(i,j) =a_mu(i,j) +0.5*xkmh(i,k,j)*a_Tmpv1
9931 a_xkmh(i,k,j) =a_xkmh(i,k,j) +0.5*mu(i,j)*a_Tmpv1
9938 DO j =j_end, j_start, -1
9941 DO i =i_start, i_end
9942 Tmpv001 =0.5*mu(i,j)*xkmh(i,k,j)
9943 Tmpv300(i,k) =Tmpv001
9944 ! Remarked by Ning Pan, 2010-08-12
9945 ! Tmpv002 =Tmpv300(i,k)*((defor11(i,k,j))**2)
9946 ! Tmpv003 =tendency(i,k,j) +Tmpv002
9947 ! tendency(i,k,j) =Tmpv003
9953 DO i =i_end, i_start, -1
9954 a_Tmpv3 =a_tendency(i,k,j)
9955 a_tendency(i,k,j) =0.0
9956 a_tendency(i,k,j) =a_tendency(i,k,j) +a_Tmpv3
9958 a_Tmpv1 =((defor11(i,k,j))**2)*a_Tmpv2
9959 a_defor11(i,k,j) =a_defor11(i,k,j) +2.0*(defor11(i,k,j))*Tmpv300(i,k)*a_Tmpv2
9960 a_mu(i,j) =a_mu(i,j) +0.5*xkmh(i,k,j)*a_Tmpv1
9961 a_xkmh(i,k,j) =a_xkmh(i,k,j) +0.5*mu(i,j)*a_Tmpv1
9968 DO j =j_end, j_start, -1
9971 ! DO i =i_start, i_end
9972 ! Tmpv001 =zx(i,k,j) +zx(i+1,k,j)
9973 ! Tmpv002 =Tmpv001 +zx(i,k+1,j)
9974 ! Tmpv003 =Tmpv002 +zx(i+1,k+1,j)
9975 ! Tmpv004 =0.25*Tmpv003
9976 ! zxavg(i,k,j) =Tmpv004
9978 ! Tmpv001 =zy(i,k,j) +zy(i,k,j+1)
9979 ! Tmpv002 =Tmpv001 +zy(i,k+1,j)
9980 ! Tmpv003 =Tmpv002 +zy(i,k+1,j+1)
9981 ! Tmpv004 =0.25*Tmpv003
9982 ! zyavg(i,k,j) =Tmpv004
9988 DO i =i_end, i_start, -1
9989 a_Tmpv4 =a_zyavg(i,k,j)
9991 a_Tmpv3 =0.25*a_Tmpv4
9993 a_zy(i,k+1,j+1) =a_zy(i,k+1,j+1) +a_Tmpv3
9995 a_zy(i,k+1,j) =a_zy(i,k+1,j) +a_Tmpv2
9996 a_zy(i,k,j) =a_zy(i,k,j) +a_Tmpv1
9997 a_zy(i,k,j+1) =a_zy(i,k,j+1) +a_Tmpv1
9998 a_Tmpv4 =a_zxavg(i,k,j)
10000 a_Tmpv3 =0.25*a_Tmpv4
10002 a_zx(i+1,k+1,j) =a_zx(i+1,k+1,j) +a_Tmpv3
10004 a_zx(i,k+1,j) =a_zx(i,k+1,j) +a_Tmpv2
10005 a_zx(i,k,j) =a_zx(i,k,j) +a_Tmpv1
10006 a_zx(i+1,k,j) =a_zx(i+1,k,j) +a_Tmpv1
10014 ! IF( config_flags%periodic_x ) THEN
10015 ! i_end =min(ite, ide-1)
10018 ! IF( config_flags%periodic_x ) THEN
10026 ! IF( config_flags%periodic_x ) THEN
10030 ! IF( config_flags%periodic_x ) THEN
10038 ! IF( config_flags%open_ye .OR. config_flags%specified .OR. config_flags%nested ) THEN
10039 ! j_end =min(jde-2, jte)
10042 ! IF( config_flags%open_ye .OR. config_flags%specified .OR. &
10043 ! config_flags%nested ) THEN
10051 ! IF( config_flags%open_ys .OR. config_flags%specified .OR. config_flags%nested ) THEN
10052 ! j_start =max(jds+1, jts)
10055 ! IF( config_flags%open_ys .OR. config_flags%specified .OR. &
10056 ! config_flags%nested ) THEN
10064 ! IF( config_flags%open_xe .OR. config_flags%specified .OR. config_flags%nested ) THEN
10065 ! i_end =min(ide-2, ite)
10068 ! IF( config_flags%open_xe .OR. config_flags%specified .OR. &
10069 ! config_flags%nested ) THEN
10077 ! IF( config_flags%open_xs .OR. config_flags%specified .OR. config_flags%nested ) THEN
10078 ! i_start =max(ids+1, its)
10081 ! IF( config_flags%open_xs .OR. config_flags%specified .OR. &
10082 ! config_flags%nested ) THEN
10087 ! ktf =min(kte, kde-1)
10091 ! i_end =min(ite, ide-1)
10093 ! j_end =min(jte, jde-1)
10095 END SUBROUTINE a_tke_shear
10097 ! Generated by TAPENADE (INRIA, Tropics team)
10098 ! Tapenade 3.5 (r3785) - 22 Mar 2011 18:35
10100 ! Differentiation of compute_diff_metrics in reverse (adjoint) mode:
10101 ! gradient of useful results: zx zy z rdzw rdz ph
10102 ! with respect to varying inputs: zx zy z rdzw rdz ph
10103 ! RW status of diff variables: zx:in-out zy:in-out z:in-out rdzw:in-out
10104 ! rdz:in-out ph:incr
10105 SUBROUTINE A_COMPUTE_DIFF_METRICS(config_flags, ph, phb0, phb, z, zb, &
10106 & rdz, rdzb, rdzw, rdzwb, zx, zxb, zy, zyb, rdx, rdy, ids, ide, jds, jde&
10107 & , kds, kde, ims, ime, jms, jme, kms, kme, its, ite, jts, jte, kts, kte&
10110 TYPE(GRID_CONFIG_REC_TYPE), INTENT(IN) :: config_flags
10111 INTEGER, INTENT(IN) :: ids, ide, jds, jde, kds, kde, ims, ime, jms, &
10112 & jme, kms, kme, its, ite, jts, jte, kts, kte
10113 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(IN) :: ph, phb
10114 REAL, DIMENSION(ims:ime, kms:kme, jms:jme) :: phb0
10115 REAL, DIMENSION(ims:ime, kms:kme, jms:jme) :: rdz, rdzw, zx, zy, z
10116 REAL, DIMENSION(ims:ime, kms:kme, jms:jme) :: rdzb, rdzwb, zxb, zyb, &
10118 REAL, INTENT(IN) :: rdx, rdy
10120 REAL, DIMENSION(its - 1:ite, kts:kte, jts - 1:jte) :: z_at_w
10121 REAL, DIMENSION(its-1:ite, kts:kte, jts-1:jte) :: z_at_wb
10122 INTEGER :: i, j, k, i_start, i_end, j_start, j_end, ktf
10125 INTEGER :: ad_from0
10127 INTEGER :: ad_from1
10129 INTEGER :: ad_from2
10131 INTEGER :: ad_from3
10133 INTEGER :: ad_from4
10134 INTEGER :: ad_from5
10154 IF (kte .GT. kde - 1) THEN
10159 ! Bug fix, WCS, 22 april 2002.
10160 ! We need rdzw in halo for average to u and v points.
10164 ! Begin with dz computations.
10165 DO j=ad_from3,j_end
10166 IF (jte .GT. jde - 1) THEN
10171 IF (j_start .GE. jts .AND. j_end .LE. min1) THEN
10176 IF (ite .GT. ide - 1) THEN
10182 ! Compute z at w points for rdz and rdzw computations. We'll switch z
10183 ! to z at p points before returning
10186 ! Bug fix, WCS, 22 april 2002
10188 z_at_w(i, k, j) = (ph(i, k, j)+phb(i, k, j))/g
10190 CALL PUSHINTEGER4(i - 1)
10191 CALL PUSHINTEGER4(ad_from)
10196 CALL PUSHINTEGER4(i - 1)
10197 CALL PUSHINTEGER4(ad_from0)
10202 CALL PUSHINTEGER4(i - 1)
10203 CALL PUSHINTEGER4(ad_from1)
10206 ! Bug fix, WCS, 22 april 2002; added the following code
10208 CALL PUSHINTEGER4(i - 1)
10209 CALL PUSHINTEGER4(ad_from2)
10211 CALL PUSHINTEGER4(j - 1)
10212 CALL PUSHINTEGER4(ad_from3)
10214 ! Now compute zx and zy; we'll assume that the halo for ph and phb is
10217 IF (ite .GT. ide - 1) THEN
10223 IF (jte .GT. jde - 1) THEN
10230 IF (ids + 1 .LT. its) THEN
10237 CALL PUSHINTEGER4(ad_from4)
10242 IF (ids + 1 .LT. its) THEN
10249 CALL PUSHINTEGER4(ad_from5)
10252 IF (jds + 1 .LT. jts) THEN
10262 IF (jds + 1 .LT. jts) THEN
10272 ! Some b.c. on zx and zy.
10273 IF (.NOT.config_flags%periodic_x) THEN
10274 IF (ite .EQ. ide) THEN
10275 CALL PUSHCONTROL1B(0)
10277 CALL PUSHCONTROL1B(1)
10279 IF (its .EQ. ids) THEN
10280 CALL PUSHCONTROL2B(0)
10282 CALL PUSHCONTROL2B(1)
10285 IF (ite .EQ. ide) THEN
10286 CALL PUSHCONTROL1B(0)
10288 CALL PUSHCONTROL1B(1)
10290 IF (its .EQ. ids) THEN
10291 CALL PUSHCONTROL2B(2)
10293 CALL PUSHCONTROL2B(3)
10296 IF (.NOT.config_flags%periodic_y) THEN
10297 IF (jte .EQ. jde) THEN
10298 CALL PUSHCONTROL1B(0)
10300 CALL PUSHCONTROL1B(1)
10302 IF (jts .EQ. jds) THEN
10303 CALL PUSHCONTROL2B(3)
10305 CALL PUSHCONTROL2B(2)
10308 IF (jte .EQ. jde) THEN
10309 CALL PUSHCONTROL1B(0)
10311 CALL PUSHCONTROL1B(1)
10313 IF (jts .EQ. jds) THEN
10314 CALL PUSHCONTROL2B(1)
10316 CALL PUSHCONTROL2B(0)
10319 ! Calculate z at p points.
10322 CALL PUSHINTEGER4(i)
10325 DO j=j_end,j_start,-1
10327 DO i=i_end,i_start,-1
10328 temp2b5 = 0.5*zb(i, k, j)/g
10329 phb0(i, k, j) = phb0(i, k, j) + temp2b5
10330 phb0(i, k+1, j) = phb0(i, k+1, j) + temp2b5
10333 CALL POPINTEGER4(i)
10336 CALL POPCONTROL2B(branch)
10337 IF (branch .LT. 2) THEN
10338 IF (branch .NE. 0) THEN
10340 DO i =i_end, i_start, -1
10341 temp2b4 = rdy*zyb(i, k, jds)/g
10342 phb0(i, k, jds) = phb0(i, k, jds) + temp2b4
10343 phb0(i, k, jds-1) = phb0(i, k, jds-1) - temp2b4
10347 DO i =i_end, i_start, -1
10348 zyb(i, k, jds) = 0.0
10352 CALL POPCONTROL1B(branch)
10353 IF (branch .EQ. 0) THEN
10355 DO i =i_end, i_start, -1
10356 temp2b3 = rdy*zyb(i, k, jde)/g
10357 phb0(i, k, jde) = phb0(i, k, jde) + temp2b3
10358 phb0(i, k, jde-1) = phb0(i, k, jde-1) - temp2b3
10362 DO i =i_end, i_start, -1
10363 zyb(i, k, jde) = 0.0
10368 IF (branch .NE. 2) THEN
10370 DO i=i_end,i_start,-1
10371 zyb(i, k, jds) = 0.0
10375 CALL POPCONTROL1B(branch)
10376 IF (branch .EQ. 0) THEN
10378 DO i=i_end,i_start,-1
10379 zyb(i, k, jde) = 0.0
10384 CALL POPCONTROL2B(branch)
10385 IF (branch .LT. 2) THEN
10386 IF (branch .EQ. 0) THEN
10387 DO j=j_end,j_start,-1
10389 zxb(ids, k, j) = 0.0
10393 CALL POPCONTROL1B(branch)
10394 IF (branch .EQ. 0) THEN
10395 DO j=j_end,j_start,-1
10397 zxb(ide, k, j) = 0.0
10402 IF (branch .EQ. 2) THEN
10403 DO j=j_end,j_start,-1
10405 temp2b2 = rdx*zxb(ids, k, j)/g
10406 phb0(ids, k, j) = phb0(ids, k, j) + temp2b2
10407 phb0(ids-1, k, j) = phb0(ids-1, k, j) - temp2b2
10410 DO j=j_end,j_start,-1
10412 zxb(ids, k, j) = 0.0
10416 CALL POPCONTROL1B(branch)
10417 IF (branch .EQ. 0) THEN
10418 DO j=j_end,j_start,-1
10420 temp2b1 = rdx*zxb(ide, k, j)/g
10421 phb0(ide, k, j) = phb0(ide, k, j) + temp2b1
10422 phb0(ide-1, k, j) = phb0(ide-1, k, j) - temp2b1
10425 DO j=j_end,j_start,-1
10427 zxb(ide, k, j) = 0.0
10434 DO i=i_end,i_start,-1
10435 temp2b0 = rdy*zyb(i, k, j)/g
10436 phb0(i, k, j) = phb0(i, k, j) + temp2b0
10437 phb0(i, k, j-1) = phb0(i, k, j-1) - temp2b0
10443 DO i=i_end,i_start,-1
10448 DO j=j_end,j_start,-1
10450 CALL POPINTEGER4(ad_from5)
10451 DO i=i_end,ad_from5,-1
10452 temp2b = rdx*zxb(i, k, j)/g
10453 phb0(i, k, j) = phb0(i, k, j) + temp2b
10454 phb0(i-1, k, j) = phb0(i-1, k, j) - temp2b
10458 DO j=j_end,j_start,-1
10460 CALL POPINTEGER4(ad_from4)
10461 DO i=i_end,ad_from4,-1
10467 CALL POPINTEGER4(ad_from3)
10468 CALL POPINTEGER4(ad_to3)
10469 DO j=ad_to3,ad_from3,-1
10470 CALL POPINTEGER4(ad_from2)
10471 CALL POPINTEGER4(ad_to2)
10472 DO i=ad_to2,ad_from2,-1
10473 temp1 = z_at_w(i, 2, j) - z_at_w(i, 1, j)
10474 temp1b = -(2.*rdzb(i, 1, j)/temp1**2)
10475 z_at_wb(i, 2, j) = z_at_wb(i, 2, j) + temp1b
10476 z_at_wb(i, 1, j) = z_at_wb(i, 1, j) - temp1b
10477 rdzb(i, 1, j) = 0.0
10480 CALL POPINTEGER4(ad_from1)
10481 CALL POPINTEGER4(ad_to1)
10482 DO i=ad_to1,ad_from1,-1
10483 temp0 = z_at_w(i, k+1, j) - z_at_w(i, k-1, j)
10484 temp0b = -(2.0*rdzb(i, k, j)/temp0**2)
10485 z_at_wb(i, k+1, j) = z_at_wb(i, k+1, j) + temp0b
10486 z_at_wb(i, k-1, j) = z_at_wb(i, k-1, j) - temp0b
10487 rdzb(i, k, j) = 0.0
10491 CALL POPINTEGER4(ad_from0)
10492 CALL POPINTEGER4(ad_to0)
10493 DO i=ad_to0,ad_from0,-1
10494 temp = z_at_w(i, k+1, j) - z_at_w(i, k, j)
10495 tempb = -(rdzwb(i, k, j)/temp**2)
10496 z_at_wb(i, k+1, j) = z_at_wb(i, k+1, j) + tempb
10497 z_at_wb(i, k, j) = z_at_wb(i, k, j) - tempb
10498 rdzwb(i, k, j) = 0.0
10502 CALL POPINTEGER4(ad_from)
10503 CALL POPINTEGER4(ad_to)
10504 DO i=ad_to,ad_from,-1
10505 phb0(i, k, j) = phb0(i, k, j) + z_at_wb(i, k, j)/g
10506 z_at_wb(i, k, j) = 0.0
10510 END SUBROUTINE A_COMPUTE_DIFF_METRICS
10512 SUBROUTINE a_horizontal_diffusion_2(rt_tendf,a_rt_tendf,ru_tendf,a_ru_tendf, &
10513 rv_tendf,a_rv_tendf,rw_tendf,a_rw_tendf,tke_tendf,a_tke_tendf,moist_tendf, &
10514 ! Revised by Ning Pan, 2010-08-10
10515 ! a_moist_tendf,n_moist,chem_tendf,a_chem_tendf,n_chem,scalar_tendf,a_scalar_tend &
10516 ! f,n_scalar,tracer_tendf,a_tracer_tendf,n_tracer,thp,a_thp,theta,a_theta,mu, &
10517 a_moist_tendf,n_moist,chem_tendf,a_chem_tendf,n_chem,scalar_tendf,a_scalar_tend&
10518 &f,n_scalar,tracer_tendf,a_tracer_tendf,n_tracer,thp,a_thp,theta,a_theta,mu, &
10519 a_mu,tke,a_tke,config_flags,defor11,a_defor11,defor22,a_defor22,defor12, &
10520 a_defor12,defor13,a_defor13,defor23,a_defor23,nba_mij,a_nba_mij,n_nba_mij, &
10521 div,a_div,moist,a_moist,chem,a_chem,scalar,a_scalar,tracer,a_tracer,msfux, &
10522 msfuy,msfvx,msfvy,msftx,msfty,xkmh,a_xkmh,xkhh,a_xkhh,km_opt,rdx,rdy,rdz,a_rdz, &
10523 rdzw,a_rdzw,fnm,fnp,cf1,cf2,cf3,zx,a_zx,zy,a_zy,dn,dnw,rho,a_rho,ids,ide,jds,jde,kds,kde, &
10524 ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
10526 !PART I: DECLARATION OF VARIABLES
10530 INTEGER :: K0_ADJ,K1_ADJ,K2_ADJ,K3_ADJ
10531 TYPE(grid_config_rec_type) :: config_flags
10532 INTEGER :: ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte
10533 INTEGER :: n_moist,n_chem,n_scalar,n_tracer,km_opt
10534 REAL :: cf1,cf2,cf3
10535 REAL,DIMENSION(kms:kme) :: fnm
10536 REAL,DIMENSION(kms:kme) :: fnp
10537 REAL,DIMENSION(kms:kme) :: dnw
10538 REAL,DIMENSION(kms:kme) :: dn
10539 REAL,DIMENSION(ims:ime,jms:jme) :: msfux,msfuy,msfvx,msfvy,msftx,msfty,mu,a_mu
10540 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: rt_tendf,a_rt_tendf,ru_tendf, &
10541 a_ru_tendf,rv_tendf,a_rv_tendf,rw_tendf,a_rw_tendf,tke_tendf,a_tke_tendf
10542 REAL , DIMENSION( ims:ime, kms:kme, jms:jme) :: &
10545 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_moist) :: moist_tendf,a_moist_tendf
10546 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_chem) :: chem_tendf,a_chem_tendf
10547 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_scalar) :: scalar_tendf,a_scalar_tendf
10548 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_tracer) :: tracer_tendf,a_tracer_tendf
10549 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_moist) :: moist,a_moist
10550 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_chem) :: chem,a_chem
10551 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_scalar) :: scalar,a_scalar
10552 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_tracer) :: tracer,a_tracer
10553 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: defor11,a_defor11,defor22,a_defor22, &
10554 defor12,a_defor12,defor13,a_defor13,defor23,a_defor23,div,a_div,xkmh, &
10555 a_xkmh,xkhh,a_xkhh,zx,a_zx,zy,a_zy,theta,a_theta,thp,a_thp,tke,a_tke, &
10556 rdz,a_rdz,rdzw,a_rdzw
10557 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: rho, a_rho
10559 INTEGER :: n_nba_mij
10560 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_nba_mij) :: nba_mij,a_nba_mij
10561 INTEGER :: im,ic,is
10563 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: Keep_Lpb0_ru_tendf
10564 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_nba_mij) :: Keep_Lpb0_nba_mij
10565 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_nba_mij) :: Keep_Lpb1_nba_mij ! Added by Ning Pan, 2010-08-11
10566 ! Remarked by Ning Pan, 2010-08-11
10567 ! REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: Keep_Lpb0_rv_tendf
10568 ! REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: Keep_Lpb0_rw_tendf
10569 ! REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: Keep_Lpb0_rt_tendf
10570 ! REAL,DIMENSION(ims:ime,kms:kme,jms:jme,ims:ime,kms:kme,jms:jme) :: Keep_Lpb1_tke_tendf
10571 ! REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_moist,ims:ime,kms:kme,jms:jme,n_moist) &
10572 ! :: Keep_Lpb3_moist_tendf
10573 ! REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_chem,ims:ime,kms:kme,jms:jme,n_chem) &
10574 ! :: Keep_Lpb5_chem_tendf
10575 ! REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_tracer,ims:ime,kms:kme,jms:jme,n_tracer) &
10576 ! :: Keep_Lpb7_tracer_tendf
10577 !! REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_scalar,ims:ime,kms:kme,jms:jme,n_scalar) &
10578 !! :: Keep_Lpb9_scalar_tendf
10579 ! INTEGER :: IX1,IX2,IX3,IX4
10581 ! Remarked by Ning Pan, 2010-08-11
10583 ! REAL,DIMENSION(PARAM_FIRST_SCALAR:max0(n_moist,n_chem,n_tracer,n_scalar)) :: Tmpv200
10584 ! REAL,DIMENSION(jms:jme,kms:kme,ims:ime) :: Tmpv400
10585 ! REAL,DIMENSION(jms:jme,kms:kme,ims:ime) :: Tmpv401
10586 ! REAL,DIMENSION(jms:jme,kms:kme,ims:ime) :: Tmpv402
10587 ! REAL,DIMENSION(jms:jme,kms:kme,ims:ime) :: Tmpv403
10588 ! REAL,DIMENSION(n_nba_mij,jms:jme,kms:kme,ims:ime) :: Tmpv500
10589 ! REAL,DIMENSION(n_nba_mij,jms:jme,kms:kme,ims:ime) :: Tmpv501
10590 ! REAL,DIMENSION(n_nba_mij,jms:jme,kms:kme,ims:ime) :: Tmpv502
10592 !PART II: CALCULATIONS OF B. S. TRAJECTORY
10594 ! Remarked by Ning Pan, 2010-08-11: LPB[0]-[7]
10599 ! Keep_Lpb0_ru_tendf(IX1,IX2,IX3) =ru_tendf(IX1,IX2,IX3)
10603 ! DO IX4=1,n_nba_mij
10607 ! Keep_Lpb0_nba_mij(IX1,IX2,IX3,IX4) =nba_mij(IX1,IX2,IX3,IX4)
10615 ! Keep_Lpb0_rv_tendf(IX1,IX2,IX3) =rv_tendf(IX1,IX2,IX3)
10622 ! Keep_Lpb0_rw_tendf(IX1,IX2,IX3) =rw_tendf(IX1,IX2,IX3)
10629 ! Keep_Lpb0_rt_tendf(IX1,IX2,IX3) =rt_tendf(IX1,IX2,IX3)
10634 ! CALL horizontal_diffusion_u_2( ru_tendf, mu, config_flags, &
10635 ! defor11, defor12, div, &
10636 ! nba_mij, n_nba_mij, &
10637 ! tke(ims,kms,jms), &
10638 ! msfux, msfuy, xkmh, rdx, rdy, fnm, fnp, &
10640 ! ids, ide, jds, jde, kds, kde, &
10641 ! ims, ime, jms, jme, kms, kme, &
10642 ! its, ite, jts, jte, kts, kte )
10643 ! CALL horizontal_diffusion_v_2( rv_tendf, mu, config_flags, &
10644 ! defor12, defor22, div, &
10645 ! nba_mij, n_nba_mij, &
10646 ! tke(ims,kms,jms), &
10647 ! msfvx, msfvy, xkmh, rdx, rdy, fnm, fnp, &
10649 ! ids, ide, jds, jde, kds, kde, &
10650 ! ims, ime, jms, jme, kms, kme, &
10651 ! its, ite, jts, jte, kts, kte )
10652 ! CALL horizontal_diffusion_w_2( rw_tendf, mu, config_flags, &
10653 ! defor13, defor23, div, &
10654 ! nba_mij, n_nba_mij, &
10655 ! tke(ims,kms,jms), &
10656 ! msftx, msfty, xkmh, rdx, rdy, fnm, fnp, &
10658 ! ids, ide, jds, jde, kds, kde, &
10659 ! ims, ime, jms, jme, kms, kme, &
10660 ! its, ite, jts, jte, kts, kte )
10661 ! CALL horizontal_diffusion_s ( rt_tendf, mu, config_flags, thp, &
10662 ! msftx, msfty, msfux, msfuy, &
10663 ! msfvx, msfvy, xkhh, rdx, rdy, &
10664 ! fnm, fnp, cf1, cf2, cf3, &
10665 ! zx, zy, rdz, rdzw, dnw, dn, &
10667 ! ids, ide, jds, jde, kds, kde, &
10668 ! ims, ime, jms, jme, kms, kme, &
10669 ! its, ite, jts, jte, kts, kte )
10675 ! Keep_Lpb1_tke_tendf(IX1,IX2,IX3) =tke_tendf(IX1,IX2,IX3)
10680 ! IF (km_opt .eq. 2) &
10681 ! CALL horizontal_diffusion_s ( tke_tendf(ims,kms,jms), &
10682 ! mu, config_flags, &
10683 ! tke(ims,kms,jms), &
10684 ! msftx, msfty, msfux, msfuy, &
10685 ! msfvx, msfvy, xkhh, rdx, rdy, &
10686 ! fnm, fnp, cf1, cf2, cf3, &
10687 ! zx, zy, rdz, rdzw, dnw, dn, &
10689 ! ids, ide, jds, jde, kds, kde, &
10690 ! ims, ime, jms, jme, kms, kme, &
10691 ! its, ite, jts, jte, kts, kte )
10700 ! Keep_Lpb3_moist_tendf(IX1,IX2,IX3,IX4) =moist_tendf(IX1,IX2,IX3,IX4)
10706 ! IF (n_moist .ge. PARAM_FIRST_SCALAR) THEN
10708 ! moist_loop: do im = PARAM_FIRST_SCALAR, n_moist
10709 ! CALL horizontal_diffusion_s( moist_tendf(ims,kms,jms,im), &
10710 ! mu, config_flags, &
10711 ! moist(ims,kms,jms,im), &
10712 ! msftx, msfty, msfux, msfuy, &
10713 ! msfvx, msfvy, xkhh, rdx, rdy, &
10714 ! fnm, fnp, cf1, cf2, cf3, &
10715 ! zx, zy, rdz, rdzw, dnw, dn, &
10717 ! ids, ide, jds, jde, kds, kde, &
10718 ! ims, ime, jms, jme, kms, kme, &
10719 ! its, ite, jts, jte, kts, kte )
10731 ! Keep_Lpb5_chem_tendf(IX1,IX2,IX3,IX4) =chem_tendf(IX1,IX2,IX3,IX4)
10737 ! IF (n_chem .ge. PARAM_FIRST_SCALAR) THEN
10739 ! chem_loop: do ic = PARAM_FIRST_SCALAR, n_chem
10740 ! CALL horizontal_diffusion_s( chem_tendf(ims,kms,jms,ic), &
10741 ! mu, config_flags, &
10742 ! chem(ims,kms,jms,ic), &
10743 ! msftx, msfty, msfux, msfuy, &
10744 ! msfvx, msfvy, xkhh, rdx, rdy, &
10745 ! fnm, fnp, cf1, cf2, cf3, &
10746 ! zx, zy, rdz, rdzw, dnw, dn, &
10748 ! ids, ide, jds, jde, kds, kde, &
10749 ! ims, ime, jms, jme, kms, kme, &
10750 ! its, ite, jts, jte, kts, kte )
10758 ! DO IX4=1,n_tracer
10762 ! Keep_Lpb7_tracer_tendf(IX1,IX2,IX3,IX4) =tracer_tendf(IX1,IX2,IX3,IX4)
10768 ! IF (n_tracer .ge. PARAM_FIRST_SCALAR) THEN
10770 ! tracer_loop: do ic = PARAM_FIRST_SCALAR, n_tracer
10771 ! CALL horizontal_diffusion_s( tracer_tendf(ims,kms,jms,ic), &
10772 ! mu, config_flags, &
10773 ! tracer(ims,kms,jms,ic), &
10774 ! msftx, msfty, msfux, msfuy, &
10775 ! msfvx, msfvy, xkhh, rdx, rdy, &
10776 ! fnm, fnp, cf1, cf2, cf3, &
10777 ! zx, zy, rdz, rdzw, dnw, dn, &
10779 ! ids, ide, jds, jde, kds, kde, &
10780 ! ims, ime, jms, jme, kms, kme, &
10781 ! its, ite, jts, jte, kts, kte )
10782 ! ENDDO tracer_loop
10789 !! DO IX4=1,n_scalar
10793 ! ! Keep_Lpb9_scalar_tendf(IX1,IX2,IX3,IX4) =scalar_tendf(IX1,IX2,IX3,IX4)
10800 ! IF (n_scalar .ge. PARAM_FIRST_SCALAR) THEN
10802 ! scalar_loop: do is = PARAM_FIRST_SCALAR, n_scalar
10803 ! CALL horizontal_diffusion_s( scalar_tendf(ims,kms,jms,is), &
10804 ! mu, config_flags, &
10805 ! scalar(ims,kms,jms,is), &
10806 ! msftx, msfty, msfux, msfuy, &
10807 ! msfvx, msfvy, xkhh, rdx, rdy, &
10808 ! fnm, fnp, cf1, cf2, cf3, &
10809 ! zx, zy, rdz, rdzw, dnw, dn, &
10811 ! ids, ide, jds, jde, kds, kde, &
10812 ! ims, ime, jms, jme, kms, kme, &
10813 ! its, ite, jts, jte, kts, kte )
10814 ! ENDDO scalar_loop
10818 !PART IV: REVERSE/BACKWARD ACCUMULATIONS
10821 ! DO IX4=1,n_scalar
10825 ! scalar_tendf(IX1,IX2,IX3,IX4) =Keep_Lpb9_scalar_tendf(IX1,IX2,IX3,IX4)
10831 ! IF(n_scalar .ge. PARAM_FIRST_SCALAR) THEN
10832 ! DO is =PARAM_FIRST_SCALAR, n_scalar
10833 ! Tmpv200(is) =scalar_tendf(ims,kms,jms,is)
10834 ! CALL horizontal_diffusion_s(scalar_tendf(ims,kms,jms,is),mu,config_flags,scalar( &
10835 ! ims,kms,jms,is),msftx,msfty,msfux,msfuy,msfvx,msfvy,xkhh,rdx,rdy,fnm,fnp,cf1,cf2,cf3, &
10836 ! zx,zy,rdz,rdzw,dnw,dn,.false.,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its, &
10837 ! ite,jts,jte,kts,kte)
10843 IF(n_scalar .ge. PARAM_FIRST_SCALAR) THEN
10845 DO is =n_scalar, PARAM_FIRST_SCALAR, -1
10847 ! scalar_tendf(ims,kms,jms,is) =Tmpv200(is) ! Remarked by Ning Pan, 2010-08-11
10849 CALL a_horizontal_diffusion_s(scalar_tendf(ims,kms,jms,is),a_scalar_tendf(ims, &
10850 kms,jms,is),mu,a_mu,config_flags,scalar(ims,kms,jms,is),a_scalar(ims,kms,jms,is) &
10851 ,msftx,msfty,msfux,msfuy,msfvx,msfvy,xkhh,a_xkhh,rdx,rdy,fnm,fnp,cf1,cf2,cf3,zx, &
10852 ! Revised by Ning Pan, 2010-08-10
10853 ! a_zx,zy,a_zy,rdz,a_rdz,rdzw,a_rdzw,dnw,dn,,ids,ide,jds,jde,kds,kde,ims,ime, &
10854 a_zx,zy,a_zy,rdz,a_rdz,rdzw,a_rdzw,dnw,dn,rho,a_rho,.false.,ids,ide,jds,jde,kds,kde,ims,ime, &
10855 jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
10863 ! Remarked by Ning Pan, 2010-08-10
10864 ! DO IX4=1,n_tracer
10868 ! tracer_tendf(IX1,IX2,IX3,IX4) =Keep_Lpb7_tracer_tendf(IX1,IX2,IX3,IX4)
10874 ! IF(n_tracer .ge. PARAM_FIRST_SCALAR) THEN
10875 ! DO ic =PARAM_FIRST_SCALAR, n_tracer
10876 ! Tmpv200(ic) =tracer_tendf(ims,kms,jms,ic)
10877 ! CALL horizontal_diffusion_s(tracer_tendf(ims,kms,jms,ic),mu,config_flags,tracer( &
10878 ! ims,kms,jms,ic),msftx,msfty,msfux,msfuy,msfvx,msfvy,xkhh,rdx,rdy,fnm,fnp,cf1,cf2,cf3, &
10879 ! zx,zy,rdz,rdzw,dnw,dn,.false.,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its, &
10880 ! ite,jts,jte,kts,kte)
10886 IF(n_tracer .ge. PARAM_FIRST_SCALAR) THEN
10888 DO ic =n_tracer, PARAM_FIRST_SCALAR, -1
10890 ! tracer_tendf(ims,kms,jms,ic) =Tmpv200(ic) ! Remarked by Ning Pan, 2010-08-11
10892 CALL a_horizontal_diffusion_s(tracer_tendf(ims,kms,jms,ic),a_tracer_tendf(ims, &
10893 kms,jms,ic),mu,a_mu,config_flags,tracer(ims,kms,jms,ic),a_tracer(ims,kms,jms,ic) &
10894 ,msftx,msfty,msfux,msfuy,msfvx,msfvy,xkhh,a_xkhh,rdx,rdy,fnm,fnp,cf1,cf2,cf3,zx, &
10895 ! Revised by Ning Pan, 2010-08-10
10896 ! a_zx,zy,a_zy,rdz,a_rdz,rdzw,a_rdzw,dnw,dn,,ids,ide,jds,jde,kds,kde,ims,ime, &
10897 a_zx,zy,a_zy,rdz,a_rdz,rdzw,a_rdzw,dnw,dn,rho,a_rho,.false.,ids,ide,jds,jde,kds,kde,ims,ime, &
10898 jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
10906 ! Remarked by Ning Pan, 2010-08-10
10911 ! chem_tendf(IX1,IX2,IX3,IX4) =Keep_Lpb5_chem_tendf(IX1,IX2,IX3,IX4)
10917 ! IF(n_chem .ge. PARAM_FIRST_SCALAR) THEN
10918 ! DO ic =PARAM_FIRST_SCALAR, n_chem
10919 ! Tmpv200(ic) =chem_tendf(ims,kms,jms,ic)
10920 ! CALL horizontal_diffusion_s(chem_tendf(ims,kms,jms,ic),mu,config_flags,chem(ims, &
10921 ! kms,jms,ic),msftx,msfty,msfux,msfuy,msfvx,msfvy,xkhh,rdx,rdy,fnm,fnp,cf1,cf2,cf3,zx, &
10922 ! zy,rdz,rdzw,dnw,dn,.false.,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite, &
10929 IF(n_chem .ge. PARAM_FIRST_SCALAR) THEN
10931 DO ic =n_chem, PARAM_FIRST_SCALAR, -1
10933 ! chem_tendf(ims,kms,jms,ic) =Tmpv200(ic) ! Remarked by Ning Pan, 2010-08-11
10935 CALL a_horizontal_diffusion_s(chem_tendf(ims,kms,jms,ic),a_chem_tendf(ims,kms, &
10936 jms,ic),mu,a_mu,config_flags,chem(ims,kms,jms,ic),a_chem(ims,kms,jms,ic) &
10937 ,msftx,msfty,msfux,msfuy,msfvx,msfvy,xkhh,a_xkhh,rdx,rdy,fnm,fnp,cf1,cf2,cf3,zx, &
10938 ! Revised by Ning Pan, 2010-08-10
10939 ! a_zx,zy,a_zy,rdz,a_rdz,rdzw,a_rdzw,dnw,dn,,ids,ide,jds,jde,kds,kde,ims,ime, &
10940 a_zx,zy,a_zy,rdz,a_rdz,rdzw,a_rdzw,dnw,dn,rho,a_rho,.false.,ids,ide,jds,jde,kds,kde,ims,ime, &
10941 jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
10949 ! Remarked by Ning Pan, 2010-08-10
10954 ! moist_tendf(IX1,IX2,IX3,IX4) =Keep_Lpb3_moist_tendf(IX1,IX2,IX3,IX4)
10960 ! IF(n_moist .ge. PARAM_FIRST_SCALAR) THEN
10961 ! DO im =PARAM_FIRST_SCALAR, n_moist
10962 ! Tmpv200(im) =moist_tendf(ims,kms,jms,im)
10963 ! CALL horizontal_diffusion_s(moist_tendf(ims,kms,jms,im),mu,config_flags,moist(ims, &
10964 ! kms,jms,im),msftx,msfty,msfux,msfuy,msfvx,msfvy,xkhh,rdx,rdy,fnm,fnp,cf1,cf2,cf3,zx, &
10965 ! zy,rdz,rdzw,dnw,dn,.false.,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite, &
10972 IF(n_moist .ge. PARAM_FIRST_SCALAR) THEN
10974 DO im =n_moist, PARAM_FIRST_SCALAR, -1
10976 ! moist_tendf(ims,kms,jms,im) =Tmpv200(im) ! Remarked by Ning Pan, 2010-08-11
10978 CALL a_horizontal_diffusion_s(moist_tendf(ims,kms,jms,im),a_moist_tendf(ims, &
10979 kms,jms,im),mu,a_mu,config_flags,moist(ims,kms,jms,im),a_moist(ims,kms,jms,im) &
10980 ,msftx,msfty,msfux,msfuy,msfvx,msfvy,xkhh,a_xkhh,rdx,rdy,fnm,fnp,cf1,cf2,cf3,zx, &
10981 ! Revised by Ning Pan, 2010-08-10
10982 ! a_zx,zy,a_zy,rdz,a_rdz,rdzw,a_rdzw,dnw,dn,,ids,ide,jds,jde,kds,kde,ims,ime, &
10983 a_zx,zy,a_zy,rdz,a_rdz,rdzw,a_rdzw,dnw,dn,rho,a_rho,.false.,ids,ide,jds,jde,kds,kde,ims,ime, &
10984 jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
10992 ! Remarked by Ning Pan, 2010-08-10
10996 ! tke_tendf(IX1,IX2,IX3) =Keep_Lpb1_tke_tendf(IX1,IX2,IX3)
11001 ! IF(km_opt .eq. 2) THEN
11002 ! Tmpv_1 =tke_tendf(ims,kms,jms)
11003 ! CALL horizontal_diffusion_s(tke_tendf(ims,kms,jms),mu,config_flags,tke(ims,kms, &
11004 ! jms),msftx,msfty,msfux,msfuy,msfvx,msfvy,xkhh,rdx,rdy,fnm,fnp,cf1,cf2,cf3,zx,zy,rdz, &
11005 ! rdzw,dnw,dn,.true.,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
11009 IF(km_opt .eq. 2) THEN
11011 ! tke_tendf(ims,kms,jms) =Tmpv_1 ! Remarked by Ning Pan, 2010-08-11
11013 CALL a_horizontal_diffusion_s(tke_tendf(ims,kms,jms),a_tke_tendf(ims,kms,jms) &
11014 ,mu,a_mu,config_flags,tke(ims,kms,jms),a_tke(ims,kms,jms),msftx,msfty,msfux, &
11015 msfuy,msfvx,msfvy,xkhh,a_xkhh,rdx,rdy,fnm,fnp,cf1,cf2,cf3,zx,a_zx,zy,a_zy,rdz, &
11016 ! Revised by Ning Pan, 2010-08-10
11017 ! a_rdz,rdzw,a_rdzw,dnw,dn,,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its, &
11018 a_rdz,rdzw,a_rdzw,dnw,dn,rho,a_rho,.true.,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its, &
11019 ite,jts,jte,kts,kte)
11024 ! Remarked by Ning Pan, 2010-08-10
11028 ! ru_tendf(IX1,IX2,IX3) =Keep_Lpb0_ru_tendf(IX1,IX2,IX3)
11032 ! DO IX4=1,n_nba_mij
11036 ! nba_mij(IX1,IX2,IX3,IX4) =Keep_Lpb0_nba_mij(IX1,IX2,IX3,IX4)
11044 ! rv_tendf(IX1,IX2,IX3) =Keep_Lpb0_rv_tendf(IX1,IX2,IX3)
11051 ! rw_tendf(IX1,IX2,IX3) =Keep_Lpb0_rw_tendf(IX1,IX2,IX3)
11058 ! rt_tendf(IX1,IX2,IX3) =Keep_Lpb0_rt_tendf(IX1,IX2,IX3)
11063 ! Remarked by Ning Pan, 2010-08-11
11067 ! Tmpv400(IX1,IX2,IX3) =ru_tendf(IX1,IX2,IX3)
11072 ! Remarked by Ning Pan, 2010-08-11
11073 ! DO IX4=1,n_nba_mij
11077 ! Tmpv500(IX1,IX2,IX3,IX4) =nba_mij(IX1,IX2,IX3,IX4)
11083 Keep_Lpb0_nba_mij = nba_mij ! Added by Ning Pan, 2010-08-11
11084 CALL horizontal_diffusion_u_2(ru_tendf,config_flags,defor11,defor12,div, &
11085 nba_mij,n_nba_mij,tke(ims,kms,jms),msfux,msfuy,xkmh,rdx,rdy,fnm,fnp,dnw,zx,zy,rdzw,rho,ids, &
11086 ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
11088 ! Remarked by Ning Pan, 2010-08-11: useless recomputation
11092 ! Tmpv401(IX1,IX2,IX3) =rv_tendf(IX1,IX2,IX3)
11097 ! DO IX4=1,n_nba_mij
11101 ! Tmpv501(IX1,IX2,IX3,IX4) =nba_mij(IX1,IX2,IX3,IX4)
11107 Keep_Lpb1_nba_mij = nba_mij ! Added by Ning Pan, 2010-08-11
11108 CALL horizontal_diffusion_v_2(rv_tendf,config_flags,defor12,defor22,div, &
11109 nba_mij,n_nba_mij,tke(ims,kms,jms),msfvx,msfvy,xkmh,rdx,rdy,fnm,fnp,dnw,zx,zy,rdzw,rho,ids, &
11110 ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
11115 ! Tmpv402(IX1,IX2,IX3) =rw_tendf(IX1,IX2,IX3)
11120 ! DO IX4=1,n_nba_mij
11124 ! Tmpv502(IX1,IX2,IX3,IX4) =nba_mij(IX1,IX2,IX3,IX4)
11130 ! CALL horizontal_diffusion_w_2(rw_tendf,mu,config_flags,defor13,defor23,div, &
11131 ! nba_mij,n_nba_mij,tke(ims,kms,jms),msftx,msfty,xkmh,rdx,rdy,fnm,fnp,dn,zx,zy,rdz,rho,ids, &
11132 ! ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
11137 ! Tmpv403(IX1,IX2,IX3) =rt_tendf(IX1,IX2,IX3)
11142 ! CALL horizontal_diffusion_s(rt_tendf,mu,config_flags,thp,msftx,msfty,msfux,msfuy, &
11143 ! msfvx,msfvy,xkhh,rdx,rdy,fnm,fnp,cf1,cf2,cf3,zx,zy,rdz,rdzw,dnw,dn,rho,.false.,ids,ide, &
11144 ! jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
11149 ! rt_tendf(IX1,IX2,IX3) =Tmpv403(IX1,IX2,IX3)
11154 CALL a_horizontal_diffusion_s(rt_tendf,a_rt_tendf,mu,a_mu,config_flags,thp, &
11155 a_thp,msftx,msfty,msfux,msfuy,msfvx,msfvy,xkhh,a_xkhh,rdx,rdy,fnm,fnp,cf1,cf2, &
11156 ! Revised by Ning Pan, 2010-08-10
11157 ! cf3,zx,a_zx,zy,a_zy,rdz,a_rdz,rdzw,a_rdzw,dnw,dn,,ids,ide,jds,jde,kds,kde, &
11158 cf3,zx,a_zx,zy,a_zy,rdz,a_rdz,rdzw,a_rdzw,dnw,dn,rho,a_rho,.false.,ids,ide,jds,jde,kds,kde, &
11159 ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
11161 ! Remarked by Ning Pan, 2010-08-11
11162 ! DO IX4=1,n_nba_mij
11166 ! nba_mij(IX1,IX2,IX3,IX4) =Tmpv502(IX1,IX2,IX3,IX4)
11175 ! rw_tendf(IX1,IX2,IX3) =Tmpv402(IX1,IX2,IX3)
11180 CALL a_horizontal_diffusion_w_2(rw_tendf,a_rw_tendf,mu,a_mu,config_flags, &
11181 defor13,a_defor13,defor23,a_defor23,div,a_div,nba_mij,a_nba_mij,n_nba_mij, &
11182 tke(ims,kms,jms),a_tke(ims,kms,jms),msftx,msfty,xkmh,a_xkmh,rdx,rdy,fnm,fnp,zx, &
11183 a_zx,zy,a_zy,rdz,a_rdz,rho,a_rho,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite, &
11186 ! Remarked by Ning Pan, 2010-08-11
11187 ! DO IX4=1,n_nba_mij
11191 ! nba_mij(IX1,IX2,IX3,IX4) =Tmpv501(IX1,IX2,IX3,IX4)
11200 ! rv_tendf(IX1,IX2,IX3) =Tmpv401(IX1,IX2,IX3)
11205 nba_mij = Keep_Lpb1_nba_mij ! Added by Ning Pan, 2010-08-11
11206 CALL a_horizontal_diffusion_v_2(rv_tendf,a_rv_tendf,mu,a_mu,config_flags, &
11207 defor12,a_defor12,defor22,a_defor22,div,a_div,nba_mij,a_nba_mij,n_nba_mij, &
11208 tke(ims,kms,jms),a_tke(ims,kms,jms),msfvx,msfvy,xkmh,a_xkmh,rdx,rdy,fnm,fnp,zx, &
11209 a_zx,zy,a_zy,rdzw,a_rdzw,rho,a_rho,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its, &
11210 ite,jts,jte,kts,kte)
11212 ! Remarked by Ning Pan, 2010-08-11
11213 ! DO IX4=1,n_nba_mij
11217 ! nba_mij(IX1,IX2,IX3,IX4) =Tmpv500(IX1,IX2,IX3,IX4)
11223 ! Remarked by Ning Pan, 2010-08-11
11227 ! ru_tendf(IX1,IX2,IX3) =Tmpv400(IX1,IX2,IX3)
11232 nba_mij = Keep_Lpb0_nba_mij ! Added by Ning Pan, 2010-08-11
11233 CALL a_horizontal_diffusion_u_2(ru_tendf,a_ru_tendf,mu,a_mu,config_flags, &
11234 defor11,a_defor11,defor12,a_defor12,div,a_div,nba_mij,a_nba_mij,n_nba_mij, &
11235 tke(ims,kms,jms),a_tke(ims,kms,jms),msfux,msfuy,xkmh,a_xkmh,rdx,rdy,fnm,fnp,zx, &
11236 a_zx,zy,a_zy,rdzw,a_rdzw,rho,a_rho,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its, &
11237 ite,jts,jte,kts,kte)
11239 END SUBROUTINE a_horizontal_diffusion_2
11241 SUBROUTINE a_horizontal_diffusion_u_2(tendency,a_tendency,mu,a_mu,config_flags, &
11242 defor11,a_defor11,defor12,a_defor12,div,a_div,nba_mij,a_nba_mij,n_nba_mij, &
11243 tke,a_tke,msfux,msfuy,xkmh,a_xkmh,rdx,rdy,fnm,fnp,zx,a_zx,zy,a_zy,rdzw, &
11244 a_rdzw,rho,a_rho,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
11246 !PART I: DECLARATION OF VARIABLES
11250 INTEGER :: K0_ADJ,K1_ADJ,K2_ADJ,K3_ADJ
11251 TYPE(grid_config_rec_type) :: config_flags
11252 INTEGER :: ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte
11253 REAL,DIMENSION(kms:kme) :: fnm
11254 REAL,DIMENSION(kms:kme) :: fnp
11255 REAL,DIMENSION(ims:ime,jms:jme) :: msfux,msfuy,mu,a_mu
11256 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: tendency,a_tendency
11257 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: rdzw,a_rdzw
11258 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: rho, a_rho
11259 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: defor11,a_defor11,defor12,a_defor12, &
11260 div,a_div,tke,a_tke,xkmh,a_xkmh,zx,a_zx,zy,a_zy
11261 INTEGER :: n_nba_mij
11262 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_nba_mij) :: nba_mij,a_nba_mij
11264 INTEGER :: i,j,k,ktf
11265 INTEGER :: i_start,i_end,j_start,j_end
11266 INTEGER :: is_ext,ie_ext,js_ext,je_ext
11267 REAL,DIMENSION(its-1:ite+1,kts:kte,jts-1:jte+1) :: titau1avg,a_titau1avg,titau2avg, &
11268 a_titau2avg,titau1,a_titau1,titau2,a_titau2,xkxavg,a_xkxavg,rravg,a_rravg
11269 REAL :: mrdx,a_mrdx,mrdy,a_mrdy,rcoup,a_rcoup
11270 REAL :: tmpzy,a_tmpzy,tmpzeta_z,a_tmpzeta_z
11271 REAL :: term1,a_term1,term2,a_term2,term3,a_term3
11273 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_nba_mij) :: Keep_Lpb12_nba_mij
11274 INTEGER :: IX1,IX2,IX3,IX4
11276 REAL :: a_Tmpv1,Tmpv001,a_Tmpv2,Tmpv002,a_Tmpv3,Tmpv003,a_Tmpv4,Tmpv004, &
11277 a_Tmpv5,Tmpv005,a_Tmpv6,Tmpv006,a_Tmpv7,Tmpv007,a_Tmpv8,Tmpv008,a_Tmpv9, &
11278 Tmpv009,a_Tmpv10,Tmpv010,a_Tmpv11,Tmpv011
11280 REAL :: Tmpv_1,Tmpv_2
11281 REAL,DIMENSION(its:ite,min0(kts+1,kts):min(kte,kde-1)) :: Tmpv300
11282 REAL,DIMENSION(its:ite,min0(kts+1,kts):min(kte,kde-1)) :: Tmpv301
11283 REAL,DIMENSION(its:ite,min0(kts+1,kts):min(kte,kde-1)) :: Tmpv302
11284 REAL,DIMENSION(its:ite,min0(kts+1,kts):min(kte,kde-1)) :: Tmpv303
11285 REAL,DIMENSION(its:ite,min0(kts+1,kts):min(kte,kde-1)) :: Tmpv304
11287 !PART II: CALCULATIONS OF B. S. TRAJECTORY
11295 j_end = MIN(jte,jde-1)
11298 IF ( config_flags%open_xs .or. config_flags%specified .or. &
11299 config_flags%nested) i_start = MAX(ids+1,its)
11304 IF ( config_flags%open_xe .or. config_flags%specified .or. &
11305 config_flags%nested) i_end = MIN(ide-1,ite)
11310 IF ( config_flags%open_ys .or. config_flags%specified .or. &
11311 config_flags%nested) j_start = MAX(jds+1,jts)
11316 IF ( config_flags%open_ye .or. config_flags%specified .or. &
11317 config_flags%nested) j_end = MIN(jde-2,jte)
11322 IF ( config_flags%periodic_x ) i_start = its
11327 IF ( config_flags%periodic_x ) i_end = ite
11334 Keep_Lpb12_nba_mij(IX1,IX2,IX3,IX4) =nba_mij(IX1,IX2,IX3,IX4)
11339 ! Remarked by Ning Pan, 2010-08-10
11340 ! DO IX4=1,n_nba_mij
11344 ! Keep_Lpb12_nba_mij(IX1,IX2,IX3,IX4) =nba_mij(IX1,IX2,IX3,IX4)
11354 CALL cal_titau_11_22_33( config_flags, titau1, &
11355 tke, xkmh, defor11, &
11356 nba_mij(ims,kms,jms,P_m11), rho, &
11357 is_ext, ie_ext, js_ext, je_ext, &
11358 ids, ide, jds, jde, kds, kde, &
11359 ims, ime, jms, jme, kms, kme, &
11360 its, ite, jts, jte, kts, kte )
11365 CALL cal_titau_12_21( config_flags, titau2, &
11367 nba_mij(ims,kms,jms,P_m12), rho, &
11368 is_ext, ie_ext, js_ext, je_ext, &
11369 ids, ide, jds, jde, kds, kde, &
11370 ims, ime, jms, jme, kms, kme, &
11371 its, ite, jts, jte, kts, kte )
11374 DO j = j_start, j_end
11377 DO i = i_start, i_end
11378 titau1avg(i,k,j)=0.5*(fnm(k)*(titau1(i-1,k ,j)+titau1(i,k ,j))+ &
11379 fnp(k)*(titau1(i-1,k-1,j)+titau1(i,k-1,j)))
11380 titau2avg(i,k,j)=0.5*(fnm(k)*(titau2(i,k ,j+1)+titau2(i,k ,j))+ &
11381 fnp(k)*(titau2(i,k-1,j+1)+titau2(i,k-1,j)))
11382 tmpzy = 0.25*( zy(i-1,k,j )+zy(i,k,j )+ &
11383 zy(i-1,k,j+1)+zy(i,k,j+1) )
11384 titau1avg(i,k,j)=titau1avg(i,k,j)*zx(i,k,j)
11385 titau2avg(i,k,j)=titau2avg(i,k,j)*tmpzy
11392 DO j = j_start, j_end
11394 DO i = i_start, i_end
11395 titau1avg(i,kts,j)=0.
11396 titau1avg(i,ktf+1,j)=0.
11397 titau2avg(i,kts,j)=0.
11398 titau2avg(i,ktf+1,j)=0.
11404 ! DO j = j_start, j_end
11407 ! DO i = i_start, i_end
11408 ! mrdx=msfux(i,j)*rdx
11409 ! mrdy=msfuy(i,j)*rdy
11410 ! tendency(i,k,j)=tendency(i,k,j)- &
11411 ! (mrdx*(titau1(i,k,j )-titau1(i-1,k,j))+ &
11412 ! mrdy*(titau2(i,k,j+1)-titau2(i,k,j ))- &
11413 ! msfuy(i,j)*rdzw(i,k,j)*((titau1avg(i,k+1,j)-titau1avg(i,k,j))+ &
11414 ! (titau2avg(i,k+1,j)-titau2avg(i,k,j)) &
11421 !PART III: INITIALIZATION OF LOCAL ADJOINT PERTURBATIONS
11423 Do K2_ADJ =jts-1, jte+1
11424 Do K1_ADJ =kts, kte
11425 Do K0_ADJ =its-1, ite+1
11426 a_titau1avg(K0_ADJ,K1_ADJ,K2_ADJ) =0.0
11431 Do K2_ADJ =jts-1, jte+1
11432 Do K1_ADJ =kts, kte
11433 Do K0_ADJ =its-1, ite+1
11434 a_titau2avg(K0_ADJ,K1_ADJ,K2_ADJ) =0.0
11439 Do K2_ADJ =jts-1, jte+1
11440 Do K1_ADJ =kts, kte
11441 Do K0_ADJ =its-1, ite+1
11442 a_titau1(K0_ADJ,K1_ADJ,K2_ADJ) =0.0
11447 Do K2_ADJ =jts-1, jte+1
11448 Do K1_ADJ =kts, kte
11449 Do K0_ADJ =its-1, ite+1
11450 a_titau2(K0_ADJ,K1_ADJ,K2_ADJ) =0.0
11455 Do K2_ADJ =jts-1, jte+1
11456 Do K1_ADJ =kts, kte
11457 Do K0_ADJ =its-1, ite+1
11458 a_xkxavg(K0_ADJ,K1_ADJ,K2_ADJ) =0.0
11463 Do K2_ADJ =jts-1, jte+1
11464 Do K1_ADJ =kts, kte
11465 Do K0_ADJ =its-1, ite+1
11466 a_rravg(K0_ADJ,K1_ADJ,K2_ADJ) =0.0
11471 ! Remarked by Ning Pan, 2010-08-10
11476 ! Remarked by Ning Pan, 2010-08-10
11482 !PART IV: REVERSE/BACKWARD ACCUMULATIONS
11485 DO j =j_end, j_start, -1
11488 DO i =i_start, i_end
11489 ! Revised by Ning Pan, 2010-08-10
11490 ! Tmpv300(i,k) =mrdx
11491 ! mrdx =msfux(i,j)*rdx
11492 mrdx =msfux(i,j)*rdx
11495 ! Revised by Ning Pan, 2010-08-10
11496 ! Tmpv301(i,k) =mrdy
11497 ! mrdy =msfuy(i,j)*rdy
11498 mrdy =msfuy(i,j)*rdy
11501 Tmpv001 =titau1(i,k,j) -titau1(i-1,k,j)
11502 Tmpv302(i,k) =Tmpv001
11503 Tmpv002 =mrdx*Tmpv302(i,k)
11504 Tmpv003 =titau2(i,k,j+1) -titau2(i,k,j)
11505 Tmpv303(i,k) =Tmpv003
11506 Tmpv004 =mrdy*Tmpv303(i,k)
11507 Tmpv005 =Tmpv002 +Tmpv004
11508 Tmpv006 =titau1avg(i,k+1,j) -titau1avg(i,k,j)
11509 Tmpv007 =titau2avg(i,k+1,j) -titau2avg(i,k,j)
11510 Tmpv008 =Tmpv006 +Tmpv007
11511 Tmpv304(i,k) =Tmpv008
11512 ! Remarked by Ning Pan, 2010-08-10
11513 ! Tmpv009 =msfuy(i,j)*rdzw(i,k,j)*Tmpv304(i,k)
11514 ! Tmpv010 =Tmpv005 -Tmpv009
11515 ! Tmpv011 =tendency(i,k,j) -Tmpv010
11516 ! tendency(i,k,j) =Tmpv011
11522 DO i =i_end, i_start, -1
11523 mrdx =Tmpv300(i,k) ! Added by Ning Pan, 2010-08-10
11524 mrdy =Tmpv301(i,k) ! Added by Ning Pan, 2010-08-10
11525 a_Tmpv11 =a_tendency(i,k,j)
11526 a_tendency(i,k,j) =0.0
11527 a_tendency(i,k,j) =a_tendency(i,k,j) +a_Tmpv11
11528 a_Tmpv10 =-a_Tmpv11
11531 a_rdzw(i,k,j) =a_rdzw(i,k,j) +msfuy(i,j)*Tmpv304(i,k)*a_Tmpv9
11532 a_Tmpv8 =msfuy(i,j)*rdzw(i,k,j)*a_Tmpv9
11535 a_titau2avg(i,k+1,j) =a_titau2avg(i,k+1,j) +a_Tmpv7
11536 a_titau2avg(i,k,j) =a_titau2avg(i,k,j) -a_Tmpv7
11537 a_titau1avg(i,k+1,j) =a_titau1avg(i,k+1,j) +a_Tmpv6
11538 a_titau1avg(i,k,j) =a_titau1avg(i,k,j) -a_Tmpv6
11541 a_mrdy =a_mrdy +Tmpv303(i,k)*a_Tmpv4
11542 a_Tmpv3 =mrdy*a_Tmpv4
11543 a_titau2(i,k,j+1) =a_titau2(i,k,j+1) +a_Tmpv3
11544 a_titau2(i,k,j) =a_titau2(i,k,j) -a_Tmpv3
11545 a_mrdx =a_mrdx +Tmpv302(i,k)*a_Tmpv2
11546 a_Tmpv1 =mrdx*a_Tmpv2
11547 a_titau1(i,k,j) =a_titau1(i,k,j) +a_Tmpv1
11548 a_titau1(i-1,k,j) =a_titau1(i-1,k,j) -a_Tmpv1
11550 ! Remarked by Ning Pan, 2010-08-10
11551 ! mrdy =Tmpv301(i,k)
11555 ! mrdx =Tmpv300(i,k)
11564 DO j =j_end, j_start, -1
11566 ! DO i =i_start, i_end
11567 ! titau1avg(i,kts,j) =0.
11569 ! titau1avg(i,ktf+1,j) =0.
11571 ! titau2avg(i,kts,j) =0.
11573 ! titau2avg(i,ktf+1,j) =0.
11577 DO i =i_end, i_start, -1
11578 a_titau2avg(i,ktf+1,j) =0.0
11579 a_titau2avg(i,kts,j) =0.0
11580 a_titau1avg(i,ktf+1,j) =0.0
11581 a_titau1avg(i,kts,j) =0.0
11587 DO j =j_end, j_start, -1
11590 DO i =i_start, i_end
11591 Tmpv001 =titau1(i-1,k,j) +titau1(i,k,j)
11592 Tmpv002 =fnm(k)*Tmpv001
11593 Tmpv003 =titau1(i-1,k-1,j) +titau1(i,k-1,j)
11594 Tmpv004 =fnp(k)*Tmpv003
11595 Tmpv005 =Tmpv002 +Tmpv004
11596 Tmpv006 =0.5*Tmpv005
11597 ! Revised by Ning Pan, 2010-08-10
11598 ! Tmpv300(i,k) =titau1avg(i,k,j)
11599 ! titau1avg(i,k,j) =Tmpv006
11600 titau1avg(i,k,j) =Tmpv006
11601 Tmpv300(i,k) =titau1avg(i,k,j)
11603 Tmpv001 =titau2(i,k,j+1) +titau2(i,k,j)
11604 Tmpv002 =fnm(k)*Tmpv001
11605 Tmpv003 =titau2(i,k-1,j+1) +titau2(i,k-1,j)
11606 Tmpv004 =fnp(k)*Tmpv003
11607 Tmpv005 =Tmpv002 +Tmpv004
11608 Tmpv006 =0.5*Tmpv005
11609 ! Revised by Ning Pan, 2010-08-10
11610 ! Tmpv301(i,k) =titau2avg(i,k,j)
11611 ! titau2avg(i,k,j) =Tmpv006
11612 titau2avg(i,k,j) =Tmpv006
11613 Tmpv301(i,k) =titau2avg(i,k,j)
11615 Tmpv001 =zy(i-1,k,j) +zy(i,k,j)
11616 Tmpv002 =Tmpv001 +zy(i-1,k,j+1)
11617 Tmpv003 =Tmpv002 +zy(i,k,j+1)
11618 Tmpv004 =0.25*Tmpv003
11619 ! Revised by Ning Pan, 2010-08-10
11620 ! Tmpv302(i,k) =tmpzy
11623 Tmpv302(i,k) =tmpzy
11625 ! Remarked by Ning Pan, 2010-08-10
11626 ! Tmpv001 =titau1avg(i,k,j)*zx(i,k,j)
11627 ! Tmpv303(i,k) =titau1avg(i,k,j)
11628 ! titau1avg(i,k,j) =Tmpv001
11630 ! Remarked by Ning Pan, 2010-08-10
11631 ! Tmpv001 =titau2avg(i,k,j)*tmpzy
11632 ! Tmpv304(i,k) =titau2avg(i,k,j)
11633 ! titau2avg(i,k,j) =Tmpv001
11638 DO k =ktf, kts+1, -1
11639 DO i =i_end, i_start, -1
11641 tmpzy =Tmpv302(i,k) ! Added by Ning Pan, 2010-08-10
11643 ! Revised by Ning Pan, 2010-08-10
11644 ! titau2avg(i,k,j) =Tmpv304(i,k)
11645 titau2avg(i,k,j) =Tmpv301(i,k)
11647 a_Tmpv1 =a_titau2avg(i,k,j)
11648 a_titau2avg(i,k,j) =0.0
11649 a_titau2avg(i,k,j) =a_titau2avg(i,k,j) +tmpzy*a_Tmpv1
11650 a_tmpzy =a_tmpzy +titau2avg(i,k,j)*a_Tmpv1
11652 ! Revised by Ning Pan, 2010-08-10
11653 ! titau1avg(i,k,j) =Tmpv303(i,k)
11654 titau1avg(i,k,j) =Tmpv300(i,k)
11656 a_Tmpv1 =a_titau1avg(i,k,j)
11657 a_titau1avg(i,k,j) =0.0
11658 a_titau1avg(i,k,j) =a_titau1avg(i,k,j) +zx(i,k,j)*a_Tmpv1
11659 a_zx(i,k,j) =a_zx(i,k,j) +titau1avg(i,k,j)*a_Tmpv1
11661 ! tmpzy =Tmpv302(i,k) ! Remarked by Ning Pan, 2010-08-10
11665 a_Tmpv3 =0.25*a_Tmpv4
11667 a_zy(i,k,j+1) =a_zy(i,k,j+1) +a_Tmpv3
11669 a_zy(i-1,k,j+1) =a_zy(i-1,k,j+1) +a_Tmpv2
11670 a_zy(i-1,k,j) =a_zy(i-1,k,j) +a_Tmpv1
11671 a_zy(i,k,j) =a_zy(i,k,j) +a_Tmpv1
11673 ! titau2avg(i,k,j) =Tmpv301(i,k) ! Remarked by Ning Pan, 2010-08-10
11675 a_Tmpv6 =a_titau2avg(i,k,j)
11676 a_titau2avg(i,k,j) =0.0
11677 a_Tmpv5 =0.5*a_Tmpv6
11680 a_Tmpv3 =fnp(k)*a_Tmpv4
11681 a_titau2(i,k-1,j+1) =a_titau2(i,k-1,j+1) +a_Tmpv3
11682 a_titau2(i,k-1,j) =a_titau2(i,k-1,j) +a_Tmpv3
11683 a_Tmpv1 =fnm(k)*a_Tmpv2
11684 a_titau2(i,k,j+1) =a_titau2(i,k,j+1) +a_Tmpv1
11685 a_titau2(i,k,j) =a_titau2(i,k,j) +a_Tmpv1
11687 ! titau1avg(i,k,j) =Tmpv300(i,k) ! Remarked by Ning Pan, 2010-08-10
11689 a_Tmpv6 =a_titau1avg(i,k,j)
11690 a_titau1avg(i,k,j) =0.0
11691 a_Tmpv5 =0.5*a_Tmpv6
11694 a_Tmpv3 =fnp(k)*a_Tmpv4
11695 a_titau1(i-1,k-1,j) =a_titau1(i-1,k-1,j) +a_Tmpv3
11696 a_titau1(i,k-1,j) =a_titau1(i,k-1,j) +a_Tmpv3
11697 a_Tmpv1 =fnm(k)*a_Tmpv2
11698 a_titau1(i-1,k,j) =a_titau1(i-1,k,j) +a_Tmpv1
11699 a_titau1(i,k,j) =a_titau1(i,k,j) +a_Tmpv1
11706 ! Remarked by Ning Pan, 2010-08-10
11707 ! DO IX4=1,n_nba_mij
11711 ! nba_mij(IX1,IX2,IX3,IX4) =Keep_Lpb12_nba_mij(IX1,IX2,IX3,IX4)
11716 ! DO IX4=1,n_nba_mij
11720 ! nba_mij(IX1,IX2,IX3,IX4) =Keep_Lpb12_nba_mij(IX1,IX2,IX3,IX4)
11726 ! Remarked by Ning Pan, 2010-08-10
11731 ! Tmpv_1 =nba_mij(ims,kms,jms,P_m11)
11732 ! CALL cal_titau_11_22_33(config_flags,titau1,mu,tke,xkmh,defor11,nba_mij(ims,kms, &
11733 ! jms,P_m11),is_ext,ie_ext,js_ext,je_ext,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms, &
11734 ! kme,its,ite,jts,jte,kts,kte)
11740 ! Tmpv_2 =nba_mij(ims,kms,jms,P_m12)
11741 ! CALL cal_titau_12_21(config_flags,titau2,mu,xkmh,defor12,nba_mij(ims,kms,jms, &
11742 ! P_m12),is_ext,ie_ext,js_ext,je_ext,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme, &
11743 ! its,ite,jts,jte,kts,kte)
11745 ! nba_mij(ims,kms,jms,P_m12) =Tmpv_2
11747 ! Added by Ning Pan, 2010-08-10
11753 CALL a_cal_titau_12_21(config_flags,titau2,a_titau2,mu,a_mu,xkmh,a_xkmh, &
11754 defor12,a_defor12,nba_mij(ims,kms,jms,P_m12),a_nba_mij(ims,kms,jms,P_m12) &
11756 ,is_ext,ie_ext,js_ext,je_ext,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite, &
11759 ! nba_mij(ims,kms,jms,P_m11) =Tmpv_1 ! Remarked by Ning Pan, 2010-08-10
11761 ! Added by Ning Pan, 2010-08-10
11770 nba_mij(IX1,IX2,IX3,IX4) =Keep_Lpb12_nba_mij(IX1,IX2,IX3,IX4)
11776 CALL a_cal_titau_11_22_33(config_flags,titau1,a_titau1,mu,a_mu,tke,a_tke, &
11777 xkmh,a_xkmh,defor11,a_defor11,nba_mij(ims,kms,jms,P_m11),a_nba_mij(ims,kms,jms, &
11778 P_m11),rho,a_rho,is_ext,ie_ext,js_ext,je_ext,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme, &
11779 its,ite,jts,jte,kts,kte)
11783 ! IF( config_flags%periodic_x ) THEN
11787 ! IF( config_flags%periodic_x ) THEN
11795 ! IF( config_flags%periodic_x ) THEN
11799 ! IF( config_flags%periodic_x ) THEN
11807 ! IF( config_flags%open_ye .or. config_flags%specified .or. config_flags%nested) THEN
11808 ! j_end =min(jde-2, jte)
11811 ! IF( config_flags%open_ye .or. config_flags%specified .or. &
11812 ! config_flags%nested) THEN
11820 ! IF( config_flags%open_ys .or. config_flags%specified .or. config_flags%nested) THEN
11821 ! j_start =max(jds+1, jts)
11824 ! IF( config_flags%open_ys .or. config_flags%specified .or. &
11825 ! config_flags%nested) THEN
11833 ! IF( config_flags%open_xe .or. config_flags%specified .or. config_flags%nested) THEN
11834 ! i_end =min(ide-1, ite)
11837 ! IF( config_flags%open_xe .or. config_flags%specified .or. &
11838 ! config_flags%nested) THEN
11846 ! IF( config_flags%open_xs .or. config_flags%specified .or. config_flags%nested) THEN
11847 ! i_start =max(ids+1, its)
11850 ! IF( config_flags%open_xs .or. config_flags%specified .or. &
11851 ! config_flags%nested) THEN
11856 ! ktf =min(kte, kde-1)
11860 ! j_end =min(jte, jde-1)
11862 END SUBROUTINE a_horizontal_diffusion_u_2
11864 SUBROUTINE a_horizontal_diffusion_v_2(tendency,a_tendency,mu,a_mu,config_flags, &
11865 defor12,a_defor12,defor22,a_defor22,div,a_div,nba_mij,a_nba_mij,n_nba_mij, &
11866 tke,a_tke,msfvx,msfvy,xkmh,a_xkmh,rdx,rdy,fnm,fnp,zx,a_zx,zy,a_zy,rdzw, &
11867 a_rdzw,rho,a_rho,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
11869 !PART I: DECLARATION OF VARIABLES
11873 INTEGER :: K0_ADJ,K1_ADJ,K2_ADJ,K3_ADJ
11874 TYPE(grid_config_rec_type) :: config_flags
11875 INTEGER :: ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte
11876 REAL,DIMENSION(kms:kme) :: fnm
11877 REAL,DIMENSION(kms:kme) :: fnp
11878 REAL,DIMENSION(ims:ime,jms:jme) :: msfvx,msfvy,mu,a_mu
11879 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: tendency,a_tendency
11880 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: defor12,a_defor12,defor22,a_defor22, &
11881 div,a_div,tke,a_tke,xkmh,a_xkmh,zx,a_zx,zy,a_zy,rdzw,a_rdzw
11882 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: rho, a_rho
11883 INTEGER :: n_nba_mij
11884 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_nba_mij) :: nba_mij,a_nba_mij
11886 INTEGER :: i,j,k,ktf
11887 INTEGER :: i_start,i_end,j_start,j_end
11888 INTEGER :: is_ext,ie_ext,js_ext,je_ext
11889 REAL,DIMENSION(its-1:ite+1,kts:kte,jts-1:jte+1) :: titau1avg,a_titau1avg,titau2avg, &
11890 a_titau2avg,titau1,a_titau1,titau2,a_titau2,xkxavg,a_xkxavg,rravg,a_rravg
11891 REAL :: mrdx,a_mrdx,mrdy,a_mrdy,rcoup,a_rcoup
11892 REAL :: tmpzx,a_tmpzx,tmpzeta_z,a_tmpzeta_z
11894 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_nba_mij) :: Keep_Lpb12_nba_mij
11895 INTEGER :: IX1,IX2,IX3,IX4
11897 REAL :: a_Tmpv1,Tmpv001,a_Tmpv2,Tmpv002,a_Tmpv3,Tmpv003,a_Tmpv4,Tmpv004, &
11898 a_Tmpv5,Tmpv005,a_Tmpv6,Tmpv006,a_Tmpv7,Tmpv007,a_Tmpv8,Tmpv008,a_Tmpv9, &
11899 Tmpv009,a_Tmpv10,Tmpv010,a_Tmpv11,Tmpv011
11901 REAL :: Tmpv_1,Tmpv_2
11902 REAL,DIMENSION(its:min(ite,ide-1),min0(kts+1,kts):min(kte,kde-1)) :: Tmpv300
11903 REAL,DIMENSION(its:min(ite,ide-1),min0(kts+1,kts):min(kte,kde-1)) :: Tmpv301
11904 REAL,DIMENSION(its:min(ite,ide-1),min0(kts+1,kts):min(kte,kde-1)) :: Tmpv302
11905 REAL,DIMENSION(its:min(ite,ide-1),min0(kts+1,kts):min(kte,kde-1)) :: Tmpv303
11906 REAL,DIMENSION(its:min(ite,ide-1),min0(kts+1,kts):min(kte,kde-1)) :: Tmpv304
11908 !PART II: CALCULATIONS OF B. S. TRAJECTORY
11913 i_end = MIN(ite,ide-1)
11918 IF ( config_flags%open_xs .or. config_flags%specified .or. &
11919 config_flags%nested) i_start = MAX(ids+1,its)
11924 IF ( config_flags%open_xe .or. config_flags%specified .or. &
11925 config_flags%nested) i_end = MIN(ide-2,ite)
11930 IF ( config_flags%open_ys .or. config_flags%specified .or. &
11931 config_flags%nested) j_start = MAX(jds+1,jts)
11936 IF ( config_flags%open_ye .or. config_flags%specified .or. &
11937 config_flags%nested) j_end = MIN(jde-1,jte)
11942 IF ( config_flags%periodic_x ) i_start = its
11947 IF ( config_flags%periodic_x ) i_end = MIN(ite,ide-1)
11954 Keep_Lpb12_nba_mij(IX1,IX2,IX3,IX4) =nba_mij(IX1,IX2,IX3,IX4)
11959 ! Remarked by Ning Pan, 2010-08-10
11960 ! DO IX4=1,n_nba_mij
11964 ! Keep_Lpb12_nba_mij(IX1,IX2,IX3,IX4) =nba_mij(IX1,IX2,IX3,IX4)
11974 CALL cal_titau_12_21( config_flags, titau1, &
11976 nba_mij(ims,kms,jms,P_m12), rho, &
11977 is_ext,ie_ext,js_ext,je_ext, &
11978 ids, ide, jds, jde, kds, kde, &
11979 ims, ime, jms, jme, kms, kme, &
11980 its, ite, jts, jte, kts, kte )
11985 CALL cal_titau_11_22_33( config_flags, titau2, &
11986 tke, xkmh, defor22, &
11987 nba_mij(ims,kms,jms,P_m22), rho, &
11988 is_ext, ie_ext, js_ext, je_ext, &
11989 ids, ide, jds, jde, kds, kde, &
11990 ims, ime, jms, jme, kms, kme, &
11991 its, ite, jts, jte, kts, kte )
11994 DO j = j_start, j_end
11997 DO i = i_start, i_end
11998 titau1avg(i,k,j)=0.5*(fnm(k)*(titau1(i+1,k ,j)+titau1(i,k ,j))+ &
11999 fnp(k)*(titau1(i+1,k-1,j)+titau1(i,k-1,j)))
12000 titau2avg(i,k,j)=0.5*(fnm(k)*(titau2(i,k ,j-1)+titau2(i,k ,j))+ &
12001 fnp(k)*(titau2(i,k-1,j-1)+titau2(i,k-1,j)))
12002 tmpzx = 0.25*( zx(i,k,j )+zx(i+1,k,j )+ &
12003 zx(i,k,j-1)+zx(i+1,k,j-1) )
12004 titau1avg(i,k,j)=titau1avg(i,k,j)*tmpzx
12005 titau2avg(i,k,j)=titau2avg(i,k,j)*zy(i,k,j)
12012 DO j = j_start, j_end
12014 DO i = i_start, i_end
12015 titau1avg(i,kts,j)=0.
12016 titau1avg(i,ktf+1,j)=0.
12017 titau2avg(i,kts,j)=0.
12018 titau2avg(i,ktf+1,j)=0.
12024 ! DO j = j_start, j_end
12027 ! DO i = i_start, i_end
12028 ! mrdx=msfvx(i,j)*rdx
12029 ! mrdy=msfvy(i,j)*rdy
12030 ! tendency(i,k,j)=tendency(i,k,j)- &
12031 ! (mrdy*(titau2(i ,k,j)-titau2(i,k,j-1))+ &
12032 ! mrdx*(titau1(i+1,k,j)-titau1(i,k,j ))- &
12033 ! msfvy(i,j)*rdzw(i,k,j)*((titau1avg(i,k+1,j)-titau1avg(i,k,j))+ &
12034 ! (titau2avg(i,k+1,j)-titau2avg(i,k,j)) &
12042 !PART III: INITIALIZATION OF LOCAL ADJOINT PERTURBATIONS
12044 Do K2_ADJ =jts-1, jte+1
12045 Do K1_ADJ =kts, kte
12046 Do K0_ADJ =its-1, ite+1
12047 a_titau1avg(K0_ADJ,K1_ADJ,K2_ADJ) =0.0
12052 Do K2_ADJ =jts-1, jte+1
12053 Do K1_ADJ =kts, kte
12054 Do K0_ADJ =its-1, ite+1
12055 a_titau2avg(K0_ADJ,K1_ADJ,K2_ADJ) =0.0
12060 Do K2_ADJ =jts-1, jte+1
12061 Do K1_ADJ =kts, kte
12062 Do K0_ADJ =its-1, ite+1
12063 a_titau1(K0_ADJ,K1_ADJ,K2_ADJ) =0.0
12068 Do K2_ADJ =jts-1, jte+1
12069 Do K1_ADJ =kts, kte
12070 Do K0_ADJ =its-1, ite+1
12071 a_titau2(K0_ADJ,K1_ADJ,K2_ADJ) =0.0
12076 Do K2_ADJ =jts-1, jte+1
12077 Do K1_ADJ =kts, kte
12078 Do K0_ADJ =its-1, ite+1
12079 a_xkxavg(K0_ADJ,K1_ADJ,K2_ADJ) =0.0
12084 Do K2_ADJ =jts-1, jte+1
12085 Do K1_ADJ =kts, kte
12086 Do K0_ADJ =its-1, ite+1
12087 a_rravg(K0_ADJ,K1_ADJ,K2_ADJ) =0.0
12092 ! Remarked by Ning Pan, 2010-08-10
12097 ! a_tmpzeta_z =0.0 ! Remarked by Ning Pan, 2010-08-10
12099 !PART IV: REVERSE/BACKWARD ACCUMULATIONS
12102 DO j =j_end, j_start, -1
12105 DO i =i_start, i_end
12106 ! Revised by Ning Pan, 2010-08-10
12107 ! Tmpv300(i,k) =mrdx
12108 ! mrdx =msfvx(i,j)*rdx
12109 mrdx =msfvx(i,j)*rdx
12112 ! Revised by Ning Pan, 2010-08-10
12113 ! Tmpv301(i,k) =mrdy
12114 ! mrdy =msfvy(i,j)*rdy
12115 mrdy =msfvy(i,j)*rdy
12118 Tmpv001 =titau2(i,k,j) -titau2(i,k,j-1)
12119 Tmpv302(i,k) =Tmpv001
12120 Tmpv002 =mrdy*Tmpv302(i,k)
12121 Tmpv003 =titau1(i+1,k,j) -titau1(i,k,j)
12122 Tmpv303(i,k) =Tmpv003
12123 Tmpv004 =mrdx*Tmpv303(i,k)
12124 Tmpv005 =Tmpv002 +Tmpv004
12125 Tmpv006 =titau1avg(i,k+1,j) -titau1avg(i,k,j)
12126 Tmpv007 =titau2avg(i,k+1,j) -titau2avg(i,k,j)
12127 Tmpv008 =Tmpv006 +Tmpv007
12128 Tmpv304(i,k) =Tmpv008
12129 ! Remarked by Ning Pan, 2010-08-10
12130 ! Tmpv009 =msfvy(i,j)*rdzw(i,k,j)*Tmpv304(i,k)
12131 ! Tmpv010 =Tmpv005 -Tmpv009
12132 ! Tmpv011 =tendency(i,k,j) -Tmpv010
12133 ! tendency(i,k,j) =Tmpv011
12139 DO i =i_end, i_start, -1
12140 mrdx =Tmpv300(i,k) ! Added by Ning Pan, 2010-08-10
12141 mrdy =Tmpv301(i,k) ! Added by Ning Pan, 2010-08-10
12142 a_Tmpv11 =a_tendency(i,k,j)
12143 a_tendency(i,k,j) =0.0
12144 a_tendency(i,k,j) =a_tendency(i,k,j) +a_Tmpv11
12145 a_Tmpv10 =-a_Tmpv11
12148 a_rdzw(i,k,j) =a_rdzw(i,k,j) +msfvy(i,j)*Tmpv304(i,k)*a_Tmpv9
12149 a_Tmpv8 =msfvy(i,j)*rdzw(i,k,j)*a_Tmpv9
12152 a_titau2avg(i,k+1,j) =a_titau2avg(i,k+1,j) +a_Tmpv7
12153 a_titau2avg(i,k,j) =a_titau2avg(i,k,j) -a_Tmpv7
12154 a_titau1avg(i,k+1,j) =a_titau1avg(i,k+1,j) +a_Tmpv6
12155 a_titau1avg(i,k,j) =a_titau1avg(i,k,j) -a_Tmpv6
12158 a_mrdx =a_mrdx +Tmpv303(i,k)*a_Tmpv4
12159 a_Tmpv3 =mrdx*a_Tmpv4
12160 a_titau1(i+1,k,j) =a_titau1(i+1,k,j) +a_Tmpv3
12161 a_titau1(i,k,j) =a_titau1(i,k,j) -a_Tmpv3
12162 a_mrdy =a_mrdy +Tmpv302(i,k)*a_Tmpv2
12163 a_Tmpv1 =mrdy*a_Tmpv2
12164 a_titau2(i,k,j) =a_titau2(i,k,j) +a_Tmpv1
12165 a_titau2(i,k,j-1) =a_titau2(i,k,j-1) -a_Tmpv1
12167 ! Remarked by Ning Pan, 2010-08-10
12168 ! mrdy =Tmpv301(i,k)
12172 ! mrdx =Tmpv300(i,k)
12181 DO j =j_end, j_start, -1
12183 ! DO i =i_start, i_end
12184 ! titau1avg(i,kts,j) =0.
12186 ! titau1avg(i,ktf+1,j) =0.
12188 ! titau2avg(i,kts,j) =0.
12190 ! titau2avg(i,ktf+1,j) =0.
12194 DO i =i_end, i_start, -1
12195 a_titau2avg(i,ktf+1,j) =0.0
12196 a_titau2avg(i,kts,j) =0.0
12197 a_titau1avg(i,ktf+1,j) =0.0
12198 a_titau1avg(i,kts,j) =0.0
12204 DO j =j_end, j_start, -1
12207 DO i =i_start, i_end
12208 Tmpv001 =titau1(i+1,k,j) +titau1(i,k,j)
12209 Tmpv002 =fnm(k)*Tmpv001
12210 Tmpv003 =titau1(i+1,k-1,j) +titau1(i,k-1,j)
12211 Tmpv004 =fnp(k)*Tmpv003
12212 Tmpv005 =Tmpv002 +Tmpv004
12213 Tmpv006 =0.5*Tmpv005
12214 ! Revised by Ning Pan, 2010-08-10
12215 ! Tmpv300(i,k) =titau1avg(i,k,j)
12216 ! titau1avg(i,k,j) =Tmpv006
12217 titau1avg(i,k,j) =Tmpv006
12218 Tmpv300(i,k) =titau1avg(i,k,j)
12220 Tmpv001 =titau2(i,k,j-1) +titau2(i,k,j)
12221 Tmpv002 =fnm(k)*Tmpv001
12222 Tmpv003 =titau2(i,k-1,j-1) +titau2(i,k-1,j)
12223 Tmpv004 =fnp(k)*Tmpv003
12224 Tmpv005 =Tmpv002 +Tmpv004
12225 Tmpv006 =0.5*Tmpv005
12226 ! Revised by Ning Pan, 2010-08-10
12227 ! Tmpv301(i,k) =titau2avg(i,k,j)
12228 ! titau2avg(i,k,j) =Tmpv006
12229 titau2avg(i,k,j) =Tmpv006
12230 Tmpv301(i,k) =titau2avg(i,k,j)
12232 Tmpv001 =zx(i,k,j) +zx(i+1,k,j)
12233 Tmpv002 =Tmpv001 +zx(i,k,j-1)
12234 Tmpv003 =Tmpv002 +zx(i+1,k,j-1)
12235 Tmpv004 =0.25*Tmpv003
12236 ! Revised by Ning Pan, 2010-08-10
12237 ! Tmpv302(i,k) =tmpzx
12240 Tmpv302(i,k) =tmpzx
12242 ! Remarked by Ning Pan, 2010-08-10
12243 ! Tmpv001 =titau1avg(i,k,j)*tmpzx
12244 ! Tmpv303(i,k) =titau1avg(i,k,j)
12245 ! titau1avg(i,k,j) =Tmpv001
12247 ! Remarked by Ning Pan, 2010-08-10
12248 ! Tmpv001 =titau2avg(i,k,j)*zy(i,k,j)
12249 ! Tmpv304(i,k) =titau2avg(i,k,j)
12250 ! titau2avg(i,k,j) =Tmpv001
12255 DO k =ktf, kts+1, -1
12256 DO i =i_end, i_start, -1
12258 ! Revised by Ning Pan, 2010-08-10
12259 ! titau2avg(i,k,j) =Tmpv304(i,k)
12260 titau2avg(i,k,j) =Tmpv301(i,k)
12262 a_Tmpv1 =a_titau2avg(i,k,j)
12263 a_titau2avg(i,k,j) =0.0
12264 a_titau2avg(i,k,j) =a_titau2avg(i,k,j) +zy(i,k,j)*a_Tmpv1
12265 a_zy(i,k,j) =a_zy(i,k,j) +titau2avg(i,k,j)*a_Tmpv1
12267 tmpzx =Tmpv302(i,k) ! Added by Ning Pan, 2010-08-10
12268 ! Revised by Ning Pan, 2010-08-10
12269 ! titau1avg(i,k,j) =Tmpv303(i,k)
12270 titau1avg(i,k,j) =Tmpv300(i,k)
12272 a_Tmpv1 =a_titau1avg(i,k,j)
12273 a_titau1avg(i,k,j) =0.0
12274 a_titau1avg(i,k,j) =a_titau1avg(i,k,j) +tmpzx*a_Tmpv1
12275 a_tmpzx =a_tmpzx +titau1avg(i,k,j)*a_Tmpv1
12277 ! tmpzx =Tmpv302(i,k) ! Remarked by Ning Pan, 2010-08-10
12281 a_Tmpv3 =0.25*a_Tmpv4
12283 a_zx(i+1,k,j-1) =a_zx(i+1,k,j-1) +a_Tmpv3
12285 a_zx(i,k,j-1) =a_zx(i,k,j-1) +a_Tmpv2
12286 a_zx(i,k,j) =a_zx(i,k,j) +a_Tmpv1
12287 a_zx(i+1,k,j) =a_zx(i+1,k,j) +a_Tmpv1
12289 ! titau2avg(i,k,j) =Tmpv301(i,k) ! Remarked by Ning Pan, 2010-08-10
12291 a_Tmpv6 =a_titau2avg(i,k,j)
12292 a_titau2avg(i,k,j) =0.0
12293 a_Tmpv5 =0.5*a_Tmpv6
12296 a_Tmpv3 =fnp(k)*a_Tmpv4
12297 a_titau2(i,k-1,j-1) =a_titau2(i,k-1,j-1) +a_Tmpv3
12298 a_titau2(i,k-1,j) =a_titau2(i,k-1,j) +a_Tmpv3
12299 a_Tmpv1 =fnm(k)*a_Tmpv2
12300 a_titau2(i,k,j-1) =a_titau2(i,k,j-1) +a_Tmpv1
12301 a_titau2(i,k,j) =a_titau2(i,k,j) +a_Tmpv1
12303 ! titau1avg(i,k,j) =Tmpv300(i,k) ! Remarked by Ning Pan, 2010-08-10
12305 a_Tmpv6 =a_titau1avg(i,k,j)
12306 a_titau1avg(i,k,j) =0.0
12307 a_Tmpv5 =0.5*a_Tmpv6
12310 a_Tmpv3 =fnp(k)*a_Tmpv4
12311 a_titau1(i+1,k-1,j) =a_titau1(i+1,k-1,j) +a_Tmpv3
12312 a_titau1(i,k-1,j) =a_titau1(i,k-1,j) +a_Tmpv3
12313 a_Tmpv1 =fnm(k)*a_Tmpv2
12314 a_titau1(i+1,k,j) =a_titau1(i+1,k,j) +a_Tmpv1
12315 a_titau1(i,k,j) =a_titau1(i,k,j) +a_Tmpv1
12322 ! Remarked by Ning Pan, 2010-08-10
12323 ! DO IX4=1,n_nba_mij
12327 ! nba_mij(IX1,IX2,IX3,IX4) =Keep_Lpb12_nba_mij(IX1,IX2,IX3,IX4)
12332 ! DO IX4=1,n_nba_mij
12336 ! nba_mij(IX1,IX2,IX3,IX4) =Keep_Lpb12_nba_mij(IX1,IX2,IX3,IX4)
12342 ! Remarked by Ning Pan, 2010-08-10
12347 ! Tmpv_1 =nba_mij(ims,kms,jms,P_m12)
12348 ! CALL cal_titau_12_21(config_flags,titau1,mu,xkmh,defor12,nba_mij(ims,kms,jms, &
12349 ! P_m12),is_ext,ie_ext,js_ext,je_ext,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme, &
12350 ! its,ite,jts,jte,kts,kte)
12352 ! Remarked by Ning Pan, 2010-08-10
12357 ! Tmpv_2 =nba_mij(ims,kms,jms,P_m22)
12358 ! CALL cal_titau_11_22_33(config_flags,titau2,mu,tke,xkmh,defor22,nba_mij(ims,kms, &
12359 ! jms,P_m22),is_ext,ie_ext,js_ext,je_ext,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms, &
12360 ! kme,its,ite,jts,jte,kts,kte)
12362 ! nba_mij(ims,kms,jms,P_m22) =Tmpv_2
12364 ! Added by Ning Pan, 2010-08-10
12370 CALL a_cal_titau_11_22_33(config_flags,titau2,a_titau2,mu,a_mu,tke,a_tke, &
12371 xkmh,a_xkmh,defor22,a_defor22,nba_mij(ims,kms,jms,P_m22),a_nba_mij(ims,kms,jms, &
12372 P_m22),rho,a_rho,is_ext,ie_ext,js_ext,je_ext,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme, &
12373 its,ite,jts,jte,kts,kte)
12375 ! nba_mij(ims,kms,jms,P_m12) =Tmpv_1 ! Remarked by Ning Pan, 2010-08-10
12377 ! Added by Ning Pan, 2010-08-10
12386 nba_mij(IX1,IX2,IX3,IX4) =Keep_Lpb12_nba_mij(IX1,IX2,IX3,IX4)
12392 CALL a_cal_titau_12_21(config_flags,titau1,a_titau1,mu,a_mu,xkmh,a_xkmh, &
12393 defor12,a_defor12,nba_mij(ims,kms,jms,P_m12),a_nba_mij(ims,kms,jms,P_m12) &
12395 ,is_ext,ie_ext,js_ext,je_ext,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite, &
12400 ! IF( config_flags%periodic_x ) THEN
12401 ! i_end =min(ite, ide-1)
12404 ! IF( config_flags%periodic_x ) THEN
12412 ! IF( config_flags%periodic_x ) THEN
12416 ! IF( config_flags%periodic_x ) THEN
12424 ! IF( config_flags%open_ye .or. config_flags%specified .or. config_flags%nested) THEN
12425 ! j_end =min(jde-1, jte)
12428 ! IF( config_flags%open_ye .or. config_flags%specified .or. &
12429 ! config_flags%nested) THEN
12437 ! IF( config_flags%open_ys .or. config_flags%specified .or. config_flags%nested) THEN
12438 ! j_start =max(jds+1, jts)
12441 ! IF( config_flags%open_ys .or. config_flags%specified .or. &
12442 ! config_flags%nested) THEN
12450 ! IF( config_flags%open_xe .or. config_flags%specified .or. config_flags%nested) THEN
12451 ! i_end =min(ide-2, ite)
12454 ! IF( config_flags%open_xe .or. config_flags%specified .or. &
12455 ! config_flags%nested) THEN
12463 ! IF( config_flags%open_xs .or. config_flags%specified .or. config_flags%nested) THEN
12464 ! i_start =max(ids+1, its)
12467 ! IF( config_flags%open_xs .or. config_flags%specified .or. &
12468 ! config_flags%nested) THEN
12473 ! ktf =min(kte, kde-1)
12475 ! i_end =min(ite, ide-1)
12479 END SUBROUTINE a_horizontal_diffusion_v_2
12481 SUBROUTINE a_horizontal_diffusion_w_2(tendency,a_tendency,mu,a_mu,config_flags, &
12482 defor13,a_defor13,defor23,a_defor23,div,a_div,nba_mij,a_nba_mij,n_nba_mij, &
12483 tke,a_tke,msftx,msfty,xkmh,a_xkmh,rdx,rdy,fnm,fnp,zx,a_zx,zy,a_zy,rdz, &
12484 a_rdz,rho,a_rho,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
12486 !PART I: DECLARATION OF VARIABLES
12490 INTEGER :: K0_ADJ,K1_ADJ,K2_ADJ,K3_ADJ
12491 TYPE(grid_config_rec_type) :: config_flags
12492 INTEGER :: ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte
12493 REAL,DIMENSION(kms:kme) :: fnm
12494 REAL,DIMENSION(kms:kme) :: fnp
12495 REAL,DIMENSION(ims:ime,jms:jme) :: msftx,msfty,mu,a_mu
12496 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: tendency,a_tendency
12497 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: defor13,a_defor13,defor23,a_defor23, &
12498 div,a_div,tke,a_tke,xkmh,a_xkmh,zx,a_zx,zy,a_zy,rdz,a_rdz
12499 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: rho, a_rho
12500 INTEGER :: n_nba_mij
12501 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_nba_mij) :: nba_mij,a_nba_mij
12503 INTEGER :: i,j,k,ktf
12504 INTEGER :: i_start,i_end,j_start,j_end
12505 INTEGER :: is_ext,ie_ext,js_ext,je_ext
12506 REAL,DIMENSION(its-1:ite+1,kts:kte,jts-1:jte+1) :: titau1avg,a_titau1avg,titau2avg, &
12507 a_titau2avg,titau1,a_titau1,titau2,a_titau2,xkxavg,a_xkxavg,rravg,a_rravg
12508 REAL :: mrdx,a_mrdx,mrdy,a_mrdy,rcoup,a_rcoup
12509 REAL :: tmpzx,a_tmpzx,tmpzy,a_tmpzy,tmpzeta_z,a_tmpzeta_z
12511 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_nba_mij) :: Keep_Lpb12_nba_mij
12512 INTEGER :: IX1,IX2,IX3,IX4
12514 REAL :: a_Tmpv1,Tmpv001,a_Tmpv2,Tmpv002,a_Tmpv3,Tmpv003,a_Tmpv4,Tmpv004, &
12515 a_Tmpv5,Tmpv005,a_Tmpv6,Tmpv006,a_Tmpv7,Tmpv007,a_Tmpv8,Tmpv008,a_Tmpv9, &
12516 Tmpv009,a_Tmpv10,Tmpv010,a_Tmpv11,Tmpv011
12518 REAL :: Tmpv_1,Tmpv_2
12519 REAL,DIMENSION(its:min(ite,ide-1),min0(kts,kts+1):min(kte,kde-1)) :: Tmpv300
12520 REAL,DIMENSION(its:min(ite,ide-1),min0(kts,kts+1):min(kte,kde-1)) :: Tmpv301
12521 REAL,DIMENSION(its:min(ite,ide-1),min0(kts,kts+1):min(kte,kde-1)) :: Tmpv302
12522 REAL,DIMENSION(its:min(ite,ide-1),min0(kts,kts+1):min(kte,kde-1)) :: Tmpv303
12523 REAL,DIMENSION(its:min(ite,ide-1),min0(kts,kts+1):min(kte,kde-1)) :: Tmpv304
12524 REAL,DIMENSION(its:min(ite,ide-1),kts:min(kte,kde-1)) :: Tmpv305
12526 !PART II: CALCULATIONS OF B. S. TRAJECTORY
12531 i_end = MIN(ite,ide-1)
12533 j_end = MIN(jte,jde-1)
12536 IF ( config_flags%open_xs .or. config_flags%specified .or. &
12537 config_flags%nested) i_start = MAX(ids+1,its)
12542 IF ( config_flags%open_xe .or. config_flags%specified .or. &
12543 config_flags%nested) i_end = MIN(ide-2,ite)
12548 IF ( config_flags%open_ys .or. config_flags%specified .or. &
12549 config_flags%nested) j_start = MAX(jds+1,jts)
12554 IF ( config_flags%open_ye .or. config_flags%specified .or. &
12555 config_flags%nested) j_end = MIN(jde-2,jte)
12560 IF ( config_flags%periodic_x ) i_start = its
12565 IF ( config_flags%periodic_x ) i_end = MIN(ite,ide-1)
12572 Keep_Lpb12_nba_mij(IX1,IX2,IX3,IX4) =nba_mij(IX1,IX2,IX3,IX4)
12577 ! Remarked by Ning Pan, 2010-08-10
12578 ! DO IX4=1,n_nba_mij
12582 ! Keep_Lpb12_nba_mij(IX1,IX2,IX3,IX4) =nba_mij(IX1,IX2,IX3,IX4)
12592 CALL cal_titau_13_31( config_flags, titau1, defor13, &
12593 nba_mij(ims,kms,jms,P_m13), &
12594 xkmh, fnm, fnp, rho, &
12595 is_ext, ie_ext, js_ext, je_ext, &
12596 ids, ide, jds, jde, kds, kde, &
12597 ims, ime, jms, jme, kms, kme, &
12598 its, ite, jts, jte, kts, kte )
12603 CALL cal_titau_23_32( config_flags, titau2, defor23, &
12604 nba_mij(ims,kms,jms,P_m23), &
12605 xkmh, fnm, fnp, rho, &
12606 is_ext, ie_ext, js_ext, je_ext, &
12607 ids, ide, jds, jde, kds, kde, &
12608 ims, ime, jms, jme, kms, kme, &
12609 its, ite, jts, jte, kts, kte )
12612 DO j = j_start, j_end
12615 DO i = i_start, i_end
12616 titau1avg(i,k,j)=0.25*(titau1(i+1,k+1,j)+titau1(i,k+1,j)+ &
12617 titau1(i+1,k ,j)+titau1(i,k ,j))
12618 titau2avg(i,k,j)=0.25*(titau2(i,k+1,j+1)+titau2(i,k+1,j)+ &
12619 titau2(i,k ,j+1)+titau2(i,k ,j))
12620 tmpzx =0.25*( zx(i,k ,j)+zx(i+1,k ,j)+ &
12621 zx(i,k+1,j)+zx(i+1,k+1,j) )
12622 tmpzy =0.25*( zy(i,k ,j)+zy(i,k ,j+1)+ &
12623 zy(i,k+1,j)+zy(i,k+1,j+1) )
12624 titau1avg(i,k,j)=titau1avg(i,k,j)*tmpzx
12625 titau2avg(i,k,j)=titau2avg(i,k,j)*tmpzy
12632 DO j = j_start, j_end
12634 DO i = i_start, i_end
12635 titau1avg(i,ktf+1,j)=0.
12636 titau2avg(i,ktf+1,j)=0.
12642 ! DO j = j_start, j_end
12645 ! DO i = i_start, i_end
12646 ! mrdx=msftx(i,j)*rdx
12647 ! mrdy=msfty(i,j)*rdy
12648 ! tendency(i,k,j)=tendency(i,k,j)- &
12649 ! (mrdx*(titau1(i+1,k,j)-titau1(i,k,j))+ &
12650 ! mrdy*(titau2(i,k,j+1)-titau2(i,k,j))- &
12651 ! msfty(i,j)*rdz(i,k,j)*(titau1avg(i,k,j)-titau1avg(i,k-1,j)+ &
12652 ! titau2avg(i,k,j)-titau2avg(i,k-1,j) &
12660 !PART III: INITIALIZATION OF LOCAL ADJOINT PERTURBATIONS
12662 Do K2_ADJ =jts-1, jte+1
12663 Do K1_ADJ =kts, kte
12664 Do K0_ADJ =its-1, ite+1
12665 a_titau1avg(K0_ADJ,K1_ADJ,K2_ADJ) =0.0
12670 Do K2_ADJ =jts-1, jte+1
12671 Do K1_ADJ =kts, kte
12672 Do K0_ADJ =its-1, ite+1
12673 a_titau2avg(K0_ADJ,K1_ADJ,K2_ADJ) =0.0
12678 Do K2_ADJ =jts-1, jte+1
12679 Do K1_ADJ =kts, kte
12680 Do K0_ADJ =its-1, ite+1
12681 a_titau1(K0_ADJ,K1_ADJ,K2_ADJ) =0.0
12686 Do K2_ADJ =jts-1, jte+1
12687 Do K1_ADJ =kts, kte
12688 Do K0_ADJ =its-1, ite+1
12689 a_titau2(K0_ADJ,K1_ADJ,K2_ADJ) =0.0
12694 Do K2_ADJ =jts-1, jte+1
12695 Do K1_ADJ =kts, kte
12696 Do K0_ADJ =its-1, ite+1
12697 a_xkxavg(K0_ADJ,K1_ADJ,K2_ADJ) =0.0
12702 Do K2_ADJ =jts-1, jte+1
12703 Do K1_ADJ =kts, kte
12704 Do K0_ADJ =its-1, ite+1
12705 a_rravg(K0_ADJ,K1_ADJ,K2_ADJ) =0.0
12710 ! Remarked by Ning Pan, 2010-08-10
12716 ! a_tmpzeta_z =0.0 ! Remarked by Ning Pan, 2010-08-10
12718 !PART IV: REVERSE/BACKWARD ACCUMULATIONS
12721 DO j =j_end, j_start, -1
12724 DO i =i_start, i_end
12725 ! Revised by Ning Pan, 2010-08-10
12726 ! Tmpv300(i,k) =mrdx
12727 ! mrdx =msftx(i,j)*rdx
12728 mrdx =msftx(i,j)*rdx
12731 ! Revised by Ning Pan, 2010-08-10
12732 ! Tmpv301(i,k) =mrdy
12733 ! mrdy =msfty(i,j)*rdy
12734 mrdy =msfty(i,j)*rdy
12737 Tmpv001 =titau1(i+1,k,j) -titau1(i,k,j)
12738 Tmpv302(i,k) =Tmpv001
12739 Tmpv002 =mrdx*Tmpv302(i,k)
12740 Tmpv003 =titau2(i,k,j+1) -titau2(i,k,j)
12741 Tmpv303(i,k) =Tmpv003
12742 Tmpv004 =mrdy*Tmpv303(i,k)
12743 Tmpv005 =Tmpv002 +Tmpv004
12744 Tmpv006 =titau1avg(i,k,j) -titau1avg(i,k-1,j)
12745 Tmpv007 =Tmpv006 +titau2avg(i,k,j)
12746 Tmpv008 =Tmpv007 -titau2avg(i,k-1,j)
12747 Tmpv304(i,k) =Tmpv008
12748 ! Remarked by Ning Pan, 2010-08-10
12749 ! Tmpv009 =msfty(i,j)*rdz(i,k,j)*Tmpv304(i,k)
12750 ! Tmpv010 =Tmpv005 -Tmpv009
12751 ! Tmpv011 =tendency(i,k,j) -Tmpv010
12752 ! tendency(i,k,j) =Tmpv011
12757 DO k =ktf, kts+1, -1
12758 DO i =i_end, i_start, -1
12759 mrdx =Tmpv300(i,k) ! Added by Ning Pan, 2010-08-10
12760 mrdy =Tmpv301(i,k) ! Added by Ning Pan, 2010-08-10
12761 a_Tmpv11 =a_tendency(i,k,j)
12762 a_tendency(i,k,j) =0.0
12763 a_tendency(i,k,j) =a_tendency(i,k,j) +a_Tmpv11
12764 a_Tmpv10 =-a_Tmpv11
12767 a_rdz(i,k,j) =a_rdz(i,k,j) +msfty(i,j)*Tmpv304(i,k)*a_Tmpv9
12768 a_Tmpv8 =msfty(i,j)*rdz(i,k,j)*a_Tmpv9
12770 a_titau2avg(i,k-1,j) =a_titau2avg(i,k-1,j) -a_Tmpv8
12772 a_titau2avg(i,k,j) =a_titau2avg(i,k,j) +a_Tmpv7
12773 a_titau1avg(i,k,j) =a_titau1avg(i,k,j) +a_Tmpv6
12774 a_titau1avg(i,k-1,j) =a_titau1avg(i,k-1,j) -a_Tmpv6
12777 a_mrdy =a_mrdy +Tmpv303(i,k)*a_Tmpv4
12778 a_Tmpv3 =mrdy*a_Tmpv4
12779 a_titau2(i,k,j+1) =a_titau2(i,k,j+1) +a_Tmpv3
12780 a_titau2(i,k,j) =a_titau2(i,k,j) -a_Tmpv3
12781 a_mrdx =a_mrdx +Tmpv302(i,k)*a_Tmpv2
12782 a_Tmpv1 =mrdx*a_Tmpv2
12783 a_titau1(i+1,k,j) =a_titau1(i+1,k,j) +a_Tmpv1
12784 a_titau1(i,k,j) =a_titau1(i,k,j) -a_Tmpv1
12786 ! Remarked by Ning Pan, 2010-08-10
12787 ! mrdy =Tmpv301(i,k)
12791 ! mrdx =Tmpv300(i,k)
12800 DO j =j_end, j_start, -1
12802 ! DO i =i_start, i_end
12803 ! titau1avg(i,ktf+1,j) =0.
12805 ! titau2avg(i,ktf+1,j) =0.
12809 DO i =i_end, i_start, -1
12810 a_titau2avg(i,ktf+1,j) =0.0
12811 a_titau1avg(i,ktf+1,j) =0.0
12817 DO j =j_end, j_start, -1
12820 DO i =i_start, i_end
12821 Tmpv001 =titau1(i+1,k+1,j) +titau1(i,k+1,j)
12822 Tmpv002 =Tmpv001 +titau1(i+1,k,j)
12823 Tmpv003 =Tmpv002 +titau1(i,k,j)
12824 Tmpv004 =0.25*Tmpv003
12825 ! Revised by Ning Pan, 2010-08-10
12826 ! Tmpv300(i,k) =titau1avg(i,k,j)
12827 ! titau1avg(i,k,j) =Tmpv004
12828 titau1avg(i,k,j) =Tmpv004
12829 Tmpv300(i,k) =titau1avg(i,k,j)
12831 Tmpv001 =titau2(i,k+1,j+1) +titau2(i,k+1,j)
12832 Tmpv002 =Tmpv001 +titau2(i,k,j+1)
12833 Tmpv003 =Tmpv002 +titau2(i,k,j)
12834 Tmpv004 =0.25*Tmpv003
12835 ! Revised by Ning Pan, 2010-08-10
12836 ! Tmpv301(i,k) =titau2avg(i,k,j)
12837 ! titau2avg(i,k,j) =Tmpv004
12838 titau2avg(i,k,j) =Tmpv004
12839 Tmpv301(i,k) =titau2avg(i,k,j)
12841 Tmpv001 =zx(i,k,j) +zx(i+1,k,j)
12842 Tmpv002 =Tmpv001 +zx(i,k+1,j)
12843 Tmpv003 =Tmpv002 +zx(i+1,k+1,j)
12844 Tmpv004 =0.25*Tmpv003
12845 ! Revised by Ning Pan, 2010-08-10
12846 ! Tmpv302(i,k) =tmpzx
12849 Tmpv302(i,k) =tmpzx
12851 Tmpv001 =zy(i,k,j) +zy(i,k,j+1)
12852 Tmpv002 =Tmpv001 +zy(i,k+1,j)
12853 Tmpv003 =Tmpv002 +zy(i,k+1,j+1)
12854 Tmpv004 =0.25*Tmpv003
12855 ! Revised by Ning Pan, 2010-08-10
12856 ! Tmpv303(i,k) =tmpzy
12859 Tmpv303(i,k) =tmpzy
12861 ! Remarked by Ning Pan, 2010-08-10
12862 ! Tmpv001 =titau1avg(i,k,j)*tmpzx
12863 ! Tmpv304(i,k) =titau1avg(i,k,j)
12864 ! titau1avg(i,k,j) =Tmpv001
12866 ! Remarked by Ning Pan, 2010-08-10
12867 ! Tmpv001 =titau2avg(i,k,j)*tmpzy
12868 ! Tmpv305(i,k) =titau2avg(i,k,j)
12869 ! titau2avg(i,k,j) =Tmpv001
12875 DO i =i_end, i_start, -1
12877 tmpzy =Tmpv303(i,k) ! Added by Ning Pan, 2010-08-10
12878 ! Revised by Ning Pan, 2010-08-10
12879 ! titau2avg(i,k,j) =Tmpv305(i,k)
12880 titau2avg(i,k,j) =Tmpv301(i,k)
12882 a_Tmpv1 =a_titau2avg(i,k,j)
12883 a_titau2avg(i,k,j) =0.0
12884 a_titau2avg(i,k,j) =a_titau2avg(i,k,j) +tmpzy*a_Tmpv1
12885 a_tmpzy =a_tmpzy +titau2avg(i,k,j)*a_Tmpv1
12887 tmpzx =Tmpv302(i,k) ! Added by Ning Pan, 2010-08-10
12888 ! Revised by Ning Pan, 2010-08-10
12889 ! titau1avg(i,k,j) =Tmpv304(i,k)
12890 titau1avg(i,k,j) =Tmpv300(i,k)
12892 a_Tmpv1 =a_titau1avg(i,k,j)
12893 a_titau1avg(i,k,j) =0.0
12894 a_titau1avg(i,k,j) =a_titau1avg(i,k,j) +tmpzx*a_Tmpv1
12895 a_tmpzx =a_tmpzx +titau1avg(i,k,j)*a_Tmpv1
12897 ! tmpzy =Tmpv303(i,k) ! Remarked by Ning Pan, 2010-08-10
12901 a_Tmpv3 =0.25*a_Tmpv4
12903 a_zy(i,k+1,j+1) =a_zy(i,k+1,j+1) +a_Tmpv3
12905 a_zy(i,k+1,j) =a_zy(i,k+1,j) +a_Tmpv2
12906 a_zy(i,k,j) =a_zy(i,k,j) +a_Tmpv1
12907 a_zy(i,k,j+1) =a_zy(i,k,j+1) +a_Tmpv1
12909 ! tmpzx =Tmpv302(i,k) ! Remarked by Ning Pan, 2010-08-10
12913 a_Tmpv3 =0.25*a_Tmpv4
12915 a_zx(i+1,k+1,j) =a_zx(i+1,k+1,j) +a_Tmpv3
12917 a_zx(i,k+1,j) =a_zx(i,k+1,j) +a_Tmpv2
12918 a_zx(i,k,j) =a_zx(i,k,j) +a_Tmpv1
12919 a_zx(i+1,k,j) =a_zx(i+1,k,j) +a_Tmpv1
12921 ! titau2avg(i,k,j) =Tmpv301(i,k) ! Remarked by Ning Pan, 2010-08-10
12923 a_Tmpv4 =a_titau2avg(i,k,j)
12924 a_titau2avg(i,k,j) =0.0
12925 a_Tmpv3 =0.25*a_Tmpv4
12927 a_titau2(i,k,j) =a_titau2(i,k,j) +a_Tmpv3
12929 a_titau2(i,k,j+1) =a_titau2(i,k,j+1) +a_Tmpv2
12930 a_titau2(i,k+1,j+1) =a_titau2(i,k+1,j+1) +a_Tmpv1
12931 a_titau2(i,k+1,j) =a_titau2(i,k+1,j) +a_Tmpv1
12933 ! titau1avg(i,k,j) =Tmpv300(i,k) ! Remarked by Ning Pan, 2010-08-10
12935 a_Tmpv4 =a_titau1avg(i,k,j)
12936 a_titau1avg(i,k,j) =0.0
12937 a_Tmpv3 =0.25*a_Tmpv4
12939 a_titau1(i,k,j) =a_titau1(i,k,j) +a_Tmpv3
12941 a_titau1(i+1,k,j) =a_titau1(i+1,k,j) +a_Tmpv2
12942 a_titau1(i+1,k+1,j) =a_titau1(i+1,k+1,j) +a_Tmpv1
12943 a_titau1(i,k+1,j) =a_titau1(i,k+1,j) +a_Tmpv1
12950 ! Remarked by Ning Pan, 2010-08-10
12951 ! DO IX4=1,n_nba_mij
12955 ! nba_mij(IX1,IX2,IX3,IX4) =Keep_Lpb12_nba_mij(IX1,IX2,IX3,IX4)
12960 ! DO IX4=1,n_nba_mij
12964 ! nba_mij(IX1,IX2,IX3,IX4) =Keep_Lpb12_nba_mij(IX1,IX2,IX3,IX4)
12970 ! Remarked by Ning Pan, 2010-08-10
12975 ! Tmpv_1 =nba_mij(ims,kms,jms,P_m13)
12976 ! CALL cal_titau_13_31(config_flags,titau1,defor13,nba_mij(ims,kms,jms,P_m13) &
12977 ! ,mu,xkmh,fnm,fnp,is_ext,ie_ext,js_ext,je_ext,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme, &
12978 ! kms,kme,its,ite,jts,jte,kts,kte)
12984 ! Tmpv_2 =nba_mij(ims,kms,jms,P_m23)
12985 ! CALL cal_titau_23_32(config_flags,titau2,defor23,nba_mij(ims,kms,jms,P_m23) &
12986 ! ,mu,xkmh,fnm,fnp,is_ext,ie_ext,js_ext,je_ext,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme, &
12987 ! kms,kme,its,ite,jts,jte,kts,kte)
12989 ! nba_mij(ims,kms,jms,P_m23) =Tmpv_2
12991 ! Added by Ning Pan, 2010-08-10
12997 CALL a_cal_titau_23_32(config_flags,titau2,a_titau2,defor23,a_defor23, &
12998 nba_mij(ims,kms,jms,P_m23),a_nba_mij(ims,kms,jms,P_m23),mu,a_mu,xkmh,a_xkmh, &
12999 fnm,fnp,rho,a_rho,is_ext,ie_ext,js_ext,je_ext,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme, &
13000 its,ite,jts,jte,kts,kte)
13002 ! nba_mij(ims,kms,jms,P_m13) =Tmpv_1 ! Remarked by Ning Pan, 2010-08-10
13004 ! Added by Ning Pan, 2010-08-10
13013 nba_mij(IX1,IX2,IX3,IX4) =Keep_Lpb12_nba_mij(IX1,IX2,IX3,IX4)
13019 CALL a_cal_titau_13_31(config_flags,titau1,a_titau1,defor13,a_defor13, &
13020 nba_mij(ims,kms,jms,P_m13),a_nba_mij(ims,kms,jms,P_m13),mu,a_mu,xkmh,a_xkmh, &
13021 fnm,fnp,rho,a_rho,is_ext,ie_ext,js_ext,je_ext,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme, &
13022 its,ite,jts,jte,kts,kte)
13026 ! IF( config_flags%periodic_x ) THEN
13027 ! i_end =min(ite, ide-1)
13030 ! IF( config_flags%periodic_x ) THEN
13038 ! IF( config_flags%periodic_x ) THEN
13042 ! IF( config_flags%periodic_x ) THEN
13050 ! IF( config_flags%open_ye .or. config_flags%specified .or. config_flags%nested) THEN
13051 ! j_end =min(jde-2, jte)
13054 ! IF( config_flags%open_ye .or. config_flags%specified .or. &
13055 ! config_flags%nested) THEN
13063 ! IF( config_flags%open_ys .or. config_flags%specified .or. config_flags%nested) THEN
13064 ! j_start =max(jds+1, jts)
13067 ! IF( config_flags%open_ys .or. config_flags%specified .or. &
13068 ! config_flags%nested) THEN
13076 ! IF( config_flags%open_xe .or. config_flags%specified .or. config_flags%nested) THEN
13077 ! i_end =min(ide-2, ite)
13080 ! IF( config_flags%open_xe .or. config_flags%specified .or. &
13081 ! config_flags%nested) THEN
13089 ! IF( config_flags%open_xs .or. config_flags%specified .or. config_flags%nested) THEN
13090 ! i_start =max(ids+1, its)
13093 ! IF( config_flags%open_xs .or. config_flags%specified .or. &
13094 ! config_flags%nested) THEN
13099 ! ktf =min(kte, kde-1)
13101 ! i_end =min(ite, ide-1)
13103 ! j_end =min(jte, jde-1)
13105 END SUBROUTINE a_horizontal_diffusion_w_2
13107 SUBROUTINE a_horizontal_diffusion_s(tendency,a_tendency,mu,a_mu,config_flags, &
13108 var,a_var,msftx,msfty,msfux,msfuy,msfvx,msfvy,xkhh,a_xkhh,rdx,rdy,fnm,fnp,cf1, &
13109 cf2,cf3,zx,a_zx,zy,a_zy,rdz,a_rdz,rdzw,a_rdzw,dnw,dn,rho,a_rho,doing_tke,ids,ide,jds, &
13110 jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
13112 !PART I: DECLARATION OF VARIABLES
13116 INTEGER :: K0_ADJ,K1_ADJ,K2_ADJ,K3_ADJ
13117 TYPE(grid_config_rec_type) :: config_flags
13118 INTEGER :: ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte
13119 LOGICAL :: doing_tke
13120 REAL :: cf1,cf2,cf3
13121 REAL,DIMENSION(kms:kme) :: fnm
13122 REAL,DIMENSION(kms:kme) :: fnp
13123 REAL,DIMENSION(kms:kme) :: dn
13124 REAL,DIMENSION(kms:kme) :: dnw
13125 REAL,DIMENSION(ims:ime,jms:jme) :: msfux
13126 REAL,DIMENSION(ims:ime,jms:jme) :: msfuy
13127 REAL,DIMENSION(ims:ime,jms:jme) :: msfvx
13128 REAL,DIMENSION(ims:ime,jms:jme) :: msfvy
13129 REAL,DIMENSION(ims:ime,jms:jme) :: msftx
13130 REAL,DIMENSION(ims:ime,jms:jme) :: msfty
13131 REAL,DIMENSION(ims:ime,jms:jme) :: mu,a_mu
13132 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: tendency,a_tendency
13133 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: xkhh,a_xkhh,rdz,a_rdz,rdzw,a_rdzw
13134 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: rho, a_rho
13135 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: var,a_var,zx,a_zx,zy,a_zy
13137 INTEGER :: i,j,k,ktf
13138 INTEGER :: i_start,i_end,j_start,j_end
13139 REAL,DIMENSION(its-1:ite+1,kts:kte,jts-1:jte+1) :: H1avg,a_H1avg,H2avg,a_H2avg, &
13140 H1,a_H1,H2,a_H2,xkxavg,a_xkxavg
13141 REAL,DIMENSION(its:ite,kts:kte,jts:jte) :: tmptendf,a_tmptendf
13142 REAL :: mrdx,a_mrdx,mrdy,a_mrdy,rcoup,a_rcoup
13143 REAL :: tmpzx,a_tmpzx,tmpzy,a_tmpzy,tmpzeta_z,a_tmpzeta_z,rdzu,a_rdzu,rdzv,a_rdzv
13144 INTEGER :: ktes1,ktes2
13146 REAL,DIMENSION(its-1:ite+1,kts:kte,jts-1:jte+1) :: Keep_Lpb22_H1avg
13147 REAL,DIMENSION(its-1:ite+1,kts:kte,jts-1:jte+1) :: Keep_Lpb22_H2avg
13148 REAL,DIMENSION(max(jds+1,jts):min(jde-2,jte)) :: Keep_Lpb22_tmpzx
13149 REAL,DIMENSION(max(jds+1,jts):min(jde-2,jte)) :: Keep_Lpb22_tmpzy
13150 REAL :: a_Tmpv1,Tmpv001,a_Tmpv2,Tmpv002,a_Tmpv3,Tmpv003,a_Tmpv4,Tmpv004, &
13151 a_Tmpv5,Tmpv005,a_Tmpv6,Tmpv006,a_Tmpv7,Tmpv007,a_Tmpv8,Tmpv008,a_Tmpv9, &
13152 Tmpv009,a_Tmpv10,Tmpv010,a_Tmpv11,Tmpv011,a_Tmpv12,Tmpv012,a_Tmpv13,Tmpv013, &
13153 a_Tmpv14,Tmpv014,a_Tmpv15,Tmpv015,a_Tmpv16,Tmpv016,a_Tmpv17,Tmpv017, &
13154 a_Tmpv18,Tmpv018,a_Tmpv19,Tmpv019,a_Tmpv20,Tmpv020
13155 REAL,DIMENSION(its:max0(min(ite,ide-1)+1,min(ite,ide-1)),min0(kts,kts+1) &
13156 :min(kte,kde-1)) :: Tmpv300
13157 REAL,DIMENSION(its:max0(min(ite,ide-1)+1,min(ite,ide-1)),min0(kts,kts+1) &
13158 :min(kte,kde-1)) :: Tmpv301
13159 REAL,DIMENSION(its:max0(min(ite,ide-1)+1,min(ite,ide-1)),min0(kts,kts+1) &
13160 :min(kte,kde-1)) :: Tmpv302
13161 REAL,DIMENSION(its:max0(min(ite,ide-1)+1,min(ite,ide-1)),min0(kts,kts+1) &
13162 :min(kte,kde-1)) :: Tmpv303
13163 REAL,DIMENSION(its:max0(min(ite,ide-1)+1,min(ite,ide-1)),min0(kts,kts+1) &
13164 :min(kte,kde-1)) :: Tmpv304
13165 REAL,DIMENSION(its:min(ite,ide-1),min0(kts+1,kts):min(kte,kde-1)) :: Tmpv305
13166 REAL,DIMENSION(its:min(ite,ide-1),kts:min(kte,kde-1)) :: Tmpv306
13167 REAL,DIMENSION(its:min(ite,ide-1),kts:min(kte,kde-1)) :: Tmpv307
13168 REAL,DIMENSION(its:min(ite,ide-1),kts:min(kte,kde-1)) :: Tmpv308
13169 REAL,DIMENSION(its:min(ite,ide-1),kts:min(kte,kde-1)) :: Tmpv309
13170 ! Added by Ning Pan, 2010-08-10
13171 REAL,DIMENSION(its:max0(min(ite,ide-1)+1,min(ite,ide-1)),min0(kts,kts+1) &
13172 :min(kte,kde-1)) :: Tmpv3010, Tmpv3011
13173 !PART II: CALCULATIONS OF B. S. TRAJECTORY
13180 i_end = MIN(ite,ide-1)
13182 j_end = MIN(jte,jde-1)
13185 IF ( config_flags%open_xs .or. config_flags%specified .or. &
13186 config_flags%nested) i_start = MAX(ids+1,its)
13191 IF ( config_flags%open_xe .or. config_flags%specified .or. &
13192 config_flags%nested) i_end = MIN(ide-2,ite)
13197 IF ( config_flags%open_ys .or. config_flags%specified .or. &
13198 config_flags%nested) j_start = MAX(jds+1,jts)
13203 IF ( config_flags%open_ye .or. config_flags%specified .or. &
13204 config_flags%nested) j_end = MIN(jde-2,jte)
13209 IF ( config_flags%periodic_x ) i_start = its
13214 IF ( config_flags%periodic_x ) i_end = MIN(ite,ide-1)
13219 ! Remarked by Ning Pan, 2010-08-10
13220 ! IF ( doing_tke ) THEN
13222 ! DO j = j_start, j_end
13224 ! DO i = i_start, i_end
13225 ! tmptendf(i,k,j)=tendency(i,k,j)
13233 DO j = j_start, j_end
13236 DO i = i_start, i_end + 1
13237 xkxavg(i,k,j)=0.5*(xkhh(i-1,k,j)+xkhh(i,k,j))
13244 DO j = j_start, j_end
13247 DO i = i_start, i_end + 1
13248 H1avg(i,k,j)=0.5*(fnm(k)*(var(i-1,k ,j)+var(i,k ,j))+ &
13249 fnp(k)*(var(i-1,k-1,j)+var(i,k-1,j)))
13256 DO j = j_start, j_end
13258 DO i = i_start, i_end + 1
13259 H1avg(i,kts ,j)=0.5*(cf1*var(i ,1,j)+cf2*var(i ,2,j)+ &
13260 cf3*var(i ,3,j)+cf1*var(i-1,1,j)+ &
13261 cf2*var(i-1,2,j)+cf3*var(i-1,3,j))
13262 H1avg(i,ktf+1,j)=0.5*(var(i,ktes1,j)+(var(i,ktes1,j)- &
13263 var(i,ktes2,j))*0.5*dnw(ktes1)/dn(ktes1)+ &
13264 var(i-1,ktes1,j)+(var(i-1,ktes1,j)- &
13265 var(i-1,ktes2,j))*0.5*dnw(ktes1)/dn(ktes1))
13271 DO j = j_start, j_end
13274 DO i = i_start, i_end + 1
13275 tmpzx = 0.5*( zx(i,k,j)+ zx(i,k+1,j))
13276 rdzu = 2./(1./rdzw(i,k,j) + 1./rdzw(i-1,k,j))
13277 H1(i,k,j)=-msfuy(i,j)*xkxavg(i,k,j)*( &
13278 rdx*(var(i,k,j)-var(i-1,k,j)) - tmpzx* &
13279 (H1avg(i,k+1,j)-H1avg(i,k,j))*rdzu )
13286 DO j = j_start, j_end + 1
13289 DO i = i_start, i_end
13290 xkxavg(i,k,j)=0.5*(xkhh(i,k,j-1)+xkhh(i,k,j))
13297 DO j = j_start, j_end + 1
13300 DO i = i_start, i_end
13301 H2avg(i,k,j)=0.5*(fnm(k)*(var(i,k ,j-1)+var(i,k ,j))+ &
13302 fnp(k)*(var(i,k-1,j-1)+var(i,k-1,j)))
13309 DO j = j_start, j_end + 1
13311 DO i = i_start, i_end
13312 H2avg(i,kts ,j)=0.5*(cf1*var(i,1,j )+cf2*var(i ,2,j)+ &
13313 cf3*var(i,3,j )+cf1*var(i,1,j-1)+ &
13314 cf2*var(i,2,j-1)+cf3*var(i,3,j-1))
13315 H2avg(i,ktf+1,j)=0.5*(var(i,ktes1,j)+(var(i,ktes1,j)- &
13316 var(i,ktes2,j))*0.5*dnw(ktes1)/dn(ktes1)+ &
13317 var(i,ktes1,j-1)+(var(i,ktes1,j-1)- &
13318 var(i,ktes2,j-1))*0.5*dnw(ktes1)/dn(ktes1))
13324 DO j = j_start, j_end + 1
13327 DO i = i_start, i_end
13328 tmpzy = 0.5*( zy(i,k,j)+ zy(i,k+1,j))
13329 rdzv = 2./(1./rdzw(i,k,j) + 1./rdzw(i,k,j-1))
13330 H2(i,k,j)=-msfvy(i,j)*xkxavg(i,k,j)*( &
13331 rdy*(var(i,k,j)-var(i,k,j-1)) - tmpzy* &
13332 (H2avg(i ,k+1,j)-H2avg(i,k,j))*rdzv)
13338 ! Added by Ning Pan, 2010-08-10
13339 DO j = j_start, j_end
13341 DO i = i_start, i_end+1
13342 Keep_Lpb22_H1avg(i,k,j) =H1avg(i,k,j)
13346 DO j = j_start, j_end+1
13348 DO i = i_start, i_end
13349 Keep_Lpb22_H2avg(i,k,j) =H2avg(i,k,j)
13355 DO j = j_start, j_end
13357 ! Remarked by Ning Pan, 2010-08-10
13358 ! DO k=kts+1, min(kte,kde-1)
13359 ! DO i=its, min(ite,ide-1)
13360 ! Keep_Lpb22_H1avg(i,k,j) =H1avg(i,k,j)
13363 ! DO k=kts+1, min(kte,kde-1)
13364 ! DO i=its, min(ite,ide-1)
13365 ! Keep_Lpb22_H2avg(i,k,j) =H2avg(i,k,j)
13368 ! Keep_Lpb22_tmpzx(j) =tmpzx
13369 ! Keep_Lpb22_tmpzy(j) =tmpzy
13372 DO i = i_start, i_end
13373 H1avg(i,k,j)=0.5*(fnm(k)*(H1(i+1,k ,j)+H1(i,k ,j))+ &
13374 fnp(k)*(H1(i+1,k-1,j)+H1(i,k-1,j)))
13375 H2avg(i,k,j)=0.5*(fnm(k)*(H2(i,k ,j+1)+H2(i,k ,j))+ &
13376 fnp(k)*(H2(i,k-1,j+1)+H2(i,k-1,j)))
13377 tmpzx = 0.5*( zx(i,k,j)+ zx(i+1,k,j ))
13378 tmpzy = 0.5*( zy(i,k,j)+ zy(i ,k,j+1))
13379 H1avg(i,k,j)=H1avg(i,k,j)*tmpzx
13380 H2avg(i,k,j)=H2avg(i,k,j)*tmpzy
13387 DO j = j_start, j_end
13389 DO i = i_start, i_end
13391 H1avg(i,ktf+1,j)=0.
13393 H2avg(i,ktf+1,j)=0.
13399 ! DO j = j_start, j_end
13402 ! DO i = i_start, i_end
13403 ! mrdx=msftx(i,j)*rdx
13404 ! mrdy=msfty(i,j)*rdy
13405 ! tendency(i,k,j)=tendency(i,k,j)- &
13406 ! (mrdx*0.5*((mu(i+1,j)+mu(i,j))*H1(i+1,k,j)- &
13407 ! (mu(i-1,j)+mu(i,j))*H1(i ,k,j))+ &
13408 ! mrdy*0.5*((mu(i,j+1)+mu(i,j))*H2(i,k,j+1)- &
13409 ! (mu(i,j-1)+mu(i,j))*H2(i,k,j ))- &
13410 ! msfty(i,j)*mu(i,j)*(H1avg(i,k+1,j)-H1avg(i,k,j)+ &
13411 ! H2avg(i,k+1,j)-H2avg(i,k,j) &
13422 ! IF ( doing_tke ) THEN
13424 ! DO j = j_start, j_end
13426 ! DO i = i_start, i_end
13427 ! tendency(i,k,j)=tmptendf(i,k,j)+2.* &
13428 ! (tendency(i,k,j)-tmptendf(i,k,j))
13435 !PART III: INITIALIZATION OF LOCAL ADJOINT PERTURBATIONS
13437 Do K2_ADJ =jts-1, jte+1
13438 Do K1_ADJ =kts, kte
13439 Do K0_ADJ =its-1, ite+1
13440 a_H1avg(K0_ADJ,K1_ADJ,K2_ADJ) =0.0
13445 Do K2_ADJ =jts-1, jte+1
13446 Do K1_ADJ =kts, kte
13447 Do K0_ADJ =its-1, ite+1
13448 a_H2avg(K0_ADJ,K1_ADJ,K2_ADJ) =0.0
13453 Do K2_ADJ =jts-1, jte+1
13454 Do K1_ADJ =kts, kte
13455 Do K0_ADJ =its-1, ite+1
13456 a_H1(K0_ADJ,K1_ADJ,K2_ADJ) =0.0
13461 Do K2_ADJ =jts-1, jte+1
13462 Do K1_ADJ =kts, kte
13463 Do K0_ADJ =its-1, ite+1
13464 a_H2(K0_ADJ,K1_ADJ,K2_ADJ) =0.0
13469 Do K2_ADJ =jts-1, jte+1
13470 Do K1_ADJ =kts, kte
13471 Do K0_ADJ =its-1, ite+1
13472 a_xkxavg(K0_ADJ,K1_ADJ,K2_ADJ) =0.0
13477 Do K2_ADJ =jts, jte
13478 Do K1_ADJ =kts, kte
13479 Do K0_ADJ =its, ite
13480 a_tmptendf(K0_ADJ,K1_ADJ,K2_ADJ) =0.0
13485 ! Remarked by Ning Pan, 2010-08-10
13491 ! a_tmpzeta_z =0.0 ! Remarked by Ning Pan, 2010-08-10
13495 !PART IV: REVERSE/BACKWARD ACCUMULATIONS
13499 ! IF( doing_tke ) THEN
13500 ! DO j =j_start, j_end
13502 ! DO i =i_start, i_end
13503 ! Tmpv001 =tendency(i,k,j) -tmptendf(i,k,j)
13504 ! Tmpv002 =2.*Tmpv001
13505 ! Tmpv003 =tmptendf(i,k,j) +Tmpv002
13506 ! tendency(i,k,j) =Tmpv003
13513 IF( doing_tke ) THEN
13515 DO j =j_end, j_start, -1
13517 DO i =i_end, i_start, -1
13518 a_Tmpv3 =a_tendency(i,k,j)
13519 a_tendency(i,k,j) =0.0
13520 a_tmptendf(i,k,j) =a_tmptendf(i,k,j) +a_Tmpv3
13522 a_Tmpv1 =2.*a_Tmpv2
13523 a_tendency(i,k,j) =a_tendency(i,k,j) +a_Tmpv1
13524 a_tmptendf(i,k,j) =a_tmptendf(i,k,j) -a_Tmpv1
13534 DO j =j_end, j_start, -1
13537 DO i =i_start, i_end
13538 ! Revised by Ning Pan, 2010-08-10
13539 ! Tmpv300(i,k) =mrdx
13540 ! mrdx =msftx(i,j)*rdx
13541 mrdx =msftx(i,j)*rdx
13544 ! Revised by Ning Pan, 2010-08-10
13545 ! Tmpv301(i,k) =mrdy
13546 ! mrdy =msfty(i,j)*rdy
13547 mrdy =msfty(i,j)*rdy
13550 Tmpv001 =mu(i+1,j) +mu(i,j)
13551 Tmpv302(i,k) =Tmpv001
13552 Tmpv002 =Tmpv302(i,k)*H1(i+1,k,j)
13553 Tmpv003 =mu(i-1,j) +mu(i,j)
13554 Tmpv303(i,k) =Tmpv003
13555 Tmpv004 =Tmpv303(i,k)*H1(i,k,j)
13556 Tmpv005 =Tmpv002 -Tmpv004
13557 Tmpv304(i,k) =Tmpv005
13558 Tmpv006 =mrdx*0.5*Tmpv304(i,k)
13559 Tmpv007 =mu(i,j+1) +mu(i,j)
13560 Tmpv305(i,k) =Tmpv007
13561 Tmpv008 =Tmpv305(i,k)*H2(i,k,j+1)
13562 Tmpv009 =mu(i,j-1) +mu(i,j)
13563 Tmpv306(i,k) =Tmpv009
13564 Tmpv010 =Tmpv306(i,k)*H2(i,k,j)
13565 Tmpv011 =Tmpv008 -Tmpv010
13566 Tmpv307(i,k) =Tmpv011
13567 Tmpv012 =mrdy*0.5*Tmpv307(i,k)
13568 Tmpv013 =Tmpv006 +Tmpv012
13569 Tmpv014 =H1avg(i,k+1,j) -H1avg(i,k,j)
13570 Tmpv015 =Tmpv014 +H2avg(i,k+1,j)
13571 Tmpv016 =Tmpv015 -H2avg(i,k,j)
13572 Tmpv308(i,k) =Tmpv016
13573 Tmpv017 =msfty(i,j)*mu(i,j)*Tmpv308(i,k)
13574 Tmpv309(i,k) =Tmpv017
13575 ! Remarked by Ning Pan, 2010-08-10
13576 ! Tmpv018 =Tmpv309(i,k)*rdzw(i,k,j)
13577 ! Tmpv019 =Tmpv013 -Tmpv018
13578 ! Tmpv020 =tendency(i,k,j) -Tmpv019
13579 ! tendency(i,k,j) =Tmpv020
13585 DO i =i_end, i_start, -1
13586 mrdx =Tmpv300(i,k) ! Added by Ning Pan, 2010-08-10
13587 mrdy =Tmpv301(i,k) ! Added by Ning Pan, 2010-08-10
13588 a_Tmpv20 =a_tendency(i,k,j)
13589 a_tendency(i,k,j) =0.0
13590 a_tendency(i,k,j) =a_tendency(i,k,j) +a_Tmpv20
13591 a_Tmpv19 =-a_Tmpv20
13593 a_Tmpv18 =-a_Tmpv19
13594 a_Tmpv17 =rdzw(i,k,j)*a_Tmpv18
13595 a_rdzw(i,k,j) =a_rdzw(i,k,j) +Tmpv309(i,k)*a_Tmpv18
13596 a_mu(i,j) =a_mu(i,j) +msfty(i,j)*Tmpv308(i,k)*a_Tmpv17
13597 a_Tmpv16 =msfty(i,j)*mu(i,j)*a_Tmpv17
13599 a_H2avg(i,k,j) =a_H2avg(i,k,j) -a_Tmpv16
13601 a_H2avg(i,k+1,j) =a_H2avg(i,k+1,j) +a_Tmpv15
13602 a_H1avg(i,k+1,j) =a_H1avg(i,k+1,j) +a_Tmpv14
13603 a_H1avg(i,k,j) =a_H1avg(i,k,j) -a_Tmpv14
13606 a_mrdy =a_mrdy +0.5*Tmpv307(i,k)*a_Tmpv12
13607 a_Tmpv11 =mrdy*0.5*a_Tmpv12
13609 a_Tmpv10 =-a_Tmpv11
13610 a_Tmpv9 =H2(i,k,j)*a_Tmpv10
13611 a_H2(i,k,j) =a_H2(i,k,j) +Tmpv306(i,k)*a_Tmpv10
13612 a_mu(i,j-1) =a_mu(i,j-1) +a_Tmpv9
13613 a_mu(i,j) =a_mu(i,j) +a_Tmpv9
13614 a_Tmpv7 =H2(i,k,j+1)*a_Tmpv8
13615 a_H2(i,k,j+1) =a_H2(i,k,j+1) +Tmpv305(i,k)*a_Tmpv8
13616 a_mu(i,j+1) =a_mu(i,j+1) +a_Tmpv7
13617 a_mu(i,j) =a_mu(i,j) +a_Tmpv7
13618 a_mrdx =a_mrdx +0.5*Tmpv304(i,k)*a_Tmpv6
13619 a_Tmpv5 =mrdx*0.5*a_Tmpv6
13622 a_Tmpv3 =H1(i,k,j)*a_Tmpv4
13623 a_H1(i,k,j) =a_H1(i,k,j) +Tmpv303(i,k)*a_Tmpv4
13624 a_mu(i-1,j) =a_mu(i-1,j) +a_Tmpv3
13625 a_mu(i,j) =a_mu(i,j) +a_Tmpv3
13626 a_Tmpv1 =H1(i+1,k,j)*a_Tmpv2
13627 a_H1(i+1,k,j) =a_H1(i+1,k,j) +Tmpv302(i,k)*a_Tmpv2
13628 a_mu(i+1,j) =a_mu(i+1,j) +a_Tmpv1
13629 a_mu(i,j) =a_mu(i,j) +a_Tmpv1
13631 ! Remarked by Ning Pan, 2010-08-10
13632 ! mrdy =Tmpv301(i,k)
13636 ! mrdx =Tmpv300(i,k)
13645 DO j =j_end, j_start, -1
13647 ! DO i =i_start, i_end
13648 ! H1avg(i,kts,j) =0.
13650 ! H1avg(i,ktf+1,j) =0.
13652 ! H2avg(i,kts,j) =0.
13654 ! H2avg(i,ktf+1,j) =0.
13658 DO i =i_end, i_start, -1
13659 a_H2avg(i,ktf+1,j) =0.0
13660 a_H2avg(i,kts,j) =0.0
13661 a_H1avg(i,ktf+1,j) =0.0
13662 a_H1avg(i,kts,j) =0.0
13668 DO j =j_end, j_start, -1
13670 ! Remarked by Ning Pan, 2010-08-10
13671 ! DO k=kts+1, min(kte,kde-1)
13672 ! DO i=its, min(ite,ide-1)
13673 ! H1avg(i,k,j) =Keep_Lpb22_H1avg(i,k,j)
13676 ! DO k=kts+1, min(kte,kde-1)
13677 ! DO i=its, min(ite,ide-1)
13678 ! H2avg(i,k,j) =Keep_Lpb22_H2avg(i,k,j)
13681 ! tmpzx =Keep_Lpb22_tmpzx(j)
13682 ! tmpzy =Keep_Lpb22_tmpzy(j)
13685 DO i =i_start, i_end
13686 Tmpv001 =H1(i+1,k,j) +H1(i,k,j)
13687 Tmpv002 =fnm(k)*Tmpv001
13688 Tmpv003 =H1(i+1,k-1,j) +H1(i,k-1,j)
13689 Tmpv004 =fnp(k)*Tmpv003
13690 Tmpv005 =Tmpv002 +Tmpv004
13691 Tmpv006 =0.5*Tmpv005
13692 ! Revised by Ning Pan, 2010-08-10
13693 ! Tmpv300(i,k) =H1avg(i,k,j)
13694 ! H1avg(i,k,j) =Tmpv006
13695 H1avg(i,k,j) =Tmpv006
13696 Tmpv300(i,k) =H1avg(i,k,j)
13698 Tmpv001 =H2(i,k,j+1) +H2(i,k,j)
13699 Tmpv002 =fnm(k)*Tmpv001
13700 Tmpv003 =H2(i,k-1,j+1) +H2(i,k-1,j)
13701 Tmpv004 =fnp(k)*Tmpv003
13702 Tmpv005 =Tmpv002 +Tmpv004
13703 Tmpv006 =0.5*Tmpv005
13704 ! Revised by Ning Pan, 2010-08-10
13705 ! Tmpv301(i,k) =H2avg(i,k,j)
13706 ! H2avg(i,k,j) =Tmpv006
13707 H2avg(i,k,j) =Tmpv006
13708 Tmpv301(i,k) =H2avg(i,k,j)
13710 Tmpv001 =zx(i,k,j) +zx(i+1,k,j)
13711 Tmpv002 =0.5*Tmpv001
13712 ! Revised by Ning Pan, 2010-08-10
13713 ! Tmpv302(i,k) =tmpzx
13716 Tmpv302(i,k) =tmpzx
13718 Tmpv001 =zy(i,k,j) +zy(i,k,j+1)
13719 Tmpv002 =0.5*Tmpv001
13720 ! Revised by Ning Pan, 2010-08-10
13721 ! Tmpv303(i,k) =tmpzy
13724 Tmpv303(i,k) =tmpzy
13726 ! Remarked by Ning Pan, 2010-08-10
13727 ! Tmpv001 =H1avg(i,k,j)*tmpzx
13728 ! Tmpv304(i,k) =H1avg(i,k,j)
13729 ! H1avg(i,k,j) =Tmpv001
13731 ! Remarked by Ning Pan, 2010-08-10
13732 ! Tmpv001 =H2avg(i,k,j)*tmpzy
13733 ! Tmpv305(i,k) =H2avg(i,k,j)
13734 ! H2avg(i,k,j) =Tmpv001
13739 DO k =ktf, kts+1, -1
13740 DO i =i_end, i_start, -1
13742 tmpzy =Tmpv303(i,k) ! Added by Ning Pan, 2010-08-10
13743 ! Revised by Ning Pan, 2010-08-10
13744 ! H2avg(i,k,j) =Tmpv305(i,k)
13745 H2avg(i,k,j) =Tmpv301(i,k)
13747 a_Tmpv1 =a_H2avg(i,k,j)
13748 a_H2avg(i,k,j) =0.0
13749 a_H2avg(i,k,j) =a_H2avg(i,k,j) +tmpzy*a_Tmpv1
13750 a_tmpzy =a_tmpzy +H2avg(i,k,j)*a_Tmpv1
13752 tmpzx =Tmpv302(i,k) ! Added by Ning Pan, 2010-08-10
13753 ! Revised by Ning Pan, 2010-08-10
13754 ! H1avg(i,k,j) =Tmpv304(i,k)
13755 H1avg(i,k,j) =Tmpv300(i,k)
13757 a_Tmpv1 =a_H1avg(i,k,j)
13758 a_H1avg(i,k,j) =0.0
13759 a_H1avg(i,k,j) =a_H1avg(i,k,j) +tmpzx*a_Tmpv1
13760 a_tmpzx =a_tmpzx +H1avg(i,k,j)*a_Tmpv1
13762 ! tmpzy =Tmpv303(i,k) ! Remarked by Ning Pan, 2010-08-10
13766 a_Tmpv1 =0.5*a_Tmpv2
13767 a_zy(i,k,j) =a_zy(i,k,j) +a_Tmpv1
13768 a_zy(i,k,j+1) =a_zy(i,k,j+1) +a_Tmpv1
13770 ! tmpzx =Tmpv302(i,k) ! Remarked by Ning Pan, 2010-08-10
13774 a_Tmpv1 =0.5*a_Tmpv2
13775 a_zx(i,k,j) =a_zx(i,k,j) +a_Tmpv1
13776 a_zx(i+1,k,j) =a_zx(i+1,k,j) +a_Tmpv1
13778 ! H2avg(i,k,j) =Tmpv301(i,k) ! Remarked by Ning Pan, 2010-08-10
13780 a_Tmpv6 =a_H2avg(i,k,j)
13781 a_H2avg(i,k,j) =0.0
13782 a_Tmpv5 =0.5*a_Tmpv6
13785 a_Tmpv3 =fnp(k)*a_Tmpv4
13786 a_H2(i,k-1,j+1) =a_H2(i,k-1,j+1) +a_Tmpv3
13787 a_H2(i,k-1,j) =a_H2(i,k-1,j) +a_Tmpv3
13788 a_Tmpv1 =fnm(k)*a_Tmpv2
13789 a_H2(i,k,j+1) =a_H2(i,k,j+1) +a_Tmpv1
13790 a_H2(i,k,j) =a_H2(i,k,j) +a_Tmpv1
13792 ! H1avg(i,k,j) =Tmpv300(i,k) ! Remarked by Ning Pan, 2010-08-10
13794 a_Tmpv6 =a_H1avg(i,k,j)
13795 a_H1avg(i,k,j) =0.0
13796 a_Tmpv5 =0.5*a_Tmpv6
13799 a_Tmpv3 =fnp(k)*a_Tmpv4
13800 a_H1(i+1,k-1,j) =a_H1(i+1,k-1,j) +a_Tmpv3
13801 a_H1(i,k-1,j) =a_H1(i,k-1,j) +a_Tmpv3
13802 a_Tmpv1 =fnm(k)*a_Tmpv2
13803 a_H1(i+1,k,j) =a_H1(i+1,k,j) +a_Tmpv1
13804 a_H1(i,k,j) =a_H1(i,k,j) +a_Tmpv1
13810 ! Added by Ning Pan, 2010-08-10
13811 DO j = j_start, j_end+1
13813 DO i = i_start, i_end
13814 H2avg(i,k,j) = Keep_Lpb22_H2avg(i,k,j)
13820 DO j =j_end+1, j_start, -1
13823 DO i =i_start, i_end
13824 Tmpv001 =zy(i,k,j) +zy(i,k+1,j)
13825 Tmpv002 =0.5*Tmpv001
13826 ! Revised by Ning Pan, 2010-08-10
13827 ! Tmpv300(i,k) =tmpzy
13830 Tmpv300(i,k) =tmpzy
13832 Tmpv001 =1./rdzw(i,k,j) +1./rdzw(i,k,j-1)
13833 Tmpv3010(i,k) =Tmpv001 ! Added by Ning Pan, 2010-08-10
13834 Tmpv002 =2./Tmpv001
13835 ! Revised by Ning Pan, 2010-08-10
13836 ! Tmpv301(i,k) =rdzv
13841 Tmpv001 =var(i,k,j) -var(i,k,j-1)
13842 Tmpv002 =rdy*Tmpv001
13843 Tmpv003 =H2avg(i,k+1,j) -H2avg(i,k,j)
13844 Tmpv302(i,k) =Tmpv003
13845 Tmpv004 =tmpzy*Tmpv302(i,k)
13846 Tmpv303(i,k) =Tmpv004
13847 Tmpv005 =Tmpv303(i,k)*rdzv
13848 Tmpv006 =Tmpv002 -Tmpv005
13849 Tmpv304(i,k) =Tmpv006
13850 ! Remarked by Ning Pan, 2010-08-10
13851 ! Tmpv007 =-msfvy(i,j)*xkxavg(i,k,j)*Tmpv304(i,k)
13852 ! H2(i,k,j) =Tmpv007
13858 DO i =i_end, i_start, -1
13859 ! Added by Ning Pan, 2010-08-10
13860 xkxavg(i,k,j)=0.5*(xkhh(i,k,j-1)+xkhh(i,k,j))
13861 tmpzy =Tmpv300(i,k)
13864 a_Tmpv7 =a_H2(i,k,j)
13866 a_xkxavg(i,k,j) =a_xkxavg(i,k,j) -msfvy(i,j)*Tmpv304(i,k)*a_Tmpv7
13867 a_Tmpv6 =-msfvy(i,j)*xkxavg(i,k,j)*a_Tmpv7
13870 a_Tmpv4 =rdzv*a_Tmpv5
13871 a_rdzv =a_rdzv +Tmpv303(i,k)*a_Tmpv5
13872 a_tmpzy =a_tmpzy +Tmpv302(i,k)*a_Tmpv4
13873 a_Tmpv3 =tmpzy*a_Tmpv4
13874 a_H2avg(i,k+1,j) =a_H2avg(i,k+1,j) +a_Tmpv3
13875 a_H2avg(i,k,j) =a_H2avg(i,k,j) -a_Tmpv3
13876 a_Tmpv1 =rdy*a_Tmpv2
13877 a_var(i,k,j) =a_var(i,k,j) +a_Tmpv1
13878 a_var(i,k,j-1) =a_var(i,k,j-1) -a_Tmpv1
13880 ! rdzv =Tmpv301(i,k) ! Remarked by Ning Pan, 2010-08-10
13884 ! Revised by Ning Pan, 2010-08-10
13885 ! a_Tmpv1 =-(2.)*a_Tmpv2/(Tmpv001*Tmpv001)
13886 a_Tmpv1 =-(2.)*a_Tmpv2/(Tmpv3010(i,k)*Tmpv3010(i,k))
13887 a_rdzw(i,k,j) =a_rdzw(i,k,j) -1./(rdzw(i,k,j)*rdzw(i,k,j))*a_Tmpv1
13888 a_rdzw(i,k,j-1) =a_rdzw(i,k,j-1) -1./(rdzw(i,k,j-1)*rdzw(i,k,j-1))*a_Tmpv1
13890 ! tmpzy =Tmpv300(i,k) ! Remarked by Ning Pan, 2010-08-10
13894 a_Tmpv1 =0.5*a_Tmpv2
13895 a_zy(i,k,j) =a_zy(i,k,j) +a_Tmpv1
13896 a_zy(i,k+1,j) =a_zy(i,k+1,j) +a_Tmpv1
13903 DO j =j_end+1, j_start, -1
13905 ! DO i =i_start, i_end
13906 ! Tmpv001 =cf1*var(i,1,j) +cf2*var(i,2,j)
13907 ! Tmpv002 =Tmpv001 +cf3*var(i,3,j)
13908 ! Tmpv003 =Tmpv002 +cf1*var(i,1,j-1)
13909 ! Tmpv004 =Tmpv003 +cf2*var(i,2,j-1)
13910 ! Tmpv005 =Tmpv004 +cf3*var(i,3,j-1)
13911 ! Tmpv006 =0.5*Tmpv005
13912 ! H2avg(i,kts,j) =Tmpv006
13914 ! Tmpv001 =var(i,ktes1,j) -var(i,ktes2,j)
13915 ! Tmpv002 =Tmpv001*0.5
13916 ! Tmpv003 =Tmpv002*dnw(ktes1)
13917 ! Tmpv004 =Tmpv003/dn(ktes1)
13918 ! Tmpv005 =var(i,ktes1,j) +Tmpv004
13919 ! Tmpv006 =Tmpv005 +var(i,ktes1,j-1)
13920 ! Tmpv007 =var(i,ktes1,j-1) -var(i,ktes2,j-1)
13921 ! Tmpv008 =Tmpv007*0.5
13922 ! Tmpv009 =Tmpv008*dnw(ktes1)
13923 ! Tmpv010 =Tmpv009/dn(ktes1)
13924 ! Tmpv011 =Tmpv006 +Tmpv010
13925 ! Tmpv012 =0.5*Tmpv011
13926 ! H2avg(i,ktf+1,j) =Tmpv012
13930 DO i =i_end, i_start, -1
13931 a_Tmpv12 =a_H2avg(i,ktf+1,j)
13932 a_H2avg(i,ktf+1,j) =0.0
13933 a_Tmpv11 =0.5*a_Tmpv12
13936 a_Tmpv9 =a_Tmpv10/dn(ktes1)
13937 a_Tmpv8 =dnw(ktes1)*a_Tmpv9
13938 a_Tmpv7 =0.5*a_Tmpv8
13939 a_var(i,ktes1,j-1) =a_var(i,ktes1,j-1) +a_Tmpv7
13940 a_var(i,ktes2,j-1) =a_var(i,ktes2,j-1) -a_Tmpv7
13942 a_var(i,ktes1,j-1) =a_var(i,ktes1,j-1) +a_Tmpv6
13943 a_var(i,ktes1,j) =a_var(i,ktes1,j) +a_Tmpv5
13945 a_Tmpv3 =a_Tmpv4/dn(ktes1)
13946 a_Tmpv2 =dnw(ktes1)*a_Tmpv3
13947 a_Tmpv1 =0.5*a_Tmpv2
13948 a_var(i,ktes1,j) =a_var(i,ktes1,j) +a_Tmpv1
13949 a_var(i,ktes2,j) =a_var(i,ktes2,j) -a_Tmpv1
13950 a_Tmpv6 =a_H2avg(i,kts,j)
13951 a_H2avg(i,kts,j) =0.0
13952 a_Tmpv5 =0.5*a_Tmpv6
13954 a_var(i,3,j-1) =a_var(i,3,j-1) +cf3*a_Tmpv5
13956 a_var(i,2,j-1) =a_var(i,2,j-1) +cf2*a_Tmpv4
13958 a_var(i,1,j-1) =a_var(i,1,j-1) +cf1*a_Tmpv3
13960 a_var(i,3,j) =a_var(i,3,j) +cf3*a_Tmpv2
13961 a_var(i,1,j) =a_var(i,1,j) +cf1*a_Tmpv1
13962 a_var(i,2,j) =a_var(i,2,j) +cf2*a_Tmpv1
13968 DO j =j_end+1, j_start, -1
13971 ! DO i =i_start, i_end
13972 ! Tmpv001 =var(i,k,j-1) +var(i,k,j)
13973 ! Tmpv002 =fnm(k)*Tmpv001
13974 ! Tmpv003 =var(i,k-1,j-1) +var(i,k-1,j)
13975 ! Tmpv004 =fnp(k)*Tmpv003
13976 ! Tmpv005 =Tmpv002 +Tmpv004
13977 ! Tmpv006 =0.5*Tmpv005
13978 ! H2avg(i,k,j) =Tmpv006
13983 DO k =ktf, kts+1, -1
13984 DO i =i_end, i_start, -1
13985 a_Tmpv6 =a_H2avg(i,k,j)
13986 a_H2avg(i,k,j) =0.0
13987 a_Tmpv5 =0.5*a_Tmpv6
13990 a_Tmpv3 =fnp(k)*a_Tmpv4
13991 a_var(i,k-1,j-1) =a_var(i,k-1,j-1) +a_Tmpv3
13992 a_var(i,k-1,j) =a_var(i,k-1,j) +a_Tmpv3
13993 a_Tmpv1 =fnm(k)*a_Tmpv2
13994 a_var(i,k,j-1) =a_var(i,k,j-1) +a_Tmpv1
13995 a_var(i,k,j) =a_var(i,k,j) +a_Tmpv1
14002 DO j =j_end+1, j_start, -1
14005 ! DO i =i_start, i_end
14006 ! Tmpv001 =xkhh(i,k,j-1) +xkhh(i,k,j)
14007 ! Tmpv002 =0.5*Tmpv001
14008 ! xkxavg(i,k,j) =Tmpv002
14014 DO i =i_end, i_start, -1
14015 a_Tmpv2 =a_xkxavg(i,k,j)
14016 a_xkxavg(i,k,j) =0.0
14017 a_Tmpv1 =0.5*a_Tmpv2
14018 a_xkhh(i,k,j-1) =a_xkhh(i,k,j-1) +a_Tmpv1
14019 a_xkhh(i,k,j) =a_xkhh(i,k,j) +a_Tmpv1
14025 ! Added by Ning Pan, 2010-08-10
14026 DO j = j_start, j_end
14028 DO i = i_start, i_end+1
14029 H1avg(i,k,j) = Keep_Lpb22_H1avg(i,k,j)
14035 DO j =j_end, j_start, -1
14038 DO i =i_start, i_end+1
14039 Tmpv001 =zx(i,k,j) +zx(i,k+1,j)
14040 Tmpv002 =0.5*Tmpv001
14041 ! Revised by Ning Pan, 2010-08-10
14042 ! Tmpv300(i,k) =tmpzx
14045 Tmpv300(i,k) =tmpzx
14047 Tmpv001 =1./rdzw(i,k,j) +1./rdzw(i-1,k,j)
14048 Tmpv3010(i,k) =Tmpv001 ! Added by Ning Pan, 2010-08-10
14049 Tmpv002 =2./Tmpv001
14050 ! Revised by Ning Pan, 2010-08-10
14051 ! Tmpv301(i,k) =rdzu
14056 Tmpv001 =var(i,k,j) -var(i-1,k,j)
14057 Tmpv002 =rdx*Tmpv001
14058 Tmpv003 =H1avg(i,k+1,j) -H1avg(i,k,j)
14059 Tmpv302(i,k) =Tmpv003
14060 Tmpv004 =tmpzx*Tmpv302(i,k)
14061 Tmpv303(i,k) =Tmpv004
14062 Tmpv005 =Tmpv303(i,k)*rdzu
14063 Tmpv006 =Tmpv002 -Tmpv005
14064 Tmpv304(i,k) =Tmpv006
14065 ! Remarked by Ning Pan, 2010-08-10
14066 ! Tmpv007 =-msfuy(i,j)*xkxavg(i,k,j)*Tmpv304(i,k)
14067 ! H1(i,k,j) =Tmpv007
14073 DO i =i_end+1, i_start, -1
14074 ! Added by Ning Pan, 2010-08-10
14075 xkxavg(i,k,j)=0.5*(xkhh(i-1,k,j)+xkhh(i,k,j))
14076 tmpzx =Tmpv300(i,k)
14079 a_Tmpv7 =a_H1(i,k,j)
14081 a_xkxavg(i,k,j) =a_xkxavg(i,k,j) -msfuy(i,j)*Tmpv304(i,k)*a_Tmpv7
14082 a_Tmpv6 =-msfuy(i,j)*xkxavg(i,k,j)*a_Tmpv7
14085 a_Tmpv4 =rdzu*a_Tmpv5
14086 a_rdzu =a_rdzu +Tmpv303(i,k)*a_Tmpv5
14087 a_tmpzx =a_tmpzx +Tmpv302(i,k)*a_Tmpv4
14088 a_Tmpv3 =tmpzx*a_Tmpv4
14089 a_H1avg(i,k+1,j) =a_H1avg(i,k+1,j) +a_Tmpv3
14090 a_H1avg(i,k,j) =a_H1avg(i,k,j) -a_Tmpv3
14091 a_Tmpv1 =rdx*a_Tmpv2
14092 a_var(i,k,j) =a_var(i,k,j) +a_Tmpv1
14093 a_var(i-1,k,j) =a_var(i-1,k,j) -a_Tmpv1
14095 ! rdzu =Tmpv301(i,k) ! Remarked by Ning Pan, 2010-08-10
14099 ! Revised by Ning Pan, 2010-08-10
14100 ! a_Tmpv1 =-(2.)*a_Tmpv2/(Tmpv001*Tmpv001)
14101 a_Tmpv1 =-(2.)*a_Tmpv2/(Tmpv3010(i,k)*Tmpv3010(i,k))
14102 a_rdzw(i,k,j) =a_rdzw(i,k,j) -1./(rdzw(i,k,j)*rdzw(i,k,j))*a_Tmpv1
14103 a_rdzw(i-1,k,j) =a_rdzw(i-1,k,j) -1./(rdzw(i-1,k,j)*rdzw(i-1,k,j))*a_Tmpv1
14105 ! tmpzx =Tmpv300(i,k) ! Remarked by Ning Pan, 2010-08-10
14109 a_Tmpv1 =0.5*a_Tmpv2
14110 a_zx(i,k,j) =a_zx(i,k,j) +a_Tmpv1
14111 a_zx(i,k+1,j) =a_zx(i,k+1,j) +a_Tmpv1
14118 DO j =j_end, j_start, -1
14120 ! DO i =i_start, i_end+1
14121 ! Tmpv001 =cf1*var(i,1,j) +cf2*var(i,2,j)
14122 ! Tmpv002 =Tmpv001 +cf3*var(i,3,j)
14123 ! Tmpv003 =Tmpv002 +cf1*var(i-1,1,j)
14124 ! Tmpv004 =Tmpv003 +cf2*var(i-1,2,j)
14125 ! Tmpv005 =Tmpv004 +cf3*var(i-1,3,j)
14126 ! Tmpv006 =0.5*Tmpv005
14127 ! H1avg(i,kts,j) =Tmpv006
14129 ! Tmpv001 =var(i,ktes1,j) -var(i,ktes2,j)
14130 ! Tmpv002 =Tmpv001*0.5
14131 ! Tmpv003 =Tmpv002*dnw(ktes1)
14132 ! Tmpv004 =Tmpv003/dn(ktes1)
14133 ! Tmpv005 =var(i,ktes1,j) +Tmpv004
14134 ! Tmpv006 =Tmpv005 +var(i-1,ktes1,j)
14135 ! Tmpv007 =var(i-1,ktes1,j) -var(i-1,ktes2,j)
14136 ! Tmpv008 =Tmpv007*0.5
14137 ! Tmpv009 =Tmpv008*dnw(ktes1)
14138 ! Tmpv010 =Tmpv009/dn(ktes1)
14139 ! Tmpv011 =Tmpv006 +Tmpv010
14140 ! Tmpv012 =0.5*Tmpv011
14141 ! H1avg(i,ktf+1,j) =Tmpv012
14145 DO i =i_end+1, i_start, -1
14146 a_Tmpv12 =a_H1avg(i,ktf+1,j)
14147 a_H1avg(i,ktf+1,j) =0.0
14148 a_Tmpv11 =0.5*a_Tmpv12
14151 a_Tmpv9 =a_Tmpv10/dn(ktes1)
14152 a_Tmpv8 =dnw(ktes1)*a_Tmpv9
14153 a_Tmpv7 =0.5*a_Tmpv8
14154 a_var(i-1,ktes1,j) =a_var(i-1,ktes1,j) +a_Tmpv7
14155 a_var(i-1,ktes2,j) =a_var(i-1,ktes2,j) -a_Tmpv7
14157 a_var(i-1,ktes1,j) =a_var(i-1,ktes1,j) +a_Tmpv6
14158 a_var(i,ktes1,j) =a_var(i,ktes1,j) +a_Tmpv5
14160 a_Tmpv3 =a_Tmpv4/dn(ktes1)
14161 a_Tmpv2 =dnw(ktes1)*a_Tmpv3
14162 a_Tmpv1 =0.5*a_Tmpv2
14163 a_var(i,ktes1,j) =a_var(i,ktes1,j) +a_Tmpv1
14164 a_var(i,ktes2,j) =a_var(i,ktes2,j) -a_Tmpv1
14165 a_Tmpv6 =a_H1avg(i,kts,j)
14166 a_H1avg(i,kts,j) =0.0
14167 a_Tmpv5 =0.5*a_Tmpv6
14169 a_var(i-1,3,j) =a_var(i-1,3,j) +cf3*a_Tmpv5
14171 a_var(i-1,2,j) =a_var(i-1,2,j) +cf2*a_Tmpv4
14173 a_var(i-1,1,j) =a_var(i-1,1,j) +cf1*a_Tmpv3
14175 a_var(i,3,j) =a_var(i,3,j) +cf3*a_Tmpv2
14176 a_var(i,1,j) =a_var(i,1,j) +cf1*a_Tmpv1
14177 a_var(i,2,j) =a_var(i,2,j) +cf2*a_Tmpv1
14183 DO j =j_end, j_start, -1
14186 ! DO i =i_start, i_end+1
14187 ! Tmpv001 =var(i-1,k,j) +var(i,k,j)
14188 ! Tmpv002 =fnm(k)*Tmpv001
14189 ! Tmpv003 =var(i-1,k-1,j) +var(i,k-1,j)
14190 ! Tmpv004 =fnp(k)*Tmpv003
14191 ! Tmpv005 =Tmpv002 +Tmpv004
14192 ! Tmpv006 =0.5*Tmpv005
14193 ! H1avg(i,k,j) =Tmpv006
14198 DO k =ktf, kts+1, -1
14199 DO i =i_end+1, i_start, -1
14200 a_Tmpv6 =a_H1avg(i,k,j)
14201 a_H1avg(i,k,j) =0.0
14202 a_Tmpv5 =0.5*a_Tmpv6
14205 a_Tmpv3 =fnp(k)*a_Tmpv4
14206 a_var(i-1,k-1,j) =a_var(i-1,k-1,j) +a_Tmpv3
14207 a_var(i,k-1,j) =a_var(i,k-1,j) +a_Tmpv3
14208 a_Tmpv1 =fnm(k)*a_Tmpv2
14209 a_var(i-1,k,j) =a_var(i-1,k,j) +a_Tmpv1
14210 a_var(i,k,j) =a_var(i,k,j) +a_Tmpv1
14217 DO j =j_end, j_start, -1
14220 ! DO i =i_start, i_end+1
14221 ! Tmpv001 =xkhh(i-1,k,j) +xkhh(i,k,j)
14222 ! Tmpv002 =0.5*Tmpv001
14223 ! xkxavg(i,k,j) =Tmpv002
14229 DO i =i_end+1, i_start, -1
14230 a_Tmpv2 =a_xkxavg(i,k,j)
14231 a_xkxavg(i,k,j) =0.0
14232 a_Tmpv1 =0.5*a_Tmpv2
14233 a_xkhh(i-1,k,j) =a_xkhh(i-1,k,j) +a_Tmpv1
14234 a_xkhh(i,k,j) =a_xkhh(i,k,j) +a_Tmpv1
14242 ! IF( doing_tke ) THEN
14243 ! DO j =j_start, j_end
14245 ! DO i =i_start, i_end
14246 ! tmptendf(i,k,j) =tendency(i,k,j)
14253 IF( doing_tke ) THEN
14255 DO j =j_end, j_start, -1
14257 DO i =i_end, i_start, -1
14258 a_tendency(i,k,j) =a_tendency(i,k,j) +a_tmptendf(i,k,j)
14259 a_tmptendf(i,k,j) =0.0
14270 ! IF( config_flags%periodic_x ) THEN
14271 ! i_end =min(ite, ide-1)
14274 ! IF( config_flags%periodic_x ) THEN
14282 ! IF( config_flags%periodic_x ) THEN
14286 ! IF( config_flags%periodic_x ) THEN
14294 ! IF( config_flags%open_ye .or. config_flags%specified .or. config_flags%nested) THEN
14295 ! j_end =min(jde-2, jte)
14298 ! IF( config_flags%open_ye .or. config_flags%specified .or. &
14299 ! config_flags%nested) THEN
14307 ! IF( config_flags%open_ys .or. config_flags%specified .or. config_flags%nested) THEN
14308 ! j_start =max(jds+1, jts)
14311 ! IF( config_flags%open_ys .or. config_flags%specified .or. &
14312 ! config_flags%nested) THEN
14320 ! IF( config_flags%open_xe .or. config_flags%specified .or. config_flags%nested) THEN
14321 ! i_end =min(ide-2, ite)
14324 ! IF( config_flags%open_xe .or. config_flags%specified .or. &
14325 ! config_flags%nested) THEN
14333 ! IF( config_flags%open_xs .or. config_flags%specified .or. config_flags%nested) THEN
14334 ! i_start =max(ids+1, its)
14337 ! IF( config_flags%open_xs .or. config_flags%specified .or. &
14338 ! config_flags%nested) THEN
14343 ! ktf =min(kte, kde-1)
14347 ! i_end =min(ite, ide-1)
14349 ! j_end =min(jte, jde-1)
14351 END SUBROUTINE a_horizontal_diffusion_s
14353 SUBROUTINE a_vertical_diffusion_2(ru_tendf,a_ru_tendf,rv_tendf,a_rv_tendf, &
14354 rw_tendf,a_rw_tendf,rt_tendf,a_rt_tendf,tke_tendf,a_tke_tendf,moist_tendf, &
14355 ! Revised by Ning Pan, 2010-08-10
14356 ! a_moist_tendf,n_moist,chem_tendf,a_chem_tendf,n_chem,scalar_tendf,a_scalar_tend &
14357 ! f,n_scalar,tracer_tendf,a_tracer_tendf,n_tracer,u_2,a_u_2,v_2,a_v_2,thp, &
14358 a_moist_tendf,n_moist,chem_tendf,a_chem_tendf,n_chem,scalar_tendf,a_scalar_tend&
14359 &f,n_scalar,tracer_tendf,a_tracer_tendf,n_tracer,u_2,a_u_2,v_2,a_v_2,thp, &
14360 a_thp,u_base,v_base,t_base,qv_base,mu,a_mu,tke,a_tke,config_flags,defor13, &
14361 a_defor13,defor23,a_defor23,defor33,a_defor33,nba_mij,a_nba_mij,n_nba_mij, &
14362 div,a_div,moist,a_moist,chem,a_chem,scalar,a_scalar,tracer,a_tracer,xkmv, &
14363 a_xkmv,xkhv,a_xkhv,km_opt,fnm,fnp,dn,dnw,rdz,a_rdz,rdzw,a_rdzw,hfx,a_hfx, &
14364 qfx,a_qfx,ust,a_ust,rho,a_rho,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme, &
14365 its,ite,jts,jte,kts,kte)
14367 !PART I: DECLARATION OF VARIABLES
14371 INTEGER :: K0_ADJ,K1_ADJ,K2_ADJ,K3_ADJ
14372 TYPE(grid_config_rec_type) :: config_flags
14373 INTEGER :: ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte
14374 INTEGER :: n_moist,n_chem,n_scalar,n_tracer,km_opt
14375 REAL,DIMENSION(kms:kme) :: fnm
14376 REAL,DIMENSION(kms:kme) :: fnp
14377 REAL,DIMENSION(kms:kme) :: dnw
14378 REAL,DIMENSION(kms:kme) :: dn
14379 REAL,DIMENSION(ims:ime,jms:jme) :: mu,a_mu
14380 REAL,DIMENSION(kms:kme) :: qv_base
14381 REAL,DIMENSION(kms:kme) :: u_base
14382 REAL,DIMENSION(kms:kme) :: v_base
14383 REAL,DIMENSION(kms:kme) :: t_base
14384 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: ru_tendf,a_ru_tendf,rv_tendf, &
14385 a_rv_tendf,rw_tendf,a_rw_tendf,tke_tendf,a_tke_tendf,rt_tendf,a_rt_tendf
14386 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_moist) :: moist_tendf,a_moist_tendf
14387 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_chem) :: chem_tendf,a_chem_tendf
14388 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_scalar) :: scalar_tendf,a_scalar_tendf
14389 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_tracer) :: tracer_tendf,a_tracer_tendf
14390 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_moist) :: moist,a_moist
14391 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_chem) :: chem,a_chem
14392 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_scalar) :: scalar,a_scalar
14393 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_tracer) :: tracer,a_tracer
14394 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: defor13,a_defor13,defor23,a_defor23, &
14395 defor33,a_defor33,div,a_div,xkmv,a_xkmv,xkhv,a_xkhv,tke,a_tke,rdz,a_rdz, &
14396 u_2,a_u_2,v_2,a_v_2,rdzw,a_rdzw
14397 INTEGER :: n_nba_mij
14398 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_nba_mij) :: nba_mij,a_nba_mij
14399 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: rho,a_rho
14400 REAL,DIMENSION(ims:ime,jms:jme) :: hfx,a_hfx,qfx,a_qfx
14401 REAL,DIMENSION(ims:ime,jms:jme) :: ust,a_ust
14402 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: thp,a_thp
14403 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: var_mix,a_var_mix
14404 INTEGER :: im,i,j,k
14405 INTEGER :: i_start,i_end,j_start,j_end
14406 REAL :: V0_u,a_V0_u,V0_v,a_V0_v,tao_xz,a_tao_xz,tao_yz,a_tao_yz,ustar, &
14408 REAL :: xsfc,a_xsfc,psi1,a_psi1,vk2,a_vk2,zrough,a_zrough,lnz,a_lnz
14409 REAL :: heat_flux,a_heat_flux,moist_flux,a_moist_flux,heat_flux0,a_heat_flux0
14412 ! REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_nba_mij) :: Keep_Lpb12_nba_mij
14413 ! Remarked by Ning Pan, 2010-08-11
14414 ! REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: Keep_Lpb0_ru_tendf
14415 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_nba_mij) :: Keep_Lpb0_nba_mij
14416 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_nba_mij) :: Keep_Lpb1_nba_mij
14417 ! REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: Keep_Lpb0_rv_tendf
14418 ! REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: Keep_Lpb0_rw_tendf
14419 ! REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: Keep_Lpb4_rt_tendf
14420 ! REAL,DIMENSION(ims:ime,kms:kme,jms:jme,ims:ime,kms:kme,jms:jme) :: Keep_Lpb7_tke_tendf
14421 ! REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: Keep_Lpb9_var_mix
14422 ! REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_moist,ims:ime,kms:kme,jms:jme,n_moist) &
14423 ! :: Keep_Lpb9_moist_tendf
14424 ! REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_chem,ims:ime,kms:kme,jms:jme,n_chem) &
14425 ! :: Keep_Lpb11_chem_tendf
14426 ! REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_tracer,ims:ime,kms:kme,jms:jme,n_tracer) &
14427 ! :: Keep_Lpb13_tracer_tendf
14428 !! REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_scalar,ims:ime,kms:kme,jms:jme,n_scalar) &
14429 !! :: Keep_Lpb15_scalar_tendf
14430 INTEGER :: IX1,IX2,IX3,IX4
14432 REAL :: a_Tmpv1,Tmpv001,a_Tmpv2,Tmpv002,a_Tmpv3,Tmpv003,a_Tmpv4,Tmpv004, &
14433 a_Tmpv5,Tmpv005,a_Tmpv6,Tmpv006,a_Tmpv7,Tmpv007,a_Tmpv8,Tmpv008
14436 REAL,DIMENSION(PARAM_FIRST_SCALAR:max0(n_moist,n_chem,n_tracer,n_scalar)) :: Tmpv200
14437 REAL,DIMENSION(its:max0(ite,min(ite,ide-1)),jts:min(jte,jde-1)) :: Tmpv300
14438 REAL,DIMENSION(its:max0(ite,min(ite,ide-1)),jts:min(jte,jde-1)) :: Tmpv301
14439 REAL,DIMENSION(its:max0(ite,min(ite,ide-1)),jts:min(jte,jde-1)) :: Tmpv302
14440 REAL,DIMENSION(its:max0(ite,min(ite,ide-1)),jts:min(jte,jde-1)) :: Tmpv303
14441 REAL,DIMENSION(its:max0(ite,min(ite,ide-1)),jts:min(jte,jde-1)) :: Tmpv304
14442 REAL,DIMENSION(its:ite,jts:min(jte,jde-1)) :: Tmpv305
14443 REAL,DIMENSION(its:ite,jts:min(jte,jde-1)) :: Tmpv306
14444 REAL,DIMENSION(its:ite,jts:min(jte,jde-1)) :: Tmpv307
14445 REAL,DIMENSION(its:ite,jts:min(jte,jde-1)) :: Tmpv308
14446 REAL,DIMENSION(its:ite,jts:min(jte,jde-1)) :: Tmpv309
14447 REAL,DIMENSION(its:min(ite,ide-1),jts:jte) :: Tmpv3010
14448 REAL,DIMENSION(its:min(ite,ide-1),jts:jte) :: Tmpv3011
14449 REAL,DIMENSION(its:min(ite,ide-1),jts:jte) :: Tmpv3012
14450 REAL,DIMENSION(its:min(ite,ide-1),jts:jte) :: Tmpv3013
14451 REAL,DIMENSION(its:min(ite,ide-1),jts:jte) :: Tmpv3014
14452 REAL,DIMENSION(its:min(ite,ide-1),jts:jte) :: Tmpv3015
14453 REAL,DIMENSION(its:min(ite,ide-1),jts:jte) :: Tmpv3016
14454 REAL,DIMENSION(its:min(ite,ide-1),jts:jte) :: Tmpv3017
14455 REAL,DIMENSION(its:min(ite,ide-1),jts:jte) :: Tmpv3018
14456 REAL,DIMENSION(its:min(ite,ide-1),jts:jte) :: Tmpv3019
14457 REAL,DIMENSION(its:ite,jts:min(jte,jde-1)) :: Tmpv3020
14458 REAL,DIMENSION(its:ite,jts:min(jte,jde-1)) :: Tmpv3021
14459 REAL,DIMENSION(its:ite,jts:min(jte,jde-1)) :: Tmpv3022
14460 REAL,DIMENSION(its:ite,jts:min(jte,jde-1)) :: Tmpv3023
14461 REAL,DIMENSION(its:ite,jts:min(jte,jde-1)) :: Tmpv3024
14462 REAL,DIMENSION(its:ite,jts:min(jte,jde-1)) :: Tmpv3025
14463 REAL,DIMENSION(its:ite,jts:min(jte,jde-1)) :: Tmpv3026
14464 REAL,DIMENSION(its:ite,jts:min(jte,jde-1)) :: Tmpv3027
14465 REAL,DIMENSION(its:ite,jts:min(jte,jde-1)) :: Tmpv3028
14466 REAL,DIMENSION(its:ite,jts:min(jte,jde-1)) :: Tmpv3029
14467 REAL,DIMENSION(its:ite,jts:min(jte,jde-1)) :: Tmpv3030
14468 REAL,DIMENSION(its:min(ite,ide-1),jts:jte) :: Tmpv3031
14469 REAL,DIMENSION(its:min(ite,ide-1),jts:jte) :: Tmpv3032
14470 REAL,DIMENSION(its:min(ite,ide-1),jts:jte) :: Tmpv3033
14471 REAL,DIMENSION(its:min(ite,ide-1),jts:jte) :: Tmpv3034
14472 REAL,DIMENSION(its:min(ite,ide-1),jts:jte) :: Tmpv3035
14473 REAL,DIMENSION(its:min(ite,ide-1),jts:jte) :: Tmpv3036
14474 REAL,DIMENSION(its:min(ite,ide-1),jts:jte) :: Tmpv3037
14475 REAL,DIMENSION(its:min(ite,ide-1),jts:jte) :: Tmpv3038
14476 REAL,DIMENSION(its:min(ite,ide-1),jts:jte) :: Tmpv3039
14477 REAL,DIMENSION(its:min(ite,ide-1),jts:jte) :: Tmpv3040
14478 REAL,DIMENSION(its:min(ite,ide-1),jts:jte) :: Tmpv3041
14479 REAL,DIMENSION(min0(jms,its):max0(jme,min(ite,ide-1)),min0(kms,jts):max0(kme,min(jte, &
14480 jde-1)),min0(ims,PARAM_FIRST_SCALAR):max0(ime,n_moist)) :: Tmpv400
14481 REAL,DIMENSION(min0(jms,its):max0(jme,min(ite,ide-1)),min0(kms,jts):max0(kme,min(jte, &
14482 jde-1)),min0(ims,PARAM_FIRST_SCALAR):max0(ime,n_moist)) :: Tmpv401
14483 REAL,DIMENSION(min0(jms,its):max0(jme,min(ite,ide-1)),min0(kms,jts):max0(kme,min(jte, &
14484 jde-1)),min0(ims,PARAM_FIRST_SCALAR):max0(ime,n_moist)) :: Tmpv402
14485 REAL,DIMENSION(its:min(ite,ide-1),jts:min(jte,jde-1),PARAM_FIRST_SCALAR:n_moist) :: Tmpv403
14486 REAL,DIMENSION(min0(1,its):max0(n_nba_mij,min(ite, ide-1)),min0(jms,kts) &
14487 :max0(jme,kte-1),min0(kms,jts):max0(kme,min(jte, jde-1)),min0(ims,PARAM_FIRST_SCALAR) &
14488 :max0(ime,n_moist)) :: Tmpv500
14489 REAL,DIMENSION(min0(1,its):max0(n_nba_mij,min(ite, ide-1)),min0(jms,kts) &
14490 :max0(jme,kte-1),min0(kms,jts):max0(kme,min(jte, jde-1)),min0(ims,PARAM_FIRST_SCALAR) &
14491 :max0(ime,n_moist)) :: Tmpv501
14492 REAL,DIMENSION(n_nba_mij,jms:jme,kms:kme,ims:ime) :: Tmpv502
14496 !PART II: CALCULATIONS OF B. S. TRAJECTORY
14499 ! Remarked by Ning Pan, 2010-08-10
14503 ! Keep_Lpb0_ru_tendf(IX1,IX2,IX3) =ru_tendf(IX1,IX2,IX3)
14507 ! DO IX4=1,n_nba_mij
14511 ! Keep_Lpb0_nba_mij(IX1,IX2,IX3,IX4) =nba_mij(IX1,IX2,IX3,IX4)
14519 ! Keep_Lpb0_rv_tendf(IX1,IX2,IX3) =rv_tendf(IX1,IX2,IX3)
14526 ! Keep_Lpb0_rw_tendf(IX1,IX2,IX3) =rw_tendf(IX1,IX2,IX3)
14532 i_end = MIN(ite,ide-1)
14534 j_end = MIN(jte,jde-1)
14535 !! Remarked by Ning Pan, 2010-08-10: r3997-r4319
14536 ! CALL vertical_diffusion_u_2( ru_tendf, config_flags, mu, &
14538 ! nba_mij, n_nba_mij, &
14539 ! dnw, rdzw, fnm, fnp, &
14540 ! ids, ide, jds, jde, kds, kde, &
14541 ! ims, ime, jms, jme, kms, kme, &
14542 ! its, ite, jts, jte, kts, kte )
14543 ! CALL vertical_diffusion_v_2( rv_tendf, config_flags, mu, &
14545 ! nba_mij, n_nba_mij, &
14546 ! dnw, rdzw, fnm, fnp, &
14547 ! ids, ide, jds, jde, kds, kde, &
14548 ! ims, ime, jms, jme, kms, kme, &
14549 ! its, ite, jts, jte, kts, kte )
14550 ! CALL vertical_diffusion_w_2( rw_tendf, config_flags, mu, &
14551 ! defor33, tke(ims,kms,jms), &
14552 ! nba_mij, n_nba_mij, &
14555 ! ids, ide, jds, jde, kds, kde, &
14556 ! ims, ime, jms, jme, kms, kme, &
14557 ! its, ite, jts, jte, kts, kte )
14560 ! vflux: SELECT CASE( config_flags%isfflx )
14563 ! cd0 = config_flags%tke_drag_coefficient
14565 ! DO j = j_start, j_end
14566 ! DO i = i_start, ite
14569 ! V0_u= sqrt((u_2(i,kts,j)**2) + &
14570 ! (((v_2(i ,kts,j )+ &
14571 ! v_2(i ,kts,j+1)+ &
14572 ! v_2(i-1,kts,j )+ &
14573 ! v_2(i-1,kts,j+1))/4)**2))+epsilon
14574 ! tao_xz=cd0*V0_u*u_2(i,kts,j)
14575 ! ru_tendf(i,kts,j)=ru_tendf(i,kts,j) &
14576 ! -0.25*(mu(i,j)+mu(i-1,j))*tao_xz*(rdzw(i,kts,j)+rdzw(i-1,kts,j))
14580 ! DO j = j_start, jte
14581 ! DO i = i_start, i_end
14584 ! V0_v= sqrt((v_2(i,kts,j)**2) + &
14585 ! (((u_2(i ,kts,j )+ &
14586 ! u_2(i ,kts,j-1)+ &
14587 ! u_2(i+1,kts,j )+ &
14588 ! u_2(i+1,kts,j-1))/4)**2))+epsilon
14589 ! tao_yz=cd0*V0_v*v_2(i,kts,j)
14590 ! rv_tendf(i,kts,j)=rv_tendf(i,kts,j) &
14591 ! -0.25*(mu(i,j)+mu(i,j-1))*tao_yz*(rdzw(i,kts,j)+rdzw(i,kts,j-1))
14596 ! DO j = j_start, j_end
14597 ! DO i = i_start, ite
14600 ! V0_u= sqrt((u_2(i,kts,j)**2) + &
14601 ! (((v_2(i ,kts,j )+ &
14602 ! v_2(i ,kts,j+1)+ &
14603 ! v_2(i-1,kts,j )+ &
14604 ! v_2(i-1,kts,j+1))/4)**2))+epsilon
14605 ! ustar=0.5*(ust(i,j)+ust(i-1,j))
14606 ! tao_xz=ustar*ustar*u_2(i,kts,j)/V0_u
14607 ! ru_tendf(i,kts,j)=ru_tendf(i,kts,j) &
14608 ! -0.25*(mu(i,j)+mu(i-1,j))*tao_xz*(rdzw(i,kts,j)+rdzw(i-1,kts,j))
14612 ! DO j = j_start, jte
14613 ! DO i = i_start, i_end
14616 ! V0_v= sqrt((v_2(i,kts,j)**2) + &
14617 ! (((u_2(i ,kts,j )+ &
14618 ! u_2(i ,kts,j-1)+ &
14619 ! u_2(i+1,kts,j )+ &
14620 ! u_2(i+1,kts,j-1))/4)**2))+epsilon
14621 ! ustar=0.5*(ust(i,j)+ust(i,j-1))
14622 ! tao_yz=ustar*ustar*v_2(i,kts,j)/V0_v
14623 ! rv_tendf(i,kts,j)=rv_tendf(i,kts,j) &
14624 ! -0.25*(mu(i,j)+mu(i,j-1))*tao_yz*(rdzw(i,kts,j)+rdzw(i,kts,j-1))
14628 ! CALL wrf_error_fatal( 'isfflx value invalid for diff_opt=2' )
14635 ! IF ( config_flags%mix_full_fields ) THEN
14637 ! DO j=jts,min(jte,jde-1)
14639 ! DO i=its,min(ite,ide-1)
14640 ! var_mix(i,k,j) = thp(i,k,j)
14646 ! DO j=jts,min(jte,jde-1)
14648 ! DO i=its,min(ite,ide-1)
14649 ! var_mix(i,k,j) = thp(i,k,j) - t_base(k)
14660 ! Keep_Lpb4_rt_tendf(IX1,IX2,IX3) =rt_tendf(IX1,IX2,IX3)
14665 ! CALL vertical_diffusion_s( rt_tendf, config_flags, var_mix, mu, xkhv, &
14666 ! dn, dnw, rdz, rdzw, fnm, fnp, &
14668 ! ids, ide, jds, jde, kds, kde, &
14669 ! ims, ime, jms, jme, kms, kme, &
14670 ! its, ite, jts, jte, kts, kte )
14673 ! hflux: SELECT CASE( config_flags%isfflx )
14676 ! heat_flux = config_flags%tke_heat_flux
14678 ! DO j = j_start, j_end
14679 ! DO i = i_start, i_end
14680 ! cpm = cp * (1. + 0.8 * moist(i,kts,j,P_QV))
14681 ! hfx(i,j)=heat_flux*cp*rho(i,1,j) ! provided for output only
14682 ! rt_tendf(i,kts,j)=rt_tendf(i,kts,j) &
14683 ! +mu(i,j)*heat_flux*rdzw(i,kts,j)
14688 ! DO j = j_start, j_end
14689 ! DO i = i_start, i_end
14690 ! cpm = cp * (1. + 0.8 * moist(i,kts,j,P_QV))
14691 ! heat_flux = hfx(i,j)/cpm/rho(i,1,j)
14692 ! rt_tendf(i,kts,j)=rt_tendf(i,kts,j) &
14693 ! +mu(i,j)*heat_flux*rdzw(i,kts,j)
14697 ! CALL wrf_error_fatal( 'isfflx value invalid for iff_opt=2' )
14707 ! Keep_Lpb7_tke_tendf(IX1,IX2,IX3) =tke_tendf(IX1,IX2,IX3)
14712 ! If (km_opt .eq. 2) then
14714 ! CALL vertical_diffusion_s( tke_tendf(ims,kms,jms), &
14715 ! config_flags, tke(ims,kms,jms), &
14717 ! dn, dnw, rdz, rdzw, fnm, fnp, &
14719 ! ids, ide, jds, jde, kds, kde, &
14720 ! ims, ime, jms, jme, kms, kme, &
14721 ! its, ite, jts, jte, kts, kte )
14731 ! Keep_Lpb9_var_mix(IX1,IX2,IX3) =var_mix(IX1,IX2,IX3)
14739 ! Keep_Lpb9_moist_tendf(IX1,IX2,IX3,IX4) =moist_tendf(IX1,IX2,IX3,IX4)
14748 ! Keep_Lpb9_moist_tendf(IX1,IX2,IX3,IX4) =moist_tendf(IX1,IX2,IX3,IX4)
14754 ! IF (n_moist .ge. PARAM_FIRST_SCALAR) THEN
14756 ! moist_loop: do im = PARAM_FIRST_SCALAR, n_moist
14757 ! IF ( (.not. config_flags%mix_full_fields) .and. (im == P_QV) ) THEN
14759 ! DO j=jts,min(jte,jde-1)
14761 ! DO i=its,min(ite,ide-1)
14762 ! var_mix(i,k,j) = moist(i,k,j,im) - qv_base(k)
14768 ! DO j=jts,min(jte,jde-1)
14770 ! DO i=its,min(ite,ide-1)
14771 ! var_mix(i,k,j) = moist(i,k,j,im)
14776 ! CALL vertical_diffusion_s( moist_tendf(ims,kms,jms,im), &
14777 ! config_flags, var_mix, &
14779 ! dn, dnw, rdz, rdzw, fnm, fnp, &
14781 ! ids, ide, jds, jde, kds, kde, &
14782 ! ims, ime, jms, jme, kms, kme, &
14783 ! its, ite, jts, jte, kts, kte )
14784 ! qflux: SELECT CASE( config_flags%isfflx )
14788 ! IF ( im == P_QV ) THEN
14790 ! DO j = j_start, j_end
14791 ! DO i = i_start, i_end
14792 ! moist_flux = qfx(i,j)/rho(i,1,j)/(1.+moist(i,kts,j,P_QV))
14793 ! moist_tendf(i,kts,j,im)=moist_tendf(i,kts,j,im) &
14794 ! +mu(i,j)*moist_flux*rdzw(i,kts,j)
14799 ! CALL wrf_error_fatal( 'isfflx value invalid for diff_opt=2' )
14812 ! Keep_Lpb11_chem_tendf(IX1,IX2,IX3,IX4) =chem_tendf(IX1,IX2,IX3,IX4)
14818 ! IF (n_chem .ge. PARAM_FIRST_SCALAR) THEN
14820 ! chem_loop: do im = PARAM_FIRST_SCALAR, n_chem
14821 ! CALL vertical_diffusion_s( chem_tendf(ims,kms,jms,im), &
14822 ! config_flags, chem(ims,kms,jms,im), &
14824 ! dn, dnw, rdz, rdzw, fnm, fnp, &
14826 ! ids, ide, jds, jde, kds, kde, &
14827 ! ims, ime, jms, jme, kms, kme, &
14828 ! its, ite, jts, jte, kts, kte )
14836 ! DO IX4=1,n_tracer
14840 ! Keep_Lpb13_tracer_tendf(IX1,IX2,IX3,IX4) =tracer_tendf(IX1,IX2,IX3,IX4)
14846 ! IF (n_tracer .ge. PARAM_FIRST_SCALAR) THEN
14848 ! tracer_loop: do im = PARAM_FIRST_SCALAR, n_tracer
14849 ! CALL vertical_diffusion_s( tracer_tendf(ims,kms,jms,im), &
14850 ! config_flags, tracer(ims,kms,jms,im), &
14852 ! dn, dnw, rdz, rdzw, fnm, fnp, &
14854 ! ids, ide, jds, jde, kds, kde, &
14855 ! ims, ime, jms, jme, kms, kme, &
14856 ! its, ite, jts, jte, kts, kte )
14857 ! ENDDO tracer_loop
14864 !! DO IX4=1,n_scalar
14868 ! ! Keep_Lpb15_scalar_tendf(IX1,IX2,IX3,IX4) =scalar_tendf(IX1,IX2,IX3,IX4)
14875 ! IF (n_scalar .ge. PARAM_FIRST_SCALAR) THEN
14877 ! scalar_loop: do im = PARAM_FIRST_SCALAR, n_scalar
14878 ! CALL vertical_diffusion_s( scalar_tendf(ims,kms,jms,im), &
14879 ! config_flags, scalar(ims,kms,jms,im), &
14881 ! dn, dnw, rdz, rdzw, fnm, fnp, &
14883 ! ids, ide, jds, jde, kds, kde, &
14884 ! ims, ime, jms, jme, kms, kme, &
14885 ! its, ite, jts, jte, kts, kte )
14886 ! ENDDO scalar_loop
14890 !PART III: INITIALIZATION OF LOCAL ADJOINT PERTURBATIONS
14892 Do K2_ADJ =jms, jme
14893 Do K1_ADJ =kms, kme
14894 Do K0_ADJ =ims, ime
14895 a_var_mix(K0_ADJ,K1_ADJ,K2_ADJ) =0.0
14905 ! Remarked by Ning Pan, 2010-08-11
14914 ! a_heat_flux0 =0.0 ! Remarked by Ning Pan, 2010-08-11
14917 !PART IV: REVERSE/BACKWARD ACCUMULATIONS
14920 ! DO IX4=1,n_scalar
14924 ! scalar_tendf(IX1,IX2,IX3,IX4) =Keep_Lpb15_scalar_tendf(IX1,IX2,IX3,IX4)
14930 ! IF(n_scalar .ge. PARAM_FIRST_SCALAR) THEN
14931 ! DO im =PARAM_FIRST_SCALAR, n_scalar
14932 ! Tmpv200(im) =scalar_tendf(ims,kms,jms,im)
14933 ! CALL vertical_diffusion_s(scalar_tendf(ims,kms,jms,im),config_flags,scalar(ims, &
14934 ! kms,jms,im),mu,xkhv,dn,dnw,rdz,rdzw,fnm,fnp,.false.,ids,ide,jds,jde,kds,kde,ims,ime, &
14935 ! jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
14941 IF(n_scalar .ge. PARAM_FIRST_SCALAR) THEN
14943 DO im =n_scalar, PARAM_FIRST_SCALAR, -1
14945 ! scalar_tendf(ims,kms,jms,im) =Tmpv200(im) ! Remarked by Ning Pan, 2010-08-11
14947 CALL a_vertical_diffusion_s(scalar_tendf(ims,kms,jms,im),a_scalar_tendf(ims, &
14948 kms,jms,im),config_flags,scalar(ims,kms,jms,im),a_scalar(ims,kms,jms,im) &
14949 ! Revised by Ning Pan, 2010-08-10
14950 ! ,mu,a_mu,xkhv,a_xkhv,dn,dnw,rdz,a_rdz,rdzw,a_rdzw,fnm,fnp,,ids,ide,jds,jde, &
14951 ,mu,a_mu,xkhv,a_xkhv,dn,dnw,rdz,a_rdz,rdzw,a_rdzw,fnm,fnp,rho,a_rho,.false.,ids,ide,jds,jde, &
14952 kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
14960 ! Remarked by Ning Pan, 2010-08-10
14961 ! DO IX4=1,n_tracer
14965 ! tracer_tendf(IX1,IX2,IX3,IX4) =Keep_Lpb13_tracer_tendf(IX1,IX2,IX3,IX4)
14971 ! IF(n_tracer .ge. PARAM_FIRST_SCALAR) THEN
14972 ! DO im =PARAM_FIRST_SCALAR, n_tracer
14973 ! Tmpv200(im) =tracer_tendf(ims,kms,jms,im)
14974 ! CALL vertical_diffusion_s(tracer_tendf(ims,kms,jms,im),config_flags,tracer(ims, &
14975 ! kms,jms,im),mu,xkhv,dn,dnw,rdz,rdzw,fnm,fnp,.false.,ids,ide,jds,jde,kds,kde,ims,ime, &
14976 ! jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
14982 IF(n_tracer .ge. PARAM_FIRST_SCALAR) THEN
14984 DO im =n_tracer, PARAM_FIRST_SCALAR, -1
14986 ! tracer_tendf(ims,kms,jms,im) =Tmpv200(im) ! Remarked by Ning Pan, 2010-08-11
14988 CALL a_vertical_diffusion_s(tracer_tendf(ims,kms,jms,im),a_tracer_tendf(ims, &
14989 kms,jms,im),config_flags,tracer(ims,kms,jms,im),a_tracer(ims,kms,jms,im) &
14990 ! Revised by Ning Pan, 2010-08-10
14991 ! ,mu,a_mu,xkhv,a_xkhv,dn,dnw,rdz,a_rdz,rdzw,a_rdzw,fnm,fnp,,ids,ide,jds,jde, &
14992 ,mu,a_mu,xkhv,a_xkhv,dn,dnw,rdz,a_rdz,rdzw,a_rdzw,fnm,fnp,rho,a_rho,.false.,ids,ide,jds,jde, &
14993 kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
15001 ! Remarked by Ning Pan, 2010-08-10
15006 ! chem_tendf(IX1,IX2,IX3,IX4) =Keep_Lpb11_chem_tendf(IX1,IX2,IX3,IX4)
15012 ! IF(n_chem .ge. PARAM_FIRST_SCALAR) THEN
15013 ! DO im =PARAM_FIRST_SCALAR, n_chem
15014 ! Tmpv200(im) =chem_tendf(ims,kms,jms,im)
15015 ! CALL vertical_diffusion_s(chem_tendf(ims,kms,jms,im),config_flags,chem(ims,kms, &
15016 ! jms,im),mu,xkhv,dn,dnw,rdz,rdzw,fnm,fnp,.false.,ids,ide,jds,jde,kds,kde,ims,ime,jms, &
15017 ! jme,kms,kme,its,ite,jts,jte,kts,kte)
15023 IF(n_chem .ge. PARAM_FIRST_SCALAR) THEN
15025 DO im =n_chem, PARAM_FIRST_SCALAR, -1
15027 ! chem_tendf(ims,kms,jms,im) =Tmpv200(im) ! Remarked by Ning Pan, 2010-08-11
15029 CALL a_vertical_diffusion_s(chem_tendf(ims,kms,jms,im),a_chem_tendf(ims,kms, &
15030 jms,im),config_flags,chem(ims,kms,jms,im),a_chem(ims,kms,jms,im),mu,a_mu,xkhv, &
15031 ! Revised by Ning Pan, 2010-08-10
15032 ! a_xkhv,dn,dnw,rdz,a_rdz,rdzw,a_rdzw,fnm,fnp,,ids,ide,jds,jde,kds,kde,ims,ime, &
15033 a_xkhv,dn,dnw,rdz,a_rdz,rdzw,a_rdzw,fnm,fnp,rho,a_rho,.false.,ids,ide,jds,jde,kds,kde,ims,ime, &
15034 jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
15042 ! Remarked by Ning Pan, 2010-08-10
15046 ! var_mix(IX1,IX2,IX3) =Keep_Lpb9_var_mix(IX1,IX2,IX3)
15054 ! moist_tendf(IX1,IX2,IX3,IX4) =Keep_Lpb9_moist_tendf(IX1,IX2,IX3,IX4)
15063 ! moist_tendf(IX1,IX2,IX3,IX4) =Keep_Lpb9_moist_tendf(IX1,IX2,IX3,IX4)
15069 IF(n_moist .ge. PARAM_FIRST_SCALAR) THEN
15070 DO im =PARAM_FIRST_SCALAR, n_moist
15071 IF( (.not. config_flags%mix_full_fields) .and. (im == P_QV) ) THEN
15073 DO j =jts, min(jte, jde-1)
15075 DO i =its, min(ite, ide-1)
15076 ! Tmpv500(i,k,j,im) =var_mix(i,k,j) ! Remarked by Ning Pan, 2010-08-11
15077 var_mix(i,k,j) =moist(i,k,j,im) -qv_base(k)
15084 DO j =jts, min(jte, jde-1)
15086 DO i =its, min(ite, ide-1)
15087 ! Tmpv501(i,k,j,im) =var_mix(i,k,j) ! Remarked by Ning Pan, 2010-08-11
15088 var_mix(i,k,j) =moist(i,k,j,im)
15094 ! Remarked by Ning Pan, 2010-08-10
15095 ! Tmpv200(im) =moist_tendf(ims,kms,jms,im)
15096 ! CALL vertical_diffusion_s(moist_tendf(ims,kms,jms,im),config_flags,var_mix,mu, &
15097 ! xkhv,dn,dnw,rdz,rdzw,fnm,fnp,.false.,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme, &
15098 ! its,ite,jts,jte,kts,kte)
15100 SELECT CASE (config_flags%isfflx)
15103 IF( im == P_QV ) THEN
15105 DO j =j_start, j_end
15106 DO i =i_start, i_end
15107 Tmpv001 =qfx(i,j)/rho(i,1,j)
15108 Tmpv400(i,j,im) =Tmpv001
15109 Tmpv002 =Tmpv400(i,j,im)/(1. +moist(i,kts,j,P_QV))
15110 ! Revised by Ning Pan, 2010-08-11
15111 ! Tmpv401(i,j,im) =moist_flux
15112 ! moist_flux =Tmpv002
15113 moist_flux =Tmpv002
15114 Tmpv401(i,j,im) =moist_flux
15116 Tmpv001 =mu(i,j)*moist_flux
15117 Tmpv402(i,j,im) =Tmpv001
15118 ! Remarked by Ning Pan, 2010-08-11
15119 ! Tmpv002 =Tmpv402(i,j,im)*rdzw(i,kts,j)
15120 ! Tmpv003 =moist_tendf(i,kts,j,im) +Tmpv002
15121 ! Tmpv403(i,j,im) =moist_tendf(i,kts,j,im)
15122 ! moist_tendf(i,kts,j,im) =Tmpv003
15128 CALL wrf_error_fatal('isfflx value invalid for diff_opt=2')
15130 ! Revised by Ning Pan, 2010-08-10
15137 IF(n_moist .ge. PARAM_FIRST_SCALAR) THEN
15139 DO im =n_moist, PARAM_FIRST_SCALAR, -1
15141 SELECT CASE (config_flags%isfflx)
15147 IF( im == P_QV ) THEN
15149 DO j =j_end, j_start, -1
15150 DO i =i_end, i_start, -1
15152 ! moist_tendf(i,kts,j,im) =Tmpv403(i,j,im) ! Remarked by Ning Pan, 2010-08-11
15153 ! Added by Ning Pan, 2010-08-11
15154 moist_flux =Tmpv401(i,j,im)
15156 a_Tmpv3 =a_moist_tendf(i,kts,j,im)
15157 a_moist_tendf(i,kts,j,im) =0.0
15158 a_moist_tendf(i,kts,j,im) =a_moist_tendf(i,kts,j,im) +a_Tmpv3
15160 a_Tmpv1 =rdzw(i,kts,j)*a_Tmpv2
15161 a_rdzw(i,kts,j) =a_rdzw(i,kts,j) +Tmpv402(i,j,im)*a_Tmpv2
15162 a_mu(i,j) =a_mu(i,j) +moist_flux*a_Tmpv1
15163 a_moist_flux =a_moist_flux +mu(i,j)*a_Tmpv1
15165 ! moist_flux =Tmpv401(i,j,im) ! Remarked by Ning Pan, 2010-08-11
15167 a_Tmpv2 =a_moist_flux
15169 a_Tmpv1 =a_Tmpv2/(1. +moist(i,kts,j,P_QV))
15170 a_moist(i,kts,j,P_QV) =a_moist(i,kts,j,P_QV) -Tmpv400(i,j,im)/((1. +moist(i, &
15171 kts,j,P_QV))*(1. +moist(i,kts,j,P_QV)))*a_Tmpv2
15172 a_qfx(i,j) =a_qfx(i,j) +a_Tmpv1/rho(i,1,j)
15173 a_rho(i,1,j) =a_rho(i,1,j) -qfx(i,j)/(rho(i,1,j)*rho(i,1,j))*a_Tmpv1
15181 ! Revised by Ning Pan, 2010-08-10
15182 ! CALL a_wrf_error_fatal('isfflx value invalid for diff_opt=2')
15183 CALL wrf_error_fatal('isfflx value invalid for diff_opt=2')
15185 ! Revised by Ning Pan, 2010-08-10
15189 ! moist_tendf(ims,kms,jms,im) =Tmpv200(im) ! Remarked by Ning Pan, 2010-08-11
15191 CALL a_vertical_diffusion_s(moist_tendf(ims,kms,jms,im),a_moist_tendf(ims,kms, &
15192 jms,im),config_flags,var_mix,a_var_mix,mu,a_mu,xkhv,a_xkhv,dn,dnw,rdz,a_rdz, &
15193 ! Revised by Ning Pan, 2010-08-10
15194 ! rdzw,a_rdzw,fnm,fnp,,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts, &
15195 rdzw,a_rdzw,fnm,fnp,rho,a_rho,.false.,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts, &
15198 IF( (.not. config_flags%mix_full_fields) .and. (im == P_QV) ) THEN
15200 DO j =min(jte, jde-1), jts, -1
15201 DO k =kte-1, kts, -1
15202 DO i =min(ite, ide-1), its, -1
15204 ! var_mix(i,k,j) =Tmpv500(i,k,j,im) ! Remarked by Ning Pan, 2010-08-11
15206 a_moist(i,k,j,im) =a_moist(i,k,j,im) +a_var_mix(i,k,j)
15207 a_var_mix(i,k,j) =0.0
15214 DO j =min(jte, jde-1), jts, -1
15215 DO k =kte-1, kts, -1
15216 DO i =min(ite, ide-1), its, -1
15218 ! var_mix(i,k,j) =Tmpv501(i,k,j,im) ! Remarked by Ning Pan, 2010-08-11
15220 a_moist(i,k,j,im) =a_moist(i,k,j,im) +a_var_mix(i,k,j)
15221 a_var_mix(i,k,j) =0.0
15234 ! Remarked by Ning Pan, 2010-08-10
15238 ! tke_tendf(IX1,IX2,IX3) =Keep_Lpb7_tke_tendf(IX1,IX2,IX3)
15243 ! IF(km_opt .eq. 2) THEN
15244 ! Tmpv_1 =tke_tendf(ims,kms,jms)
15245 ! CALL vertical_diffusion_s(tke_tendf(ims,kms,jms),config_flags,tke(ims,kms,jms) &
15246 ! ,mu,xkhv,dn,dnw,rdz,rdzw,fnm,fnp,.true.,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms, &
15247 ! kme,its,ite,jts,jte,kts,kte)
15251 IF(km_opt .eq. 2) THEN
15253 ! tke_tendf(ims,kms,jms) =Tmpv_1 ! Remarked by Ning Pan, 2010-08-11
15255 CALL a_vertical_diffusion_s(tke_tendf(ims,kms,jms),a_tke_tendf(ims,kms,jms) &
15256 ,config_flags,tke(ims,kms,jms),a_tke(ims,kms,jms),mu,a_mu,xkhv,a_xkhv,dn,dnw, &
15257 ! Revised by Ning Pan, 2010-08-10
15258 ! rdz,a_rdz,rdzw,a_rdzw,fnm,fnp,,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme, &
15259 rdz,a_rdz,rdzw,a_rdzw,fnm,fnp,rho,a_rho,.true.,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme, &
15260 its,ite,jts,jte,kts,kte)
15268 SELECT CASE (config_flags%isfflx)
15270 heat_flux =config_flags%tke_heat_flux
15272 DO j =j_start, j_end
15273 DO i =i_start, i_end
15274 Tmpv001 =mu(i,j)*heat_flux
15275 Tmpv300(i,j) =Tmpv001
15276 ! Remarked by Ning Pan, 2010-08-11
15277 ! Tmpv002 =Tmpv300(i,j)*rdzw(i,kts,j)
15278 ! Tmpv003 =rt_tendf(i,kts,j) +Tmpv002
15279 ! rt_tendf(i,kts,j) =Tmpv003
15284 DO j =j_start, j_end
15285 DO i =i_start, i_end
15286 ! Revised by Ning Pan, 2010-08-11
15287 ! Tmpv301(i,j) =cpm
15288 ! cpm =cp*(1. +0.8*moist(i,kts,j,P_QV))
15289 cpm =cp*(1. +0.8*moist(i,kts,j,P_QV))
15292 Tmpv001 =hfx(i,j)/cpm
15293 Tmpv302(i,j) =Tmpv001
15294 Tmpv002 =Tmpv302(i,j)/rho(i,1,j)
15295 ! Revised by Ning Pan, 2010-08-11
15296 ! Tmpv303(i,j) =heat_flux
15297 ! heat_flux =Tmpv002
15299 Tmpv303(i,j) =heat_flux
15301 Tmpv001 =mu(i,j)*heat_flux
15302 Tmpv304(i,j) =Tmpv001
15303 ! Remarked by Ning Pan, 2010-08-11
15304 ! Tmpv002 =Tmpv304(i,j)*rdzw(i,kts,j)
15305 ! Tmpv003 =rt_tendf(i,kts,j) +Tmpv002
15306 ! rt_tendf(i,kts,j) =Tmpv003
15311 CALL wrf_error_fatal('isfflx value invalid for diff_opt=2')
15313 ! Revised by Ning Pan, 2010-08-10
15317 SELECT CASE (config_flags%isfflx)
15321 DO j =j_end, j_start, -1
15322 DO i =i_end, i_start, -1
15323 a_Tmpv3 =a_rt_tendf(i,kts,j)
15324 a_rt_tendf(i,kts,j) =0.0
15325 a_rt_tendf(i,kts,j) =a_rt_tendf(i,kts,j) +a_Tmpv3
15327 a_Tmpv1 =rdzw(i,kts,j)*a_Tmpv2
15328 a_rdzw(i,kts,j) =a_rdzw(i,kts,j) +Tmpv300(i,j)*a_Tmpv2
15329 a_mu(i,j) =a_mu(i,j) +heat_flux*a_Tmpv1
15330 ! a_heat_flux =a_heat_flux +mu(i,j)*a_Tmpv1 ! Remarked by Ning Pan, 2010-08-11
15333 ! Remarked by Ning Pan, 2010-08-10
15334 ! a_config_flags%tke_heat_flux =a_config_flags%tke_heat_flux +a_heat_flux
15339 DO j =j_end, j_start, -1
15340 DO i =i_end, i_start, -1
15341 heat_flux =Tmpv303(i,j) ! Added by Ning Pan, 2010-08-11
15342 a_Tmpv3 =a_rt_tendf(i,kts,j)
15343 a_rt_tendf(i,kts,j) =0.0
15344 a_rt_tendf(i,kts,j) =a_rt_tendf(i,kts,j) +a_Tmpv3
15346 a_Tmpv1 =rdzw(i,kts,j)*a_Tmpv2
15347 a_rdzw(i,kts,j) =a_rdzw(i,kts,j) +Tmpv304(i,j)*a_Tmpv2
15348 a_mu(i,j) =a_mu(i,j) +heat_flux*a_Tmpv1
15349 a_heat_flux =a_heat_flux +mu(i,j)*a_Tmpv1
15351 ! heat_flux =Tmpv303(i,j) ! Remarked by Ning Pan, 2010-08-11
15353 cpm =Tmpv301(i,j) ! Added by Ning Pan, 2010-08-11
15354 a_Tmpv2 =a_heat_flux
15356 a_Tmpv1 =a_Tmpv2/rho(i,1,j)
15357 a_rho(i,1,j) =a_rho(i,1,j) -Tmpv302(i,j)/(rho(i,1,j)*rho(i,1,j))*a_Tmpv2
15358 a_hfx(i,j) =a_hfx(i,j) +a_Tmpv1/cpm
15359 a_cpm =a_cpm -hfx(i,j)/(cpm*cpm)*a_Tmpv1
15361 ! cpm =Tmpv301(i,j) ! Remarked by Ning Pan, 2010-08-11
15363 a_moist(i,kts,j,P_QV) =a_moist(i,kts,j,P_QV) +cp*0.8*a_cpm
15370 ! Revised by Ning Pan, 2010-08-10
15371 ! CALL a_wrf_error_fatal('isfflx value invalid for diff_opt=2')
15372 CALL wrf_error_fatal('isfflx value invalid for diff_opt=2')
15374 ! Revised by Ning Pan, 2010-08-10
15379 ! Remarked by Ning Pan, 2010-08-10
15383 ! rt_tendf(IX1,IX2,IX3) =Keep_Lpb4_rt_tendf(IX1,IX2,IX3)
15391 ! Tmpv400(IX1,IX2,IX3) =rt_tendf(IX1,IX2,IX3)
15396 ! CALL vertical_diffusion_s(rt_tendf,config_flags,var_mix,mu,xkhv,dn,dnw,rdz,rdzw, &
15397 ! fnm,fnp,.false.,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
15399 ! Remarked by Ning Pan, 2010-08-11
15403 ! rt_tendf(IX1,IX2,IX3) =Tmpv400(IX1,IX2,IX3)
15408 ! Added by Ning Pan, 2010-08-11
15410 IF( config_flags%mix_full_fields ) THEN
15411 DO j =jts, min(jte, jde-1)
15413 DO i =its, min(ite, ide-1)
15414 var_mix(i,k,j) =thp(i,k,j)
15419 DO j =jts, min(jte, jde-1)
15421 DO i =its, min(ite, ide-1)
15422 var_mix(i,k,j) =thp(i,k,j) -t_base(k)
15428 CALL a_vertical_diffusion_s(rt_tendf,a_rt_tendf,config_flags,var_mix, &
15429 ! Revised by Ning Pan, 2010-08-10
15430 ! a_var_mix,mu,a_mu,xkhv,a_xkhv,dn,dnw,rdz,a_rdz,rdzw,a_rdzw,fnm,fnp,,ids, &
15431 a_var_mix,mu,a_mu,xkhv,a_xkhv,dn,dnw,rdz,a_rdz,rdzw,a_rdzw,fnm,fnp,rho,a_rho,.false.,ids, &
15432 ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
15436 ! IF( config_flags%mix_full_fields ) THEN
15437 ! DO j =jts, min(jte, jde-1)
15439 ! DO i =its, min(ite, ide-1)
15440 ! var_mix(i,k,j) =thp(i,k,j)
15446 ! DO j =jts, min(jte, jde-1)
15448 ! DO i =its, min(ite, ide-1)
15449 ! var_mix(i,k,j) =thp(i,k,j) -t_base(k)
15456 IF( config_flags%mix_full_fields ) THEN
15458 DO j =min(jte, jde-1), jts, -1
15459 DO k =kte-1, kts, -1
15460 DO i =min(ite, ide-1), its, -1
15461 a_thp(i,k,j) =a_thp(i,k,j) +a_var_mix(i,k,j)
15462 a_var_mix(i,k,j) =0.0
15469 DO j =min(jte, jde-1), jts, -1
15470 DO k =kte-1, kts, -1
15471 DO i =min(ite, ide-1), its, -1
15472 a_thp(i,k,j) =a_thp(i,k,j) +a_var_mix(i,k,j)
15473 a_var_mix(i,k,j) =0.0
15484 SELECT CASE (config_flags%isfflx)
15486 cd0 =config_flags%tke_drag_coefficient
15488 DO j =j_start, j_end
15490 ! Tmpv300(i,j) =V0_u ! Remarked by Ning Pan, 2010-08-11
15493 ! Tmpv301(i,j) =tao_xz ! Remarked by Ning Pan, 2010-08-11
15496 Tmpv001 =v_2(i,kts,j) +v_2(i,kts,j+1)
15497 Tmpv002 =Tmpv001 +v_2(i-1,kts,j)
15498 Tmpv003 =Tmpv002 +v_2(i-1,kts,j+1)
15500 Tmpv302(i,j) =Tmpv004
15501 Tmpv005 =Tmpv302(i,j)**2
15502 Tmpv006 =(u_2(i,kts,j)**2) +Tmpv005
15503 Tmpv303(i,j) =Tmpv006
15504 Tmpv007 =sqrt(Tmpv303(i,j))
15505 Tmpv008 =Tmpv007 +epsilon
15506 ! Revised by Ning Pan, 2010-08-11
15507 ! Tmpv304(i,j) =V0_u
15513 Tmpv305(i,j) =Tmpv001
15514 Tmpv002 =Tmpv305(i,j)*u_2(i,kts,j)
15515 ! Revised by Ning Pan, 2010-08-11
15516 ! Tmpv306(i,j) =tao_xz
15519 Tmpv306(i,j) =tao_xz
15521 Tmpv001 =mu(i,j) +mu(i-1,j)
15522 Tmpv002 =0.25*Tmpv001
15523 Tmpv307(i,j) =Tmpv002
15524 Tmpv003 =Tmpv307(i,j)*tao_xz
15525 Tmpv004 =rdzw(i,kts,j) +rdzw(i-1,kts,j)
15526 Tmpv308(i,j) =Tmpv003
15527 Tmpv309(i,j) =Tmpv004
15528 ! Remarked by Ning Pan, 2010-08-11
15529 ! Tmpv005 =Tmpv308(i,j)*Tmpv309(i,j)
15530 ! Tmpv006 =ru_tendf(i,kts,j) -Tmpv005
15531 ! ru_tendf(i,kts,j) =Tmpv006
15536 DO i =i_start, i_end
15537 ! Tmpv3010(i,j) =V0_v ! Remarked by Ning Pan, 2010-08-11
15540 ! Tmpv3011(i,j) =tao_yz ! Remarked by Ning Pan, 2010-08-11
15543 Tmpv001 =u_2(i,kts,j) +u_2(i,kts,j-1)
15544 Tmpv002 =Tmpv001 +u_2(i+1,kts,j)
15545 Tmpv003 =Tmpv002 +u_2(i+1,kts,j-1)
15547 Tmpv3012(i,j) =Tmpv004
15548 Tmpv005 =Tmpv3012(i,j)**2
15549 Tmpv006 =(v_2(i,kts,j)**2) +Tmpv005
15550 Tmpv3013(i,j) =Tmpv006
15551 Tmpv007 =sqrt(Tmpv3013(i,j))
15552 Tmpv008 =Tmpv007 +epsilon
15553 ! Revised by Ning Pan, 2010-08-11
15554 ! Tmpv3014(i,j) =V0_v
15557 Tmpv3014(i,j) =V0_v
15560 Tmpv3015(i,j) =Tmpv001
15561 Tmpv002 =Tmpv3015(i,j)*v_2(i,kts,j)
15562 ! Revised by Ning Pan, 2010-08-11
15563 ! Tmpv3016(i,j) =tao_yz
15566 Tmpv3016(i,j) =tao_yz
15568 Tmpv001 =mu(i,j) +mu(i,j-1)
15569 Tmpv002 =0.25*Tmpv001
15570 Tmpv3017(i,j) =Tmpv002
15571 Tmpv003 =Tmpv3017(i,j)*tao_yz
15572 Tmpv004 =rdzw(i,kts,j) +rdzw(i,kts,j-1)
15573 Tmpv3018(i,j) =Tmpv003
15574 Tmpv3019(i,j) =Tmpv004
15575 ! Remarked by Ning Pan, 2010-08-11
15576 ! Tmpv005 =Tmpv3018(i,j)*Tmpv3019(i,j)
15577 ! Tmpv006 =rv_tendf(i,kts,j) -Tmpv005
15578 ! rv_tendf(i,kts,j) =Tmpv006
15583 DO j =j_start, j_end
15585 ! Tmpv3020(i,j) =V0_u ! Remarked by Ning Pan, 2010-08-11
15588 ! Tmpv3021(i,j) =tao_xz ! Remarked by Ning Pan, 2010-08-11
15591 Tmpv001 =v_2(i,kts,j) +v_2(i,kts,j+1)
15592 Tmpv002 =Tmpv001 +v_2(i-1,kts,j)
15593 Tmpv003 =Tmpv002 +v_2(i-1,kts,j+1)
15595 Tmpv3022(i,j) =Tmpv004
15596 Tmpv005 =Tmpv3022(i,j)**2
15597 Tmpv006 =(u_2(i,kts,j)**2) +Tmpv005
15598 Tmpv3023(i,j) =Tmpv006
15599 Tmpv007 =sqrt(Tmpv3023(i,j))
15600 Tmpv008 =Tmpv007 +epsilon
15601 ! Revised by Ning Pan, 2010-08-11
15602 ! Tmpv3024(i,j) =V0_u
15605 Tmpv3024(i,j) =V0_u
15607 Tmpv001 =ust(i,j) +ust(i-1,j)
15608 Tmpv002 =0.5*Tmpv001
15609 ! Revised by Ning Pan, 2010-08-11
15610 ! Tmpv3025(i,j) =ustar
15613 Tmpv3025(i,j) =ustar
15615 Tmpv001 =ustar*ustar*u_2(i,kts,j)
15616 Tmpv3026(i,j) =Tmpv001
15617 Tmpv002 =Tmpv3026(i,j)/V0_u
15618 ! Revised by Ning Pan, 2010-08-11
15619 ! Tmpv3027(i,j) =tao_xz
15622 Tmpv3027(i,j) =tao_xz
15624 Tmpv001 =mu(i,j) +mu(i-1,j)
15625 Tmpv002 =0.25*Tmpv001
15626 Tmpv3028(i,j) =Tmpv002
15627 Tmpv003 =Tmpv3028(i,j)*tao_xz
15628 Tmpv004 =rdzw(i,kts,j) +rdzw(i-1,kts,j)
15629 Tmpv3029(i,j) =Tmpv003
15630 Tmpv3030(i,j) =Tmpv004
15631 ! Remarked by Ning Pan, 2010-08-11
15632 ! Tmpv005 =Tmpv3029(i,j)*Tmpv3030(i,j)
15633 ! Tmpv006 =ru_tendf(i,kts,j) -Tmpv005
15634 ! ru_tendf(i,kts,j) =Tmpv006
15639 DO i =i_start, i_end
15640 ! Tmpv3031(i,j) =V0_v ! Remakred by Ning Pan, 2010-08-11
15643 ! Tmpv3032(i,j) =tao_yz ! Remarked by Ning Pan, 2010-08-11
15646 Tmpv001 =u_2(i,kts,j) +u_2(i,kts,j-1)
15647 Tmpv002 =Tmpv001 +u_2(i+1,kts,j)
15648 Tmpv003 =Tmpv002 +u_2(i+1,kts,j-1)
15650 Tmpv3033(i,j) =Tmpv004
15651 Tmpv005 =Tmpv3033(i,j)**2
15652 Tmpv006 =(v_2(i,kts,j)**2) +Tmpv005
15653 Tmpv3034(i,j) =Tmpv006
15654 Tmpv007 =sqrt(Tmpv3034(i,j))
15655 Tmpv008 =Tmpv007 +epsilon
15656 ! Revised by Ning Pan, 2010-08-11
15657 ! Tmpv3035(i,j) =V0_v
15660 Tmpv3035(i,j) =V0_v
15662 Tmpv001 =ust(i,j) +ust(i,j-1)
15663 Tmpv002 =0.5*Tmpv001
15664 ! Revised by Ning Pan, 2010-08-11
15665 ! Tmpv3036(i,j) =ustar
15668 Tmpv3036(i,j) =ustar
15670 Tmpv001 =ustar*ustar*v_2(i,kts,j)
15671 Tmpv3037(i,j) =Tmpv001
15672 Tmpv002 =Tmpv3037(i,j)/V0_v
15673 ! Revised by Ning Pan, 2010-08-11
15674 ! Tmpv3038(i,j) =tao_yz
15677 Tmpv3038(i,j) =tao_yz
15679 Tmpv001 =mu(i,j) +mu(i,j-1)
15680 Tmpv002 =0.25*Tmpv001
15681 Tmpv3039(i,j) =Tmpv002
15682 Tmpv003 =Tmpv3039(i,j)*tao_yz
15683 Tmpv004 =rdzw(i,kts,j) +rdzw(i,kts,j-1)
15684 Tmpv3040(i,j) =Tmpv003
15685 Tmpv3041(i,j) =Tmpv004
15686 ! Remarked by Ning Pan, 2010-08-11
15687 ! Tmpv005 =Tmpv3040(i,j)*Tmpv3041(i,j)
15688 ! Tmpv006 =rv_tendf(i,kts,j) -Tmpv005
15689 ! rv_tendf(i,kts,j) =Tmpv006
15694 CALL wrf_error_fatal('isfflx value invalid for diff_opt=2')
15696 ! Revised by Ning Pan, 2010-08-10
15700 SELECT CASE (config_flags%isfflx)
15704 DO j =jte, j_start, -1
15705 DO i =i_end, i_start, -1
15706 IF ( (config_flags%m_opt .EQ. 1) .OR. (config_flags%sfs_opt .GT. 0) ) THEN
15707 a_tao_yz = -a_nba_mij(i, kts, j, p_m23)
15708 a_nba_mij(i, kts, j, p_m23) = 0.0
15712 tao_yz =Tmpv3016(i,j) ! Added by Ning Pan, 2010-08-11
15713 a_Tmpv6 =a_rv_tendf(i,kts,j)
15714 a_rv_tendf(i,kts,j) =0.0
15715 a_rv_tendf(i,kts,j) =a_rv_tendf(i,kts,j) +a_Tmpv6
15717 a_Tmpv3 =Tmpv3019(i,j)*a_Tmpv5
15718 a_Tmpv4 =Tmpv3018(i,j)*a_Tmpv5
15719 a_rdzw(i,kts,j) =a_rdzw(i,kts,j) +a_Tmpv4
15720 a_rdzw(i,kts,j-1) =a_rdzw(i,kts,j-1) +a_Tmpv4
15721 a_Tmpv2 =tao_yz*a_Tmpv3
15722 a_tao_yz =a_tao_yz +Tmpv3017(i,j)*a_Tmpv3
15723 a_Tmpv1 =0.25*a_Tmpv2
15724 a_mu(i,j) =a_mu(i,j) +a_Tmpv1
15725 a_mu(i,j-1) =a_mu(i,j-1) +a_Tmpv1
15727 ! tao_yz =Tmpv3016(i,j) ! Remarked by Ning Pan, 2010-08-11
15731 a_Tmpv1 =v_2(i,kts,j)*a_Tmpv2
15732 a_v_2(i,kts,j) =a_v_2(i,kts,j) +Tmpv3015(i,j)*a_Tmpv2
15733 ! a_cd0 =a_cd0 +V0_v*a_Tmpv1 ! Remarked by Ning Pan, 2010-08-11
15734 a_V0_v =a_V0_v +cd0*a_Tmpv1
15736 ! V0_v =Tmpv3014(i,j) ! Remarked by Ning Pan, 2010-08-11
15741 a_Tmpv6 =g_Sqrt(1.0, Tmpv3013(i,j))*a_Tmpv7
15742 a_v_2(i,kts,j) =a_v_2(i,kts,j) +2.0*v_2(i,kts,j)*a_Tmpv6
15744 a_Tmpv4 =2.0*Tmpv3012(i,j)*a_Tmpv5
15747 a_u_2(i+1,kts,j-1) =a_u_2(i+1,kts,j-1) +a_Tmpv3
15749 a_u_2(i+1,kts,j) =a_u_2(i+1,kts,j) +a_Tmpv2
15750 a_u_2(i,kts,j) =a_u_2(i,kts,j) +a_Tmpv1
15751 a_u_2(i,kts,j-1) =a_u_2(i,kts,j-1) +a_Tmpv1
15753 ! tao_yz =Tmpv3011(i,j) ! Remarked by Ning Pan, 2010-08-11
15757 ! V0_v =Tmpv3010(i,j) ! Remarked by Ning Pan, 2010-08-11
15762 DO j =j_end, j_start, -1
15763 DO i =ite, i_start, -1
15764 IF ( (config_flags%m_opt .EQ. 1) .OR. (config_flags%sfs_opt .GT. 0) ) THEN
15765 a_tao_xz = -a_nba_mij(i, kts, j, p_m13)
15766 a_nba_mij(i, kts, j, p_m13) = 0.0
15770 tao_xz =Tmpv306(i,j) ! Added by Ning Pan, 2010-08-11
15771 a_Tmpv6 =a_ru_tendf(i,kts,j)
15772 a_ru_tendf(i,kts,j) =0.0
15773 a_ru_tendf(i,kts,j) =a_ru_tendf(i,kts,j) +a_Tmpv6
15775 a_Tmpv3 =Tmpv309(i,j)*a_Tmpv5
15776 a_Tmpv4 =Tmpv308(i,j)*a_Tmpv5
15777 a_rdzw(i,kts,j) =a_rdzw(i,kts,j) +a_Tmpv4
15778 a_rdzw(i-1,kts,j) =a_rdzw(i-1,kts,j) +a_Tmpv4
15779 a_Tmpv2 =tao_xz*a_Tmpv3
15780 a_tao_xz =a_tao_xz +Tmpv307(i,j)*a_Tmpv3
15781 a_Tmpv1 =0.25*a_Tmpv2
15782 a_mu(i,j) =a_mu(i,j) +a_Tmpv1
15783 a_mu(i-1,j) =a_mu(i-1,j) +a_Tmpv1
15785 ! tao_xz =Tmpv306(i,j) ! Remarked by Ning Pan, 2010-08-11
15789 a_Tmpv1 =u_2(i,kts,j)*a_Tmpv2
15790 a_u_2(i,kts,j) =a_u_2(i,kts,j) +Tmpv305(i,j)*a_Tmpv2
15791 ! a_cd0 =a_cd0 +V0_u*a_Tmpv1 ! Remarked by Ning Pan, 2010-08-11
15792 a_V0_u =a_V0_u +cd0*a_Tmpv1
15794 ! V0_u =Tmpv304(i,j) ! Remarked by Ning Pan, 2010-08-11
15799 a_Tmpv6 =g_Sqrt(1.0, Tmpv303(i,j))*a_Tmpv7
15800 a_u_2(i,kts,j) =a_u_2(i,kts,j) +2.0*u_2(i,kts,j)*a_Tmpv6
15802 a_Tmpv4 =2.0*Tmpv302(i,j)*a_Tmpv5
15805 a_v_2(i-1,kts,j+1) =a_v_2(i-1,kts,j+1) +a_Tmpv3
15807 a_v_2(i-1,kts,j) =a_v_2(i-1,kts,j) +a_Tmpv2
15808 a_v_2(i,kts,j) =a_v_2(i,kts,j) +a_Tmpv1
15809 a_v_2(i,kts,j+1) =a_v_2(i,kts,j+1) +a_Tmpv1
15811 ! tao_xz =Tmpv301(i,j) ! Remarked by Ning Pan, 2010-08-11
15815 ! V0_u =Tmpv300(i,j) ! Remarked by Ning Pan, 2010-08-11
15820 ! a_config_flags%tke_drag_coefficient =a_config_flags%tke_drag_coefficient +a_cd0
15821 ! a_cd0 =0.0 ! Remarked by Ning Pan, 2010-08-11
15825 DO j =jte, j_start, -1
15826 DO i =i_end, i_start, -1
15827 IF ( (config_flags%m_opt .EQ. 1) .OR. (config_flags%sfs_opt .GT. 0) ) THEN
15828 a_tao_yz = -a_nba_mij(i, kts, j, p_m23)
15829 a_nba_mij(i, kts, j, p_m23) = 0.0
15833 tao_yz =Tmpv3038(i,j) ! Added by Ning Pan, 2010-08-11
15834 a_Tmpv6 =a_rv_tendf(i,kts,j)
15835 a_rv_tendf(i,kts,j) =0.0
15836 a_rv_tendf(i,kts,j) =a_rv_tendf(i,kts,j) +a_Tmpv6
15838 a_Tmpv3 =Tmpv3041(i,j)*a_Tmpv5
15839 a_Tmpv4 =Tmpv3040(i,j)*a_Tmpv5
15840 a_rdzw(i,kts,j) =a_rdzw(i,kts,j) +a_Tmpv4
15841 a_rdzw(i,kts,j-1) =a_rdzw(i,kts,j-1) +a_Tmpv4
15842 a_Tmpv2 =tao_yz*a_Tmpv3
15843 a_tao_yz =a_tao_yz +Tmpv3039(i,j)*a_Tmpv3
15844 a_Tmpv1 =0.25*a_Tmpv2
15845 a_mu(i,j) =a_mu(i,j) +a_Tmpv1
15846 a_mu(i,j-1) =a_mu(i,j-1) +a_Tmpv1
15848 ! tao_yz =Tmpv3038(i,j) ! Remarked by Ning Pan, 2010-08-11
15850 ! Added by Ning Pan, 2010-08-11
15851 V0_v =Tmpv3035(i,j)
15852 ustar =Tmpv3036(i,j)
15856 a_Tmpv1 =a_Tmpv2/V0_v
15857 a_V0_v =a_V0_v -Tmpv3037(i,j)/(V0_v*V0_v)*a_Tmpv2
15858 a_ustar =a_ustar +2.0*ustar*v_2(i,kts,j)*a_Tmpv1
15859 a_v_2(i,kts,j) =a_v_2(i,kts,j) +ustar*ustar*a_Tmpv1
15861 ! ustar =Tmpv3036(i,j) ! Remarked by Ning Pan, 2010-08-11
15865 a_Tmpv1 =0.5*a_Tmpv2
15866 a_ust(i,j) =a_ust(i,j) +a_Tmpv1
15867 a_ust(i,j-1) =a_ust(i,j-1) +a_Tmpv1
15869 ! V0_v =Tmpv3035(i,j) ! Remarked by Ning Pan, 2010-08-11
15874 a_Tmpv6 =g_Sqrt(1.0, Tmpv3034(i,j))*a_Tmpv7
15875 a_v_2(i,kts,j) =a_v_2(i,kts,j) +2.0*v_2(i,kts,j)*a_Tmpv6
15877 a_Tmpv4 =2.0*Tmpv3033(i,j)*a_Tmpv5
15880 a_u_2(i+1,kts,j-1) =a_u_2(i+1,kts,j-1) +a_Tmpv3
15882 a_u_2(i+1,kts,j) =a_u_2(i+1,kts,j) +a_Tmpv2
15883 a_u_2(i,kts,j) =a_u_2(i,kts,j) +a_Tmpv1
15884 a_u_2(i,kts,j-1) =a_u_2(i,kts,j-1) +a_Tmpv1
15886 ! tao_yz =Tmpv3032(i,j) ! Remarked by Ning Pan, 2010-08-11
15890 ! V0_v =Tmpv3031(i,j) ! Remarked by Ning Pan, 2010-08-11
15895 DO j =j_end, j_start, -1
15896 DO i =ite, i_start, -1
15897 IF ( (config_flags%m_opt .EQ. 1) .OR. (config_flags%sfs_opt .GT. 0) ) THEN
15898 a_tao_xz = -a_nba_mij(i, kts, j, p_m13)
15899 a_nba_mij(i, kts, j, p_m13) = 0.0
15903 tao_xz =Tmpv3027(i,j) ! Added by Ning Pan, 2010-08-11
15904 a_Tmpv6 =a_ru_tendf(i,kts,j)
15905 a_ru_tendf(i,kts,j) =0.0
15906 a_ru_tendf(i,kts,j) =a_ru_tendf(i,kts,j) +a_Tmpv6
15908 a_Tmpv3 =Tmpv3030(i,j)*a_Tmpv5
15909 a_Tmpv4 =Tmpv3029(i,j)*a_Tmpv5
15910 a_rdzw(i,kts,j) =a_rdzw(i,kts,j) +a_Tmpv4
15911 a_rdzw(i-1,kts,j) =a_rdzw(i-1,kts,j) +a_Tmpv4
15912 a_Tmpv2 =tao_xz*a_Tmpv3
15913 a_tao_xz =a_tao_xz +Tmpv3028(i,j)*a_Tmpv3
15914 a_Tmpv1 =0.25*a_Tmpv2
15915 a_mu(i,j) =a_mu(i,j) +a_Tmpv1
15916 a_mu(i-1,j) =a_mu(i-1,j) +a_Tmpv1
15918 ! tao_xz =Tmpv3027(i,j) ! Remarked by Ning Pan, 2010-08-11
15920 ! Added by Ning Pan, 2010-08-11
15921 V0_u =Tmpv3024(i,j)
15922 ustar =Tmpv3025(i,j)
15926 a_Tmpv1 =a_Tmpv2/V0_u
15927 a_V0_u =a_V0_u -Tmpv3026(i,j)/(V0_u*V0_u)*a_Tmpv2
15928 a_ustar =a_ustar +2.0*ustar*u_2(i,kts,j)*a_Tmpv1
15929 a_u_2(i,kts,j) =a_u_2(i,kts,j) +ustar*ustar*a_Tmpv1
15931 ! ustar =Tmpv3025(i,j) ! Remarked by Ning Pan, 2010-08-11
15935 a_Tmpv1 =0.5*a_Tmpv2
15936 a_ust(i,j) =a_ust(i,j) +a_Tmpv1
15937 a_ust(i-1,j) =a_ust(i-1,j) +a_Tmpv1
15939 ! V0_u =Tmpv3024(i,j) ! Remarked by Ning Pan, 2010-08-11
15944 a_Tmpv6 =g_Sqrt(1.0, Tmpv3023(i,j))*a_Tmpv7
15945 a_u_2(i,kts,j) =a_u_2(i,kts,j) +2.0*u_2(i,kts,j)*a_Tmpv6
15947 a_Tmpv4 =2.0*Tmpv3022(i,j)*a_Tmpv5
15950 a_v_2(i-1,kts,j+1) =a_v_2(i-1,kts,j+1) +a_Tmpv3
15952 a_v_2(i-1,kts,j) =a_v_2(i-1,kts,j) +a_Tmpv2
15953 a_v_2(i,kts,j) =a_v_2(i,kts,j) +a_Tmpv1
15954 a_v_2(i,kts,j+1) =a_v_2(i,kts,j+1) +a_Tmpv1
15956 ! tao_xz =Tmpv3021(i,j) ! Remarked by Ning Pan, 2010-08-11
15960 ! V0_u =Tmpv3020(i,j) ! Remarked by Ning Pan, 2010-08-11
15968 ! Revised by Ning Pan, 2010-08-10
15969 ! CALL a_wrf_error_fatal('isfflx value invalid for diff_opt=2')
15970 CALL wrf_error_fatal('isfflx value invalid for diff_opt=2')
15972 ! Revised by Ning Pan, 2010-08-10
15977 ! Remarked by Ning Pan, 2010-08-10
15981 ! ru_tendf(IX1,IX2,IX3) =Keep_Lpb0_ru_tendf(IX1,IX2,IX3)
15985 ! DO IX4=1,n_nba_mij
15989 ! nba_mij(IX1,IX2,IX3,IX4) =Keep_Lpb0_nba_mij(IX1,IX2,IX3,IX4)
15997 ! rv_tendf(IX1,IX2,IX3) =Keep_Lpb0_rv_tendf(IX1,IX2,IX3)
16004 ! rw_tendf(IX1,IX2,IX3) =Keep_Lpb0_rw_tendf(IX1,IX2,IX3)
16009 ! Remarked by Ning Pan, 2010-08-11
16011 ! i_end =min(ite, ide-1)
16013 ! j_end =min(jte, jde-1)
16017 ! Tmpv400(IX1,IX2,IX3) =ru_tendf(IX1,IX2,IX3)
16022 ! DO IX4=1,n_nba_mij
16026 ! Tmpv500(IX1,IX2,IX3,IX4) =nba_mij(IX1,IX2,IX3,IX4)
16032 Keep_Lpb0_nba_mij = nba_mij
16033 CALL vertical_diffusion_u_2(ru_tendf,config_flags,defor13,xkmv,nba_mij, &
16034 n_nba_mij,dnw,rdzw,fnm,fnp,rho,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite, &
16040 ! Tmpv401(IX1,IX2,IX3) =rv_tendf(IX1,IX2,IX3)
16045 ! DO IX4=1,n_nba_mij
16049 ! Tmpv501(IX1,IX2,IX3,IX4) =nba_mij(IX1,IX2,IX3,IX4)
16055 Keep_Lpb1_nba_mij = nba_mij
16056 CALL vertical_diffusion_v_2(rv_tendf,config_flags,defor23,xkmv,nba_mij, &
16057 n_nba_mij,dnw,rdzw,fnm,fnp,rho,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite, &
16063 ! Tmpv402(IX1,IX2,IX3) =rw_tendf(IX1,IX2,IX3)
16068 ! DO IX4=1,n_nba_mij
16072 ! Tmpv502(IX1,IX2,IX3,IX4) =nba_mij(IX1,IX2,IX3,IX4)
16078 ! CALL vertical_diffusion_w_2(rw_tendf,config_flags,defor33,tke(ims,kms,jms) &
16079 ! ,nba_mij,n_nba_mij,div,xkmv,dn,rdz,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme, &
16080 ! its,ite,jts,jte,kts,kte)
16082 ! DO IX4=1,n_nba_mij
16086 ! nba_mij(IX1,IX2,IX3,IX4) =Tmpv502(IX1,IX2,IX3,IX4)
16095 ! rw_tendf(IX1,IX2,IX3) =Tmpv402(IX1,IX2,IX3)
16100 CALL a_vertical_diffusion_w_2(rw_tendf,a_rw_tendf,config_flags,mu,a_mu, &
16101 defor33,a_defor33,tke(ims,kms,jms),a_tke(ims,kms,jms),nba_mij,a_nba_mij, &
16102 n_nba_mij,div,a_div,xkmv,a_xkmv,dn,rdz,a_rdz,rho,a_rho,ids,ide,jds,jde,kds,kde,ims,ime, &
16103 jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
16105 ! Remarked by Ning Pan, 2010-08-11
16106 ! DO IX4=1,n_nba_mij
16110 ! nba_mij(IX1,IX2,IX3,IX4) =Tmpv501(IX1,IX2,IX3,IX4)
16119 ! rv_tendf(IX1,IX2,IX3) =Tmpv401(IX1,IX2,IX3)
16124 nba_mij = Keep_Lpb1_nba_mij
16125 CALL a_vertical_diffusion_v_2(rv_tendf,a_rv_tendf,config_flags,mu,a_mu, &
16126 defor23,a_defor23,xkmv,a_xkmv,nba_mij,a_nba_mij,n_nba_mij,dnw,rdzw,a_rdzw, &
16127 fnm,fnp,rho,a_rho,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
16129 ! Remarked by Ning Pan, 2010-08-11
16130 ! DO IX4=1,n_nba_mij
16134 ! nba_mij(IX1,IX2,IX3,IX4) =Tmpv500(IX1,IX2,IX3,IX4)
16143 ! ru_tendf(IX1,IX2,IX3) =Tmpv400(IX1,IX2,IX3)
16148 nba_mij = Keep_Lpb0_nba_mij
16149 CALL a_vertical_diffusion_u_2(ru_tendf,a_ru_tendf,config_flags,mu,a_mu, &
16150 defor13,a_defor13,xkmv,a_xkmv,nba_mij,a_nba_mij,n_nba_mij,dnw,rdzw,a_rdzw, &
16151 fnm,fnp,rho,a_rho,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
16153 END SUBROUTINE a_vertical_diffusion_2
16155 SUBROUTINE a_vertical_diffusion_u_2(tendency,a_tendency,config_flags,mu,a_mu, &
16156 defor13,a_defor13,xkmv,a_xkmv,nba_mij,a_nba_mij,n_nba_mij,dnw,rdzw,a_rdzw, &
16157 fnm,fnp,rho,a_rho,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
16159 !PART I: DECLARATION OF VARIABLES
16163 INTEGER :: K0_ADJ,K1_ADJ,K2_ADJ,K3_ADJ
16164 TYPE(grid_config_rec_type) :: config_flags
16165 INTEGER :: ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte
16166 REAL,DIMENSION(kms:kme) :: fnm
16167 REAL,DIMENSION(kms:kme) :: fnp
16168 REAL,DIMENSION(kms:kme) :: dnw
16169 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: tendency,a_tendency
16170 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: defor13,a_defor13,xkmv,a_xkmv,rdzw,a_rdzw
16171 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: rho, a_rho
16172 INTEGER :: n_nba_mij
16173 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_nba_mij) :: nba_mij,a_nba_mij
16174 REAL,DIMENSION(ims:ime,jms:jme) :: mu,a_mu
16175 INTEGER :: i,j,k,ktf
16176 INTEGER :: i_start,i_end,j_start,j_end
16177 INTEGER :: is_ext,ie_ext,js_ext,je_ext
16178 REAL,DIMENSION(its-1:ite+1,kts:kte,jts-1:jte+1) :: titau3,a_titau3
16179 REAL,DIMENSION(its:ite,jts:jte) :: zzavg,a_zzavg
16180 REAL :: rdzu,a_rdzu
16182 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_nba_mij) :: Keep_Lpb12_nba_mij
16183 ! REAL,DIMENSION(max(jds+1,jts):min(jde-2,jte)) :: Keep_Lpb14_rdzu
16184 INTEGER :: IX1,IX2,IX3,IX4
16186 REAL :: a_Tmpv1,Tmpv001,a_Tmpv2,Tmpv002,a_Tmpv3,Tmpv003
16189 REAL,DIMENSION(its:ite) :: Tmpv200
16190 REAL,DIMENSION(its:ite) :: Tmpv201 ! Added by Ning Pan, 2010-08-10
16191 REAL,DIMENSION(its:ite,kts+1:min(kte,kde-1)) :: Tmpv300
16192 REAL,DIMENSION(its:ite,kts+1:min(kte,kde-1)) :: Tmpv301
16193 REAL,DIMENSION(its:ite,kts+1:min(kte,kde-1)) :: Tmpv302 ! Added by Ning Pan, 2010-08-10
16195 !PART II: CALCULATIONS OF B. S. TRAJECTORY
16203 j_end = MIN(jte,jde-1)
16206 IF ( config_flags%open_xs .or. config_flags%specified .or. &
16207 config_flags%nested) i_start = MAX(ids+1,its)
16212 IF ( config_flags%open_xe .or. config_flags%specified .or. &
16213 config_flags%nested) i_end = MIN(ide-1,ite)
16218 IF ( config_flags%open_ys .or. config_flags%specified .or. &
16219 config_flags%nested) j_start = MAX(jds+1,jts)
16224 IF ( config_flags%open_ye .or. config_flags%specified .or. &
16225 config_flags%nested) j_end = MIN(jde-2,jte)
16230 IF ( config_flags%periodic_x ) i_start = its
16235 IF ( config_flags%periodic_x ) i_end = ite
16242 Keep_Lpb12_nba_mij(IX1,IX2,IX3,IX4) =nba_mij(IX1,IX2,IX3,IX4)
16252 CALL cal_titau_13_31( config_flags, titau3, defor13, &
16253 nba_mij(ims,kms,jms,P_m13), &
16254 xkmv, fnm, fnp, rho, &
16255 is_ext, ie_ext, js_ext, je_ext, &
16256 ids, ide, jds, jde, kds, kde, &
16257 ims, ime, jms, jme, kms, kme, &
16258 its, ite, jts, jte, kts, kte )
16261 ! Remarked by Ning Pan, 2010-08-10
16262 ! DO j = j_start, j_end
16265 ! DO i = i_start, i_end
16266 ! rdzu = 2./(1./rdzw(i,k,j) + 1./rdzw(i-1,k,j))
16267 ! tendency(i,k,j)=tendency(i,k,j)-rdzu*(titau3(i,k+1,j)-titau3(i,k,j))
16274 ! DO j = j_start, j_end
16276 ! ! Keep_Lpb14_rdzu(j) =rdzu
16280 ! DO i = i_start, i_end
16281 ! rdzu = 2./(1./rdzw(i,k,j) + 1./rdzw(i-1,k,j))
16282 ! tendency(i,k,j)=tendency(i,k,j)-rdzu*(titau3(i,k+1,j))
16287 !PART III: INITIALIZATION OF LOCAL ADJOINT PERTURBATIONS
16289 Do K2_ADJ =jts-1, jte+1
16290 Do K1_ADJ =kts, kte
16291 Do K0_ADJ =its-1, ite+1
16292 a_titau3(K0_ADJ,K1_ADJ,K2_ADJ) =0.0
16297 Do K1_ADJ =jts, jte
16298 Do K0_ADJ =its, ite
16299 a_zzavg(K0_ADJ,K1_ADJ) =0.0
16305 !PART IV: REVERSE/BACKWARD ACCUMULATIONS
16308 DO j =j_end, j_start, -1
16310 ! rdzu =Keep_Lpb14_rdzu(j)
16313 DO i =i_start, i_end
16314 Tmpv001 =1./rdzw(i,k,j) +1./rdzw(i-1,k,j)
16315 Tmpv201(i) =Tmpv001 ! Added by Ning Pan, 2010-08-10
16316 Tmpv002 =2./Tmpv001
16317 ! Revised by Ning Pan, 2010-08-10
16323 ! Remarked by Ning Pan, 2010-08-10
16324 ! Tmpv001 =rdzu*(titau3(i,k+1,j))
16325 ! Tmpv002 =tendency(i,k,j) -Tmpv001
16326 ! tendency(i,k,j) =Tmpv002
16330 DO i =i_end, i_start, -1
16331 rdzu =Tmpv200(i) ! Added by Ning Pan, 2010-08-10
16332 a_Tmpv2 =a_tendency(i,k,j)
16333 a_tendency(i,k,j) =0.0
16334 a_tendency(i,k,j) =a_tendency(i,k,j) +a_Tmpv2
16336 a_rdzu =a_rdzu +(titau3(i,k+1,j))*a_Tmpv1
16337 a_titau3(i,k+1,j) =a_titau3(i,k+1,j) +rdzu*a_Tmpv1
16339 ! rdzu =Tmpv200(i) ! Remarked by Ning Pan, 2010-08-10
16343 ! Revised by Ning Pan, 2010-08-10
16344 ! a_Tmpv1 =-(2.)*a_Tmpv2/(Tmpv001*Tmpv001)
16345 a_Tmpv1 =-(2.)*a_Tmpv2/(Tmpv201(i)*Tmpv201(i))
16346 a_rdzw(i,k,j) =a_rdzw(i,k,j) -1./(rdzw(i,k,j)*rdzw(i,k,j))*a_Tmpv1
16347 a_rdzw(i-1,k,j) =a_rdzw(i-1,k,j) -1./(rdzw(i-1,k,j)*rdzw(i-1,k,j))*a_Tmpv1
16353 DO j =j_end, j_start, -1
16356 DO i =i_start, i_end
16357 Tmpv001 =1./rdzw(i,k,j) +1./rdzw(i-1,k,j)
16358 Tmpv302(i,k) =Tmpv001 ! Added by Ning Pan, 2010-08-10
16359 Tmpv002 =2./Tmpv001
16360 ! Revised by Ning Pan, 2010-08-10
16361 ! Tmpv300(i,k) =rdzu
16366 Tmpv001 =titau3(i,k+1,j) -titau3(i,k,j)
16367 Tmpv301(i,k) =Tmpv001
16368 ! Remarked by Ning Pan, 2010-08-10
16369 ! Tmpv002 =rdzu*Tmpv301(i,k)
16370 ! Tmpv003 =tendency(i,k,j) -Tmpv002
16371 ! tendency(i,k,j) =Tmpv003
16376 DO k =ktf, kts+1, -1
16377 DO i =i_end, i_start, -1
16378 rdzu =Tmpv300(i,k) ! Added by Ning Pan, 2010-08-10
16379 a_Tmpv3 =a_tendency(i,k,j)
16380 a_tendency(i,k,j) =0.0
16381 a_tendency(i,k,j) =a_tendency(i,k,j) +a_Tmpv3
16383 a_rdzu =a_rdzu +Tmpv301(i,k)*a_Tmpv2
16384 a_Tmpv1 =rdzu*a_Tmpv2
16385 a_titau3(i,k+1,j) =a_titau3(i,k+1,j) +a_Tmpv1
16386 a_titau3(i,k,j) =a_titau3(i,k,j) -a_Tmpv1
16388 ! rdzu =Tmpv300(i,k) ! Remarked by Ning Pan, 2010-08-10
16392 ! Revised by Ning Pan, 2010-08-10
16393 ! a_Tmpv1 =-(2.)*a_Tmpv2/(Tmpv001*Tmpv001)
16394 a_Tmpv1 =-(2.)*a_Tmpv2/(Tmpv302(i,k)*Tmpv302(i,k))
16395 a_rdzw(i,k,j) =a_rdzw(i,k,j) -1./(rdzw(i,k,j)*rdzw(i,k,j))*a_Tmpv1
16396 a_rdzw(i-1,k,j) =a_rdzw(i-1,k,j) -1./(rdzw(i-1,k,j)*rdzw(i-1,k,j))*a_Tmpv1
16407 nba_mij(IX1,IX2,IX3,IX4) =Keep_Lpb12_nba_mij(IX1,IX2,IX3,IX4)
16413 ! Remarked by Ning Pan, 2010-08-10
16418 ! Tmpv_1 =nba_mij(ims,kms,jms,P_m13)
16419 ! CALL cal_titau_13_31(config_flags,titau3,defor13,nba_mij(ims,kms,jms,P_m13) &
16420 ! ,mu,xkmv,fnm,fnp,is_ext,ie_ext,js_ext,je_ext,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme, &
16421 ! kms,kme,its,ite,jts,jte,kts,kte)
16423 ! nba_mij(ims,kms,jms,P_m13) =Tmpv_1
16425 CALL a_cal_titau_13_31(config_flags,titau3,a_titau3,defor13,a_defor13, &
16426 nba_mij(ims,kms,jms,P_m13),a_nba_mij(ims,kms,jms,P_m13),mu,a_mu,xkmv,a_xkmv, &
16427 fnm,fnp,rho,a_rho,is_ext,ie_ext,js_ext,je_ext,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme, &
16428 its,ite,jts,jte,kts,kte)
16432 ! IF( config_flags%periodic_x ) THEN
16436 ! IF( config_flags%periodic_x ) THEN
16444 ! IF( config_flags%periodic_x ) THEN
16448 ! IF( config_flags%periodic_x ) THEN
16456 ! IF( config_flags%open_ye .or. config_flags%specified .or. config_flags%nested) THEN
16457 ! j_end =min(jde-2, jte)
16460 ! IF( config_flags%open_ye .or. config_flags%specified .or. &
16461 ! config_flags%nested) THEN
16469 ! IF( config_flags%open_ys .or. config_flags%specified .or. config_flags%nested) THEN
16470 ! j_start =max(jds+1, jts)
16473 ! IF( config_flags%open_ys .or. config_flags%specified .or. &
16474 ! config_flags%nested) THEN
16482 ! IF( config_flags%open_xe .or. config_flags%specified .or. config_flags%nested) THEN
16483 ! i_end =min(ide-1, ite)
16486 ! IF( config_flags%open_xe .or. config_flags%specified .or. &
16487 ! config_flags%nested) THEN
16495 ! IF( config_flags%open_xs .or. config_flags%specified .or. config_flags%nested) THEN
16496 ! i_start =max(ids+1, its)
16499 ! IF( config_flags%open_xs .or. config_flags%specified .or. &
16500 ! config_flags%nested) THEN
16505 ! ktf =min(kte, kde-1)
16509 ! j_end =min(jte, jde-1)
16511 END SUBROUTINE a_vertical_diffusion_u_2
16513 SUBROUTINE a_vertical_diffusion_v_2(tendency,a_tendency,config_flags,mu,a_mu, &
16514 defor23,a_defor23,xkmv,a_xkmv,nba_mij,a_nba_mij,n_nba_mij,dnw,rdzw,a_rdzw, &
16515 fnm,fnp,rho,a_rho,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
16517 !PART I: DECLARATION OF VARIABLES
16521 INTEGER :: K0_ADJ,K1_ADJ,K2_ADJ,K3_ADJ
16522 TYPE(grid_config_rec_type) :: config_flags
16523 INTEGER :: ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte
16524 REAL,DIMENSION(kms:kme) :: fnm
16525 REAL,DIMENSION(kms:kme) :: fnp
16526 REAL,DIMENSION(kms:kme) :: dnw
16527 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: tendency,a_tendency
16528 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: defor23,a_defor23,xkmv,a_xkmv,rdzw,a_rdzw
16529 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: rho, a_rho
16530 INTEGER :: n_nba_mij
16531 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_nba_mij) :: nba_mij,a_nba_mij
16532 REAL,DIMENSION(ims:ime,jms:jme) :: mu,a_mu
16533 INTEGER :: i,j,k,ktf
16534 INTEGER :: i_start,i_end,j_start,j_end
16535 INTEGER :: is_ext,ie_ext,js_ext,je_ext
16536 REAL,DIMENSION(its-1:ite+1,kts:kte,jts-1:jte+1) :: titau3,a_titau3
16537 REAL,DIMENSION(its:ite,jts:jte) :: zzavg,a_zzavg
16538 REAL :: rdzv,a_rdzv
16540 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_nba_mij) :: Keep_Lpb12_nba_mij
16541 ! REAL,DIMENSION(max(jds+1,jts):min(jde-1,jte)) :: Keep_Lpb14_rdzv
16542 INTEGER :: IX1,IX2,IX3,IX4
16544 REAL :: a_Tmpv1,Tmpv001,a_Tmpv2,Tmpv002,a_Tmpv3,Tmpv003
16547 REAL,DIMENSION(its:min(ite,ide-1)) :: Tmpv200
16548 REAL,DIMENSION(its:min(ite,ide-1)) :: Tmpv201 ! Added by Ning Pan, 2010-08-10
16549 REAL,DIMENSION(its:min(ite,ide-1),kts+1:min(kte,kde-1)) :: Tmpv300
16550 REAL,DIMENSION(its:min(ite,ide-1),kts+1:min(kte,kde-1)) :: Tmpv301
16551 REAL,DIMENSION(its:min(ite,ide-1),kts+1:min(kte,kde-1)) :: Tmpv302 ! Added by Ning Pan, 2010-08-10
16553 !PART II: CALCULATIONS OF B. S. TRAJECTORY
16558 i_end = MIN(ite,ide-1)
16563 IF ( config_flags%open_xs .or. config_flags%specified .or. &
16564 config_flags%nested) i_start = MAX(ids+1,its)
16569 IF ( config_flags%open_xe .or. config_flags%specified .or. &
16570 config_flags%nested) i_end = MIN(ide-2,ite)
16575 IF ( config_flags%open_ys .or. config_flags%specified .or. &
16576 config_flags%nested) j_start = MAX(jds+1,jts)
16581 IF ( config_flags%open_ye .or. config_flags%specified .or. &
16582 config_flags%nested) j_end = MIN(jde-1,jte)
16587 IF ( config_flags%periodic_x ) i_start = its
16592 IF ( config_flags%periodic_x ) i_end = MIN(ite,ide-1)
16599 Keep_Lpb12_nba_mij(IX1,IX2,IX3,IX4) =nba_mij(IX1,IX2,IX3,IX4)
16609 CALL cal_titau_23_32( config_flags, titau3, defor23, &
16610 nba_mij(ims,kms,jms,P_m23), &
16611 xkmv, fnm, fnp, rho, &
16612 is_ext, ie_ext, js_ext, je_ext, &
16613 ids, ide, jds, jde, kds, kde, &
16614 ims, ime, jms, jme, kms, kme, &
16615 its, ite, jts, jte, kts, kte )
16618 ! Remarked by Ning Pan, 2010-08-10
16619 ! DO j = j_start, j_end
16622 ! DO i = i_start, i_end
16623 ! rdzv = 2./(1./rdzw(i,k,j) + 1./rdzw(i,k,j-1))
16624 ! tendency(i,k,j)=tendency(i,k,j)-rdzv*(titau3(i,k+1,j)-titau3(i,k,j))
16631 ! DO j = j_start, j_end
16633 ! ! Keep_Lpb14_rdzv(j) =rdzv
16637 ! DO i = i_start, i_end
16638 ! rdzv = 2./(1./rdzw(i,k,j) + 1./rdzw(i,k,j-1))
16639 ! tendency(i,k,j)=tendency(i,k,j)-rdzv*(titau3(i,k+1,j))
16644 !PART III: INITIALIZATION OF LOCAL ADJOINT PERTURBATIONS
16646 Do K2_ADJ =jts-1, jte+1
16647 Do K1_ADJ =kts, kte
16648 Do K0_ADJ =its-1, ite+1
16649 a_titau3(K0_ADJ,K1_ADJ,K2_ADJ) =0.0
16654 Do K1_ADJ =jts, jte
16655 Do K0_ADJ =its, ite
16656 a_zzavg(K0_ADJ,K1_ADJ) =0.0
16662 !PART IV: REVERSE/BACKWARD ACCUMULATIONS
16665 DO j =j_end, j_start, -1
16667 ! rdzv =Keep_Lpb14_rdzv(j)
16670 DO i =i_start, i_end
16671 Tmpv001 =1./rdzw(i,k,j) +1./rdzw(i,k,j-1)
16672 Tmpv201(i) =Tmpv001 ! Added by Ning Pan, 2010-08-10
16673 Tmpv002 =2./Tmpv001
16674 ! Revised by Ning Pan, 2010-08-10
16680 ! Remarked by Ning Pan, 2010-08-10
16681 ! Tmpv001 =rdzv*(titau3(i,k+1,j))
16682 ! Tmpv002 =tendency(i,k,j) -Tmpv001
16683 ! tendency(i,k,j) =Tmpv002
16687 DO i =i_end, i_start, -1
16688 rdzv =Tmpv200(i) ! Added by Ning Pan, 2010-08-10
16689 a_Tmpv2 =a_tendency(i,k,j)
16690 a_tendency(i,k,j) =0.0
16691 a_tendency(i,k,j) =a_tendency(i,k,j) +a_Tmpv2
16693 a_rdzv =a_rdzv +(titau3(i,k+1,j))*a_Tmpv1
16694 a_titau3(i,k+1,j) =a_titau3(i,k+1,j) +rdzv*a_Tmpv1
16696 ! rdzv =Tmpv200(i) ! Remarked by Ning Pan, 2010-08-10
16700 ! Revised by Ning Pan, 2010-08-10
16701 ! a_Tmpv1 =-(2.)*a_Tmpv2/(Tmpv001*Tmpv001)
16702 a_Tmpv1 =-(2.)*a_Tmpv2/(Tmpv201(i)*Tmpv201(i))
16703 a_rdzw(i,k,j) =a_rdzw(i,k,j) -1./(rdzw(i,k,j)*rdzw(i,k,j))*a_Tmpv1
16704 a_rdzw(i,k,j-1) =a_rdzw(i,k,j-1) -1./(rdzw(i,k,j-1)*rdzw(i,k,j-1))*a_Tmpv1
16710 DO j =j_end, j_start, -1
16713 DO i =i_start, i_end
16714 Tmpv001 =1./rdzw(i,k,j) +1./rdzw(i,k,j-1)
16715 Tmpv302(i,k) =Tmpv001 ! Added by Ning Pan, 2010-08-10
16716 Tmpv002 =2./Tmpv001
16717 ! Revised by Ning Pan, 2010-08-10
16718 ! Tmpv300(i,k) =rdzv
16723 Tmpv001 =titau3(i,k+1,j) -titau3(i,k,j)
16724 Tmpv301(i,k) =Tmpv001
16725 ! Remarked by Ning Pan, 2010-08-10
16726 ! Tmpv002 =rdzv*Tmpv301(i,k)
16727 ! Tmpv003 =tendency(i,k,j) -Tmpv002
16728 ! tendency(i,k,j) =Tmpv003
16733 DO k =ktf, kts+1, -1
16734 DO i =i_end, i_start, -1
16735 rdzv =Tmpv300(i,k) ! Added by Ning Pan, 2010-08-10
16736 a_Tmpv3 =a_tendency(i,k,j)
16737 a_tendency(i,k,j) =0.0
16738 a_tendency(i,k,j) =a_tendency(i,k,j) +a_Tmpv3
16740 a_rdzv =a_rdzv +Tmpv301(i,k)*a_Tmpv2
16741 a_Tmpv1 =rdzv*a_Tmpv2
16742 a_titau3(i,k+1,j) =a_titau3(i,k+1,j) +a_Tmpv1
16743 a_titau3(i,k,j) =a_titau3(i,k,j) -a_Tmpv1
16745 ! rdzv =Tmpv300(i,k) ! Remarked by Ning Pan, 2010-08-10
16749 ! Revised by Ning Pan, 2010-08-10
16750 ! a_Tmpv1 =-(2.)*a_Tmpv2/(Tmpv001*Tmpv001)
16751 a_Tmpv1 =-(2.)*a_Tmpv2/(Tmpv302(i,k)*Tmpv302(i,k))
16752 a_rdzw(i,k,j) =a_rdzw(i,k,j) -1./(rdzw(i,k,j)*rdzw(i,k,j))*a_Tmpv1
16753 a_rdzw(i,k,j-1) =a_rdzw(i,k,j-1) -1./(rdzw(i,k,j-1)*rdzw(i,k,j-1))*a_Tmpv1
16764 nba_mij(IX1,IX2,IX3,IX4) =Keep_Lpb12_nba_mij(IX1,IX2,IX3,IX4)
16770 ! Remarked by Ning Pan, 2010-08-10
16775 ! Tmpv_1 =nba_mij(ims,kms,jms,P_m23)
16776 ! CALL cal_titau_23_32(config_flags,titau3,defor23,nba_mij(ims,kms,jms,P_m23) &
16777 ! ,mu,xkmv,fnm,fnp,is_ext,ie_ext,js_ext,je_ext,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme, &
16778 ! kms,kme,its,ite,jts,jte,kts,kte)
16780 ! nba_mij(ims,kms,jms,P_m23) =Tmpv_1
16782 CALL a_cal_titau_23_32(config_flags,titau3,a_titau3,defor23,a_defor23, &
16783 nba_mij(ims,kms,jms,P_m23),a_nba_mij(ims,kms,jms,P_m23),mu,a_mu,xkmv,a_xkmv, &
16784 fnm,fnp,rho,a_rho,is_ext,ie_ext,js_ext,je_ext,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme, &
16785 its,ite,jts,jte,kts,kte)
16789 ! IF( config_flags%periodic_x ) THEN
16790 ! i_end =min(ite, ide-1)
16793 ! IF( config_flags%periodic_x ) THEN
16801 ! IF( config_flags%periodic_x ) THEN
16805 ! IF( config_flags%periodic_x ) THEN
16813 ! IF( config_flags%open_ye .or. config_flags%specified .or. config_flags%nested) THEN
16814 ! j_end =min(jde-1, jte)
16817 ! IF( config_flags%open_ye .or. config_flags%specified .or. &
16818 ! config_flags%nested) THEN
16826 ! IF( config_flags%open_ys .or. config_flags%specified .or. config_flags%nested) THEN
16827 ! j_start =max(jds+1, jts)
16830 ! IF( config_flags%open_ys .or. config_flags%specified .or. &
16831 ! config_flags%nested) THEN
16839 ! IF( config_flags%open_xe .or. config_flags%specified .or. config_flags%nested) THEN
16840 ! i_end =min(ide-2, ite)
16843 ! IF( config_flags%open_xe .or. config_flags%specified .or. &
16844 ! config_flags%nested) THEN
16852 ! IF( config_flags%open_xs .or. config_flags%specified .or. config_flags%nested) THEN
16853 ! i_start =max(ids+1, its)
16856 ! IF( config_flags%open_xs .or. config_flags%specified .or. &
16857 ! config_flags%nested) THEN
16862 ! ktf =min(kte, kde-1)
16864 ! i_end =min(ite, ide-1)
16868 END SUBROUTINE a_vertical_diffusion_v_2
16870 SUBROUTINE a_vertical_diffusion_w_2(tendency,a_tendency,config_flags,mu,a_mu, &
16871 defor33,a_defor33,tke,a_tke,nba_mij,a_nba_mij,n_nba_mij,div,a_div,xkmv, &
16872 a_xkmv,dn,rdz,a_rdz,rho,a_rho,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts, &
16875 !PART I: DECLARATION OF VARIABLES
16879 INTEGER :: K0_ADJ,K1_ADJ,K2_ADJ,K3_ADJ
16880 TYPE(grid_config_rec_type) :: config_flags
16881 INTEGER :: ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte
16882 REAL,DIMENSION(kms:kme) :: dn
16883 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: tendency,a_tendency
16884 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: defor33,a_defor33,tke,a_tke,div, &
16885 a_div,xkmv,a_xkmv,rdz,a_rdz
16886 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: rho, a_rho
16887 INTEGER :: n_nba_mij
16888 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_nba_mij) :: nba_mij,a_nba_mij
16889 REAL,DIMENSION(ims:ime,jms:jme) :: mu,a_mu
16890 INTEGER :: i,j,k,ktf
16891 INTEGER :: i_start,i_end,j_start,j_end
16892 INTEGER :: is_ext,ie_ext,js_ext,je_ext
16893 REAL,DIMENSION(its-1:ite+1,kts:kte,jts-1:jte+1) :: titau3,a_titau3
16895 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_nba_mij) :: Keep_Lpb12_nba_mij
16896 INTEGER :: IX1,IX2,IX3,IX4
16898 REAL :: a_Tmpv1,Tmpv001,a_Tmpv2,Tmpv002,a_Tmpv3,Tmpv003
16901 REAL,DIMENSION(its:min(ite,ide-1),kts+1:min(kte,kde-1)) :: Tmpv300
16903 !PART II: CALCULATIONS OF B. S. TRAJECTORY
16908 i_end = MIN(ite,ide-1)
16910 j_end = MIN(jte,jde-1)
16913 IF ( config_flags%open_xs .or. config_flags%specified .or. &
16914 config_flags%nested) i_start = MAX(ids+1,its)
16919 IF ( config_flags%open_xe .or. config_flags%specified .or. &
16920 config_flags%nested) i_end = MIN(ide-2,ite)
16925 IF ( config_flags%open_ys .or. config_flags%specified .or. &
16926 config_flags%nested) j_start = MAX(jds+1,jts)
16931 IF ( config_flags%open_ye .or. config_flags%specified .or. &
16932 config_flags%nested) j_end = MIN(jde-2,jte)
16937 IF ( config_flags%periodic_x ) i_start = its
16942 IF ( config_flags%periodic_x ) i_end = MIN(ite,ide-1)
16949 Keep_Lpb12_nba_mij(IX1,IX2,IX3,IX4) =nba_mij(IX1,IX2,IX3,IX4)
16959 CALL cal_titau_11_22_33( config_flags, titau3, &
16960 tke, xkmv, defor33, &
16961 nba_mij(ims,kms,jms,P_m33), rho, &
16962 is_ext, ie_ext, js_ext, je_ext, &
16963 ids, ide, jds, jde, kds, kde, &
16964 ims, ime, jms, jme, kms, kme, &
16965 its, ite, jts, jte, kts, kte )
16968 ! DO j = j_start, j_end
16970 ! DO k = kts+1, ktf
16971 ! DO i = i_start, i_end
16972 ! tendency(i,k,j)=tendency(i,k,j)-rdz(i,k,j)*(titau3(i,k,j)-titau3(i,k-1,j))
16978 !PART III: INITIALIZATION OF LOCAL ADJOINT PERTURBATIONS
16980 Do K2_ADJ =jts-1, jte+1
16981 Do K1_ADJ =kts, kte
16982 Do K0_ADJ =its-1, ite+1
16983 a_titau3(K0_ADJ,K1_ADJ,K2_ADJ) =0.0
16988 !PART IV: REVERSE/BACKWARD ACCUMULATIONS
16991 DO j =j_end, j_start, -1
16994 DO i =i_start, i_end
16995 Tmpv001 =titau3(i,k,j) -titau3(i,k-1,j)
16996 Tmpv300(i,k) =Tmpv001
16997 ! Remarked by Ning Pan, 2010-08-10
16998 ! Tmpv002 =rdz(i,k,j)*Tmpv300(i,k)
16999 ! Tmpv003 =tendency(i,k,j) -Tmpv002
17000 ! tendency(i,k,j) =Tmpv003
17005 DO k =ktf, kts+1, -1
17006 DO i =i_end, i_start, -1
17007 a_Tmpv3 =a_tendency(i,k,j)
17008 a_tendency(i,k,j) =0.0
17009 a_tendency(i,k,j) =a_tendency(i,k,j) +a_Tmpv3
17011 a_rdz(i,k,j) =a_rdz(i,k,j) +Tmpv300(i,k)*a_Tmpv2
17012 a_Tmpv1 =rdz(i,k,j)*a_Tmpv2
17013 a_titau3(i,k,j) =a_titau3(i,k,j) +a_Tmpv1
17014 a_titau3(i,k-1,j) =a_titau3(i,k-1,j) -a_Tmpv1
17025 nba_mij(IX1,IX2,IX3,IX4) =Keep_Lpb12_nba_mij(IX1,IX2,IX3,IX4)
17031 ! Remarked by Ning Pan, 2010-08-10
17036 ! Tmpv_1 =nba_mij(ims,kms,jms,P_m33)
17037 ! CALL cal_titau_11_22_33(config_flags,titau3,mu,tke,xkmv,defor33,nba_mij(ims,kms, &
17038 ! jms,P_m33),is_ext,ie_ext,js_ext,je_ext,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms, &
17039 ! kme,its,ite,jts,jte,kts,kte)
17041 ! nba_mij(ims,kms,jms,P_m33) =Tmpv_1
17043 CALL a_cal_titau_11_22_33(config_flags,titau3,a_titau3,mu,a_mu,tke,a_tke, &
17044 xkmv,a_xkmv,defor33,a_defor33,nba_mij(ims,kms,jms,P_m33),a_nba_mij(ims,kms,jms, &
17045 P_m33),rho,a_rho,is_ext,ie_ext,js_ext,je_ext,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme, &
17046 its,ite,jts,jte,kts,kte)
17050 ! IF( config_flags%periodic_x ) THEN
17051 ! i_end =min(ite, ide-1)
17054 ! IF( config_flags%periodic_x ) THEN
17062 ! IF( config_flags%periodic_x ) THEN
17066 ! IF( config_flags%periodic_x ) THEN
17074 ! IF( config_flags%open_ye .or. config_flags%specified .or. config_flags%nested) THEN
17075 ! j_end =min(jde-2, jte)
17078 ! IF( config_flags%open_ye .or. config_flags%specified .or. &
17079 ! config_flags%nested) THEN
17087 ! IF( config_flags%open_ys .or. config_flags%specified .or. config_flags%nested) THEN
17088 ! j_start =max(jds+1, jts)
17091 ! IF( config_flags%open_ys .or. config_flags%specified .or. &
17092 ! config_flags%nested) THEN
17100 ! IF( config_flags%open_xe .or. config_flags%specified .or. config_flags%nested) THEN
17101 ! i_end =min(ide-2, ite)
17104 ! IF( config_flags%open_xe .or. config_flags%specified .or. &
17105 ! config_flags%nested) THEN
17113 ! IF( config_flags%open_xs .or. config_flags%specified .or. config_flags%nested) THEN
17114 ! i_start =max(ids+1, its)
17117 ! IF( config_flags%open_xs .or. config_flags%specified .or. &
17118 ! config_flags%nested) THEN
17123 ! ktf =min(kte, kde-1)
17125 ! i_end =min(ite, ide-1)
17127 ! j_end =min(jte, jde-1)
17129 END SUBROUTINE a_vertical_diffusion_w_2
17131 SUBROUTINE a_vertical_diffusion_s(tendency,a_tendency,config_flags,var,a_var, &
17132 mu,a_mu,xkhv,a_xkhv,dn,dnw,rdz,a_rdz,rdzw,a_rdzw,fnm,fnp,rho,a_rho,doing_tke,ids,ide, &
17133 jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
17135 !PART I: DECLARATION OF VARIABLES
17139 INTEGER :: K0_ADJ,K1_ADJ,K2_ADJ,K3_ADJ
17140 TYPE(grid_config_rec_type) :: config_flags
17141 INTEGER :: ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte
17142 LOGICAL :: doing_tke
17143 REAL,DIMENSION(kms:kme) :: fnm
17144 REAL,DIMENSION(kms:kme) :: fnp
17145 REAL,DIMENSION(kms:kme) :: dn
17146 REAL,DIMENSION(kms:kme) :: dnw
17147 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: tendency,a_tendency
17148 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: xkhv,a_xkhv
17149 REAL,DIMENSION(ims:ime,jms:jme) :: mu,a_mu
17150 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: var,a_var,rdz,a_rdz,rdzw,a_rdzw
17151 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: rho, a_rho
17152 INTEGER :: i,j,k,ktf
17153 INTEGER :: i_start,i_end,j_start,j_end
17154 REAL,DIMENSION(its:ite,kts:kte,jts:jte) :: H3,a_H3,xkxavg,a_xkxavg,rravg,a_rravg
17155 REAL,DIMENSION(its:ite,kts:kte,jts:jte) :: tmptendf,a_tmptendf
17157 REAL :: a_Tmpv1,Tmpv001,a_Tmpv2,Tmpv002,a_Tmpv3,Tmpv003,a_Tmpv4,Tmpv004
17158 REAL,DIMENSION(its:min(ite,ide-1),min0(kts+1,kts):min(kte,kde-1)) :: Tmpv300
17159 REAL,DIMENSION(its:min(ite,ide-1),min0(kts+1,kts):min(kte,kde-1)) :: Tmpv301
17160 REAL,DIMENSION(its:min(ite,ide-1),kts+1:min(kte,kde-1)) :: Tmpv302
17162 !PART II: CALCULATIONS OF B. S. TRAJECTORY
17167 i_end = MIN(ite,ide-1)
17169 j_end = MIN(jte,jde-1)
17172 IF ( config_flags%open_xs .or. config_flags%specified .or. &
17173 config_flags%nested) i_start = MAX(ids+1,its)
17178 IF ( config_flags%open_xe .or. config_flags%specified .or. &
17179 config_flags%nested) i_end = MIN(ide-2,ite)
17184 IF ( config_flags%open_ys .or. config_flags%specified .or. &
17185 config_flags%nested) j_start = MAX(jds+1,jts)
17190 IF ( config_flags%open_ye .or. config_flags%specified .or. &
17191 config_flags%nested) j_end = MIN(jde-2,jte)
17196 IF ( config_flags%periodic_x ) i_start = its
17201 IF ( config_flags%periodic_x ) i_end = MIN(ite,ide-1)
17206 ! Remarked by Ning Pan, 2010-08-10
17207 ! IF (doing_tke) THEN
17209 ! DO j = j_start, j_end
17211 ! DO i = i_start, i_end
17212 ! tmptendf(i,k,j)=tendency(i,k,j)
17224 DO j = j_start, j_end
17227 DO i = i_start, i_end
17228 xkxavg(i,k,j)=fnm(k)*xkhv(i,k,j)+fnp(k)*xkhv(i,k-1,j)
17229 H3(i,k,j)=-xkxavg(i,k,j)*(var(i,k,j)-var(i,k-1,j))*rdz(i,k,j)
17236 DO j = j_start, j_end
17238 DO i = i_start, i_end
17246 ! DO j = j_start, j_end
17249 ! DO i = i_start, i_end
17250 ! tendency(i,k,j)=tendency(i,k,j) &
17251 ! -mu(i,j)*(H3(i,k+1,j)-H3(i,k,j))*rdzw(i,k,j)
17260 ! IF (doing_tke) THEN
17262 ! DO j = j_start, j_end
17264 ! DO i = i_start, i_end
17265 ! tendency(i,k,j)=tmptendf(i,k,j)+2.* &
17266 ! (tendency(i,k,j)-tmptendf(i,k,j))
17273 !PART III: INITIALIZATION OF LOCAL ADJOINT PERTURBATIONS
17275 Do K2_ADJ =jts, jte
17276 Do K1_ADJ =kts, kte
17277 Do K0_ADJ =its, ite
17278 a_H3(K0_ADJ,K1_ADJ,K2_ADJ) =0.0
17283 Do K2_ADJ =jts, jte
17284 Do K1_ADJ =kts, kte
17285 Do K0_ADJ =its, ite
17286 a_xkxavg(K0_ADJ,K1_ADJ,K2_ADJ) =0.0
17291 Do K2_ADJ =jts, jte
17292 Do K1_ADJ =kts, kte
17293 Do K0_ADJ =its, ite
17294 a_rravg(K0_ADJ,K1_ADJ,K2_ADJ) =0.0
17299 Do K2_ADJ =jts, jte
17300 Do K1_ADJ =kts, kte
17301 Do K0_ADJ =its, ite
17302 a_tmptendf(K0_ADJ,K1_ADJ,K2_ADJ) =0.0
17307 !PART IV: REVERSE/BACKWARD ACCUMULATIONS
17311 ! IF(doing_tke) THEN
17312 ! DO j =j_start, j_end
17314 ! DO i =i_start, i_end
17315 ! Tmpv001 =tendency(i,k,j) -tmptendf(i,k,j)
17316 ! Tmpv002 =2.*Tmpv001
17317 ! Tmpv003 =tmptendf(i,k,j) +Tmpv002
17318 ! tendency(i,k,j) =Tmpv003
17327 DO j =j_end, j_start, -1
17329 DO i =i_end, i_start, -1
17330 a_Tmpv3 =a_tendency(i,k,j)
17331 a_tendency(i,k,j) =0.0
17332 a_tmptendf(i,k,j) =a_tmptendf(i,k,j) +a_Tmpv3
17334 a_Tmpv1 =2.*a_Tmpv2
17335 a_tendency(i,k,j) =a_tendency(i,k,j) +a_Tmpv1
17336 a_tmptendf(i,k,j) =a_tmptendf(i,k,j) -a_Tmpv1
17346 DO j =j_end, j_start, -1
17349 DO i =i_start, i_end
17350 Tmpv001 =H3(i,k+1,j) -H3(i,k,j)
17351 Tmpv300(i,k) =Tmpv001
17352 Tmpv002 =mu(i,j)*Tmpv300(i,k)
17353 Tmpv301(i,k) =Tmpv002
17354 ! Remarked by Ning Pan, 2010-08-10
17355 ! Tmpv003 =Tmpv301(i,k)*rdzw(i,k,j)
17356 ! Tmpv004 =tendency(i,k,j) -Tmpv003
17357 ! tendency(i,k,j) =Tmpv004
17363 DO i =i_end, i_start, -1
17364 a_Tmpv4 =a_tendency(i,k,j)
17365 a_tendency(i,k,j) =0.0
17366 a_tendency(i,k,j) =a_tendency(i,k,j) +a_Tmpv4
17368 a_Tmpv2 =rdzw(i,k,j)*a_Tmpv3
17369 a_rdzw(i,k,j) =a_rdzw(i,k,j) +Tmpv301(i,k)*a_Tmpv3
17370 a_mu(i,j) =a_mu(i,j) +Tmpv300(i,k)*a_Tmpv2
17371 a_Tmpv1 =mu(i,j)*a_Tmpv2
17372 a_H3(i,k+1,j) =a_H3(i,k+1,j) +a_Tmpv1
17373 a_H3(i,k,j) =a_H3(i,k,j) -a_Tmpv1
17380 DO j =j_end, j_start, -1
17382 ! DO i =i_start, i_end
17385 ! H3(i,ktf+1,j) =0.
17389 DO i =i_end, i_start, -1
17390 a_H3(i,ktf+1,j) =0.0
17396 xkxavg = 0. ! Added by Ning Pan, 2010-08-10
17398 DO j =j_end, j_start, -1
17401 DO i =i_start, i_end
17402 Tmpv001 =fnm(k)*xkhv(i,k,j) +fnp(k)*xkhv(i,k-1,j)
17403 ! Revised by Ning Pan, 2010-08-10
17404 ! Tmpv300(i,k) =xkxavg(i,k,j)
17405 ! xkxavg(i,k,j) =Tmpv001
17406 xkxavg(i,k,j) =Tmpv001
17407 Tmpv300(i,k) =xkxavg(i,k,j)
17409 Tmpv001 =var(i,k,j) -var(i,k-1,j)
17410 Tmpv301(i,k) =Tmpv001
17411 Tmpv002 =-xkxavg(i,k,j)*Tmpv301(i,k)
17412 Tmpv302(i,k) =Tmpv002
17413 ! Remarked by Ning Pan, 2010-08-10
17414 ! Tmpv003 =Tmpv302(i,k)*rdz(i,k,j)
17415 ! H3(i,k,j) =Tmpv003
17420 DO k =ktf, kts+1, -1
17421 DO i =i_end, i_start, -1
17422 xkxavg(i,k,j) =Tmpv300(i,k) ! Added by Ning Pan, 2010-08-10
17423 a_Tmpv3 =a_H3(i,k,j)
17425 a_Tmpv2 =rdz(i,k,j)*a_Tmpv3
17426 a_rdz(i,k,j) =a_rdz(i,k,j) +Tmpv302(i,k)*a_Tmpv3
17427 a_xkxavg(i,k,j) =a_xkxavg(i,k,j) -Tmpv301(i,k)*a_Tmpv2
17428 a_Tmpv1 =-xkxavg(i,k,j)*a_Tmpv2
17429 a_var(i,k,j) =a_var(i,k,j) +a_Tmpv1
17430 a_var(i,k-1,j) =a_var(i,k-1,j) -a_Tmpv1
17432 ! xkxavg(i,k,j) =Tmpv300(i,k) ! Remarked by Ning Pan, 2010-08-10
17434 a_Tmpv1 =a_xkxavg(i,k,j)
17435 a_xkxavg(i,k,j) =0.0
17436 a_xkhv(i,k,j) =a_xkhv(i,k,j) +fnm(k)*a_Tmpv1
17437 a_xkhv(i,k-1,j) =a_xkhv(i,k-1,j) +fnp(k)*a_Tmpv1
17450 ! IF(doing_tke) THEN
17451 ! DO j =j_start, j_end
17453 ! DO i =i_start, i_end
17454 ! tmptendf(i,k,j) =tendency(i,k,j)
17463 DO j =j_end, j_start, -1
17465 DO i =i_end, i_start, -1
17466 a_tendency(i,k,j) =a_tendency(i,k,j) +a_tmptendf(i,k,j)
17467 a_tmptendf(i,k,j) =0.0
17478 ! IF( config_flags%periodic_x ) THEN
17479 ! i_end =min(ite, ide-1)
17482 ! IF( config_flags%periodic_x ) THEN
17490 ! IF( config_flags%periodic_x ) THEN
17494 ! IF( config_flags%periodic_x ) THEN
17502 ! IF( config_flags%open_ye .or. config_flags%specified .or. config_flags%nested) THEN
17503 ! j_end =min(jde-2, jte)
17506 ! IF( config_flags%open_ye .or. config_flags%specified .or. &
17507 ! config_flags%nested) THEN
17515 ! IF( config_flags%open_ys .or. config_flags%specified .or. config_flags%nested) THEN
17516 ! j_start =max(jds+1, jts)
17519 ! IF( config_flags%open_ys .or. config_flags%specified .or. &
17520 ! config_flags%nested) THEN
17528 ! IF( config_flags%open_xe .or. config_flags%specified .or. config_flags%nested) THEN
17529 ! i_end =min(ide-2, ite)
17532 ! IF( config_flags%open_xe .or. config_flags%specified .or. &
17533 ! config_flags%nested) THEN
17541 ! IF( config_flags%open_xs .or. config_flags%specified .or. config_flags%nested) THEN
17542 ! i_start =max(ids+1, its)
17545 ! IF( config_flags%open_xs .or. config_flags%specified .or. &
17546 ! config_flags%nested) THEN
17551 ! ktf =min(kte, kde-1)
17553 ! i_end =min(ite, ide-1)
17555 ! j_end =min(jte, jde-1)
17557 END SUBROUTINE a_vertical_diffusion_s
17559 SUBROUTINE a_cal_titau_11_22_33(config_flags,titau,a_titau,mu,a_mu,tke,a_tke, &
17560 xkx,a_xkx,defor,a_defor,mtau,a_mtau,rho,a_rho,is_ext,ie_ext,js_ext,je_ext,ids,ide,jds, &
17561 jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
17563 !PART I: DECLARATION OF VARIABLES
17567 INTEGER :: K0_ADJ,K1_ADJ,K2_ADJ,K3_ADJ
17568 TYPE(grid_config_rec_type) :: config_flags
17569 INTEGER :: ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte
17570 INTEGER :: is_ext,ie_ext,js_ext,je_ext
17571 REAL,DIMENSION(its-1:ite+1,kts:kte,jts-1:jte+1) :: titau,a_titau
17572 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: defor,a_defor,xkx,a_xkx,tke,a_tke
17573 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: mtau,a_mtau
17574 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: rho, a_rho
17575 REAL,DIMENSION(ims:ime,jms:jme) :: mu,a_mu
17576 INTEGER :: i,j,k,ktf,i_start,i_end,j_start,j_end
17578 ! REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: Keep_Lpb13_mtau
17579 INTEGER :: IX1,IX2,IX3
17581 REAL :: a_Tmpv1,Tmpv001,a_Tmpv2,Tmpv002
17582 ! Revised by Ning Pan, 2010-08-10
17583 ! REAL,DIMENSION(i_start-is_ext:i_end+ie_ext,kts:min(kte,kde-1),j_start-js_ext:j_end+ &
17584 ! je_ext) :: Tmpv400
17585 ! REAL,DIMENSION(i_start-is_ext:i_end+ie_ext,kts:min(kte,kde-1),j_start-js_ext:j_end+ &
17586 ! je_ext) :: Tmpv401
17587 ! REAL,DIMENSION(i_start-is_ext:i_end+ie_ext,kts:min(kte,kde-1),j_start-js_ext:j_end+ &
17588 ! je_ext) :: Tmpv402
17589 REAL,DIMENSION(its-1:ite+1,kts:kte,jts-1:jte+1) :: Tmpv400, Tmpv401, Tmpv402
17591 !PART II: CALCULATIONS OF B. S. TRAJECTORY
17595 ktf = MIN( kte, kde-1 )
17602 IF ( config_flags%open_xs .OR. config_flags%specified .OR. &
17603 config_flags%nested) i_start = MAX( ids+1, its )
17608 IF ( config_flags%open_xe .OR. config_flags%specified .OR. &
17609 config_flags%nested) i_end = MIN( ide-1, ite )
17614 IF ( config_flags%open_ys .OR. config_flags%specified .OR. &
17615 config_flags%nested) j_start = MAX( jds+1, jts )
17620 IF ( config_flags%open_ye .OR. config_flags%specified .OR. &
17621 config_flags%nested) j_end = MIN( jde-1, jte )
17626 IF ( config_flags%periodic_x ) i_start = its
17631 IF ( config_flags%periodic_x ) i_end = ite
17634 i_start = i_start - is_ext
17635 i_end = i_end + ie_ext
17636 j_start = j_start - js_ext
17637 j_end = j_end + je_ext
17643 ! ! Keep_Lpb13_mtau(IX1,IX2,IX3) =mtau(IX1,IX2,IX3)
17648 ! IF ( config_flags%sfs_opt .GT. 0 ) THEN
17650 ! DO j = j_start, j_end
17652 ! DO i = i_start, i_end
17653 ! titau(i,k,j) = mu(i,j) * mtau(i,k,j)
17658 ! IF ( config_flags%m_opt .EQ. 1 ) THEN
17660 ! DO j = j_start, j_end
17662 ! DO i = i_start, i_end
17663 ! titau(i,k,j) = - mu(i,j) * xkx(i,k,j) * defor(i,k,j)
17664 ! mtau(i,k,j) = - xkx(i,k,j) * defor(i,k,j)
17670 ! DO j = j_start, j_end
17672 ! DO i = i_start, i_end
17673 ! titau(i,k,j) = - mu(i,j) * xkx(i,k,j) * defor(i,k,j)
17681 !PART IV: REVERSE/BACKWARD ACCUMULATIONS
17687 ! mtau(IX1,IX2,IX3) =Keep_Lpb13_mtau(IX1,IX2,IX3)
17692 IF( config_flags%sfs_opt .GT. 0 ) THEN
17693 ! Remarked by Ning Pan, 2010-08-10
17694 ! DO j =j_start, j_end
17696 ! DO i =i_start, i_end
17697 ! Tmpv001 =mu(i,j)*mtau(i,k,j)
17698 ! titau(i,k,j) =Tmpv001
17704 IF( config_flags%m_opt .EQ. 1 ) THEN
17705 DO j =j_start, j_end
17707 DO i =i_start, i_end
17708 Tmpv001 =-mu(i,j)*xkx(i,k,j)
17709 Tmpv400(i,k,j) =Tmpv001
17710 ! Remarked by Ning Pan, 2010-08-10
17711 ! Tmpv002 =Tmpv400(i,k,j)*defor(i,k,j)
17712 ! titau(i,k,j) =Tmpv002
17714 ! Remarked by Ning Pan, 2010-08-10
17715 ! Tmpv001 =-xkx(i,k,j)*defor(i,k,j)
17716 ! Tmpv401(i,k,j) =mtau(i,k,j)
17717 ! mtau(i,k,j) =Tmpv001
17723 DO j =j_start, j_end
17725 DO i =i_start, i_end
17726 Tmpv001 =-mu(i,j)*xkx(i,k,j)
17727 Tmpv402(i,k,j) =Tmpv001
17728 ! Remarked by Ning Pan, 2010-08-10
17729 ! Tmpv002 =Tmpv402(i,k,j)*defor(i,k,j)
17730 ! titau(i,k,j) =Tmpv002
17738 IF( config_flags%sfs_opt .GT. 0 ) THEN
17740 DO j =j_end, j_start, -1
17742 DO i =i_end, i_start, -1
17743 a_Tmpv1 =a_titau(i,k,j)
17744 a_titau(i,k,j) =0.0
17745 a_mu(i,j) =a_mu(i,j) +mtau(i,k,j)*a_Tmpv1
17746 a_mtau(i,k,j) =a_mtau(i,k,j) +mu(i,j)*a_Tmpv1
17753 IF( config_flags%m_opt .EQ. 1 ) THEN
17755 DO j =j_end, j_start, -1
17757 DO i =i_end, i_start, -1
17759 ! mtau(i,k,j) =Tmpv401(i,k,j) ! Remarked by Ning Pan, 2010-08-10
17761 a_Tmpv1 =a_mtau(i,k,j)
17763 a_xkx(i,k,j) =a_xkx(i,k,j) -defor(i,k,j)*a_Tmpv1
17764 a_defor(i,k,j) =a_defor(i,k,j) -xkx(i,k,j)*a_Tmpv1
17765 a_Tmpv2 =a_titau(i,k,j)
17766 a_titau(i,k,j) =0.0
17767 a_Tmpv1 =defor(i,k,j)*a_Tmpv2
17768 a_defor(i,k,j) =a_defor(i,k,j) +Tmpv400(i,k,j)*a_Tmpv2
17769 a_mu(i,j) =a_mu(i,j) -xkx(i,k,j)*a_Tmpv1
17770 a_xkx(i,k,j) =a_xkx(i,k,j) -mu(i,j)*a_Tmpv1
17777 DO j =j_end, j_start, -1
17779 DO i =i_end, i_start, -1
17780 a_Tmpv2 =a_titau(i,k,j)
17781 a_titau(i,k,j) =0.0
17782 a_Tmpv1 =defor(i,k,j)*a_Tmpv2
17783 a_defor(i,k,j) =a_defor(i,k,j) +Tmpv402(i,k,j)*a_Tmpv2
17784 a_mu(i,j) =a_mu(i,j) -xkx(i,k,j)*a_Tmpv1
17785 a_xkx(i,k,j) =a_xkx(i,k,j) -mu(i,j)*a_Tmpv1
17795 ! i_start =i_start-is_ext
17796 ! i_end =i_end+ie_ext
17797 ! j_start =j_start-js_ext
17798 ! j_end =j_end+je_ext
17802 ! IF( config_flags%periodic_x ) THEN
17806 ! IF( config_flags%periodic_x ) THEN
17814 ! IF( config_flags%periodic_x ) THEN
17818 ! IF( config_flags%periodic_x ) THEN
17826 ! IF( config_flags%open_ye .OR. config_flags%specified .OR. config_flags%nested) THEN
17827 ! j_end =min(jde-1, jte)
17830 ! IF( config_flags%open_ye .OR. config_flags%specified .OR. &
17831 ! config_flags%nested) THEN
17839 ! IF( config_flags%open_ys .OR. config_flags%specified .OR. config_flags%nested) THEN
17840 ! j_start =max(jds+1, jts)
17843 ! IF( config_flags%open_ys .OR. config_flags%specified .OR. &
17844 ! config_flags%nested) THEN
17852 ! IF( config_flags%open_xe .OR. config_flags%specified .OR. config_flags%nested) THEN
17853 ! i_end =min(ide-1, ite)
17856 ! IF( config_flags%open_xe .OR. config_flags%specified .OR. &
17857 ! config_flags%nested) THEN
17865 ! IF( config_flags%open_xs .OR. config_flags%specified .OR. config_flags%nested) THEN
17866 ! i_start =max(ids+1, its)
17869 ! IF( config_flags%open_xs .OR. config_flags%specified .OR. &
17870 ! config_flags%nested) THEN
17875 ! ktf =min(kte, kde-1)
17881 END SUBROUTINE a_cal_titau_11_22_33
17883 SUBROUTINE a_cal_titau_12_21(config_flags,titau,a_titau,mu,a_mu,xkx,a_xkx, &
17884 defor,a_defor,mtau,a_mtau,rho,a_rho,is_ext,ie_ext,js_ext,je_ext,ids,ide,jds,jde,kds,kde, &
17885 ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
17887 !PART I: DECLARATION OF VARIABLES
17891 INTEGER :: K0_ADJ,K1_ADJ,K2_ADJ,K3_ADJ
17892 TYPE(grid_config_rec_type) :: config_flags
17893 INTEGER :: ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte
17894 INTEGER :: is_ext,ie_ext,js_ext,je_ext
17895 REAL,DIMENSION(its-1:ite+1,kts:kte,jts-1:jte+1) :: titau,a_titau
17896 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: defor,a_defor,xkx,a_xkx
17897 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: mtau,a_mtau
17898 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: rho, a_rho
17899 REAL,DIMENSION(ims:ime,jms:jme) :: mu,a_mu
17900 INTEGER :: i,j,k,ktf,i_start,i_end,j_start,j_end
17901 REAL,DIMENSION(its-1:ite+1,kts:kte,jts-1:jte+1) :: xkxavg,a_xkxavg
17902 REAL,DIMENSION(its-1:ite+1,jts-1:jte+1) :: muavg,a_muavg
17904 ! REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: Keep_Lpb16_mtau
17905 INTEGER :: IX1,IX2,IX3
17907 REAL :: a_Tmpv1,Tmpv001,a_Tmpv2,Tmpv002,a_Tmpv3,Tmpv003,a_Tmpv4,Tmpv004
17908 ! Revised by Ning Pan, 2010-08-10
17909 ! REAL,DIMENSION(i_start-is_ext:i_end+ie_ext,kts:min(kte,kde-1),j_start-js_ext:j_end+ &
17910 ! je_ext) :: Tmpv400
17911 ! REAL,DIMENSION(i_start-is_ext:i_end+ie_ext,kts:min(kte,kde-1),j_start-js_ext:j_end+ &
17912 ! je_ext) :: Tmpv401
17913 ! REAL,DIMENSION(i_start-is_ext:i_end+ie_ext,kts:min(kte,kde-1),j_start-js_ext:j_end+ &
17914 ! je_ext) :: Tmpv402
17915 REAL,DIMENSION(its-1:ite+1,kts:kte,jts-1:jte+1) :: Tmpv400, Tmpv401, Tmpv402
17917 !PART II: CALCULATIONS OF B. S. TRAJECTORY
17921 ktf = MIN( kte, kde-1 )
17928 IF ( config_flags%open_xs .OR. config_flags%specified .OR. &
17929 config_flags%nested ) i_start = MAX( ids+1, its )
17934 IF ( config_flags%open_xe .OR. config_flags%specified .OR. &
17935 config_flags%nested ) i_end = MIN( ide-1, ite )
17940 IF ( config_flags%open_ys .OR. config_flags%specified .OR. &
17941 config_flags%nested ) j_start = MAX( jds+1, jts )
17946 IF ( config_flags%open_ye .OR. config_flags%specified .OR. &
17947 config_flags%nested ) j_end = MIN( jde-1, jte )
17952 IF ( config_flags%periodic_x ) i_start = its
17957 IF ( config_flags%periodic_x ) i_end = ite
17960 i_start = i_start - is_ext
17961 i_end = i_end + ie_ext
17962 j_start = j_start - js_ext
17963 j_end = j_end + je_ext
17966 DO j = j_start, j_end
17969 DO i = i_start, i_end
17970 xkxavg(i,k,j) = 0.25 * ( xkx(i-1,k,j ) + xkx(i,k,j ) + &
17971 xkx(i-1,k,j-1) + xkx(i,k,j-1) )
17978 DO j = j_start, j_end
17980 DO i = i_start, i_end
17981 muavg(i,j) = 0.25 * ( mu(i-1,j ) + mu(i,j ) + &
17982 mu(i-1,j-1) + mu(i,j-1) )
17993 ! ! Keep_Lpb16_mtau(IX1,IX2,IX3) =mtau(IX1,IX2,IX3)
17998 ! IF ( config_flags%sfs_opt .GT. 0 ) THEN
18000 ! DO j = j_start, j_end
18002 ! DO i = i_start, i_end
18003 ! titau(i,k,j) = muavg(i,j) * mtau(i,k,j)
18008 ! IF ( config_flags%m_opt .EQ. 1 ) THEN
18010 ! DO j = j_start, j_end
18012 ! DO i = i_start, i_end
18013 ! titau(i,k,j) = - muavg(i,j) * xkxavg(i,k,j) * defor(i,k,j)
18014 ! mtau(i,k,j) = - xkxavg(i,k,j) * defor(i,k,j)
18020 ! DO j = j_start, j_end
18022 ! DO i = i_start, i_end
18023 ! titau(i,k,j) = - muavg(i,j) * xkxavg(i,k,j) * defor(i,k,j)
18031 !PART III: INITIALIZATION OF LOCAL ADJOINT PERTURBATIONS
18033 Do K2_ADJ =jts-1, jte+1
18034 Do K1_ADJ =kts, kte
18035 Do K0_ADJ =its-1, ite+1
18036 a_xkxavg(K0_ADJ,K1_ADJ,K2_ADJ) =0.0
18041 Do K1_ADJ =jts-1, jte+1
18042 Do K0_ADJ =its-1, ite+1
18043 a_muavg(K0_ADJ,K1_ADJ) =0.0
18047 !PART IV: REVERSE/BACKWARD ACCUMULATIONS
18053 ! mtau(IX1,IX2,IX3) =Keep_Lpb16_mtau(IX1,IX2,IX3)
18058 IF( config_flags%sfs_opt .GT. 0 ) THEN
18059 ! Remarked by Ning Pan, 2010-08-10
18060 ! DO j =j_start, j_end
18062 ! DO i =i_start, i_end
18063 ! Tmpv001 =muavg(i,j)*mtau(i,k,j)
18064 ! titau(i,k,j) =Tmpv001
18070 IF( config_flags%m_opt .EQ. 1 ) THEN
18071 DO j =j_start, j_end
18073 DO i =i_start, i_end
18074 Tmpv001 =-muavg(i,j)*xkxavg(i,k,j)
18075 Tmpv400(i,k,j) =Tmpv001
18076 ! Remarked by Ning Pan, 2010-08-10
18077 ! Tmpv002 =Tmpv400(i,k,j)*defor(i,k,j)
18078 ! titau(i,k,j) =Tmpv002
18080 ! Remarked by Ning Pan, 2010-08-10
18081 ! Tmpv001 =-xkxavg(i,k,j)*defor(i,k,j)
18082 ! Tmpv401(i,k,j) =mtau(i,k,j)
18083 ! mtau(i,k,j) =Tmpv001
18089 DO j =j_start, j_end
18091 DO i =i_start, i_end
18092 Tmpv001 =-muavg(i,j)*xkxavg(i,k,j)
18093 Tmpv402(i,k,j) =Tmpv001
18094 ! Remarked by Ning Pan, 2010-08-10
18095 ! Tmpv002 =Tmpv402(i,k,j)*defor(i,k,j)
18096 ! titau(i,k,j) =Tmpv002
18104 IF( config_flags%sfs_opt .GT. 0 ) THEN
18106 DO j =j_end, j_start, -1
18108 DO i =i_end, i_start, -1
18109 a_Tmpv1 =a_titau(i,k,j)
18110 a_titau(i,k,j) =0.0
18111 a_muavg(i,j) =a_muavg(i,j) +mtau(i,k,j)*a_Tmpv1
18112 a_mtau(i,k,j) =a_mtau(i,k,j) +muavg(i,j)*a_Tmpv1
18119 IF( config_flags%m_opt .EQ. 1 ) THEN
18121 DO j =j_end, j_start, -1
18123 DO i =i_end, i_start, -1
18125 ! mtau(i,k,j) =Tmpv401(i,k,j) ! Remarked by Ning Pan, 2010-08-10
18127 a_Tmpv1 =a_mtau(i,k,j)
18129 a_xkxavg(i,k,j) =a_xkxavg(i,k,j) -defor(i,k,j)*a_Tmpv1
18130 a_defor(i,k,j) =a_defor(i,k,j) -xkxavg(i,k,j)*a_Tmpv1
18131 a_Tmpv2 =a_titau(i,k,j)
18132 a_titau(i,k,j) =0.0
18133 a_Tmpv1 =defor(i,k,j)*a_Tmpv2
18134 a_defor(i,k,j) =a_defor(i,k,j) +Tmpv400(i,k,j)*a_Tmpv2
18135 a_muavg(i,j) =a_muavg(i,j) -xkxavg(i,k,j)*a_Tmpv1
18136 a_xkxavg(i,k,j) =a_xkxavg(i,k,j) -muavg(i,j)*a_Tmpv1
18143 DO j =j_end, j_start, -1
18145 DO i =i_end, i_start, -1
18146 a_Tmpv2 =a_titau(i,k,j)
18147 a_titau(i,k,j) =0.0
18148 a_Tmpv1 =defor(i,k,j)*a_Tmpv2
18149 a_defor(i,k,j) =a_defor(i,k,j) +Tmpv402(i,k,j)*a_Tmpv2
18150 a_muavg(i,j) =a_muavg(i,j) -xkxavg(i,k,j)*a_Tmpv1
18151 a_xkxavg(i,k,j) =a_xkxavg(i,k,j) -muavg(i,j)*a_Tmpv1
18163 DO j =j_end, j_start, -1
18165 ! DO i =i_start, i_end
18166 ! Tmpv001 =mu(i-1,j) +mu(i,j)
18167 ! Tmpv002 =Tmpv001 +mu(i-1,j-1)
18168 ! Tmpv003 =Tmpv002 +mu(i,j-1)
18169 ! Tmpv004 =0.25*Tmpv003
18170 ! muavg(i,j) =Tmpv004
18174 DO i =i_end, i_start, -1
18175 a_Tmpv4 =a_muavg(i,j)
18177 a_Tmpv3 =0.25*a_Tmpv4
18179 a_mu(i,j-1) =a_mu(i,j-1) +a_Tmpv3
18181 a_mu(i-1,j-1) =a_mu(i-1,j-1) +a_Tmpv2
18182 a_mu(i-1,j) =a_mu(i-1,j) +a_Tmpv1
18183 a_mu(i,j) =a_mu(i,j) +a_Tmpv1
18189 DO j =j_end, j_start, -1
18192 ! DO i =i_start, i_end
18193 ! Tmpv001 =xkx(i-1,k,j) +xkx(i,k,j)
18194 ! Tmpv002 =Tmpv001 +xkx(i-1,k,j-1)
18195 ! Tmpv003 =Tmpv002 +xkx(i,k,j-1)
18196 ! Tmpv004 =0.25*Tmpv003
18197 ! xkxavg(i,k,j) =Tmpv004
18203 DO i =i_end, i_start, -1
18204 a_Tmpv4 =a_xkxavg(i,k,j)
18205 a_xkxavg(i,k,j) =0.0
18206 a_Tmpv3 =0.25*a_Tmpv4
18208 a_xkx(i,k,j-1) =a_xkx(i,k,j-1) +a_Tmpv3
18210 a_xkx(i-1,k,j-1) =a_xkx(i-1,k,j-1) +a_Tmpv2
18211 a_xkx(i-1,k,j) =a_xkx(i-1,k,j) +a_Tmpv1
18212 a_xkx(i,k,j) =a_xkx(i,k,j) +a_Tmpv1
18219 ! i_start =i_start-is_ext
18220 ! i_end =i_end+ie_ext
18221 ! j_start =j_start-js_ext
18222 ! j_end =j_end+je_ext
18226 ! IF( config_flags%periodic_x ) THEN
18230 ! IF( config_flags%periodic_x ) THEN
18238 ! IF( config_flags%periodic_x ) THEN
18242 ! IF( config_flags%periodic_x ) THEN
18250 ! IF( config_flags%open_ye .OR. config_flags%specified .OR. config_flags%nested ) THEN
18251 ! j_end =min(jde-1, jte)
18254 ! IF( config_flags%open_ye .OR. config_flags%specified .OR. &
18255 ! config_flags%nested ) THEN
18263 ! IF( config_flags%open_ys .OR. config_flags%specified .OR. config_flags%nested ) THEN
18264 ! j_start =max(jds+1, jts)
18267 ! IF( config_flags%open_ys .OR. config_flags%specified .OR. &
18268 ! config_flags%nested ) THEN
18276 ! IF( config_flags%open_xe .OR. config_flags%specified .OR. config_flags%nested ) THEN
18277 ! i_end =min(ide-1, ite)
18280 ! IF( config_flags%open_xe .OR. config_flags%specified .OR. &
18281 ! config_flags%nested ) THEN
18289 ! IF( config_flags%open_xs .OR. config_flags%specified .OR. config_flags%nested ) THEN
18290 ! i_start =max(ids+1, its)
18293 ! IF( config_flags%open_xs .OR. config_flags%specified .OR. &
18294 ! config_flags%nested ) THEN
18299 ! ktf =min(kte, kde-1)
18305 END SUBROUTINE a_cal_titau_12_21
18307 SUBROUTINE a_cal_titau_13_31(config_flags,titau,a_titau,defor,a_defor,mtau, &
18308 a_mtau,mu,a_mu,xkx,a_xkx,fnm,fnp,rho,a_rho,is_ext,ie_ext,js_ext,je_ext,ids,ide,jds,jde, &
18309 kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
18311 !PART I: DECLARATION OF VARIABLES
18315 INTEGER :: K0_ADJ,K1_ADJ,K2_ADJ,K3_ADJ
18316 TYPE(grid_config_rec_type) :: config_flags
18317 INTEGER :: ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte
18318 INTEGER :: is_ext,ie_ext,js_ext,je_ext
18319 REAL,DIMENSION(kms:kme) :: fnm,fnp
18320 REAL,DIMENSION(its-1:ite+1,kts:kte,jts-1:jte+1) :: titau,a_titau
18321 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: defor,a_defor,xkx,a_xkx
18322 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: rho, a_rho
18323 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: mtau,a_mtau
18324 REAL,DIMENSION(ims:ime,jms:jme) :: mu,a_mu
18325 INTEGER :: i,j,k,ktf,i_start,i_end,j_start,j_end
18326 REAL,DIMENSION(its-1:ite+1,kts:kte,jts-1:jte+1) :: xkxavg,a_xkxavg
18327 REAL,DIMENSION(its-1:ite+1,jts-1:jte+1) :: muavg,a_muavg
18329 ! REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: Keep_Lpb16_mtau
18330 INTEGER :: IX1,IX2,IX3
18332 REAL :: a_Tmpv1,Tmpv001,a_Tmpv2,Tmpv002,a_Tmpv3,Tmpv003,a_Tmpv4,Tmpv004, &
18333 a_Tmpv5,Tmpv005,a_Tmpv6,Tmpv006
18334 ! Revised by Ning Pan, 2010-08-10
18335 ! REAL,DIMENSION(i_start-is_ext:i_end+ie_ext,kts+1:min(kte,kde-1),j_start-js_ext:j_end+ &
18336 ! je_ext) :: Tmpv400
18337 ! REAL,DIMENSION(i_start-is_ext:i_end+ie_ext,kts+1:min(kte,kde-1),j_start-js_ext:j_end+ &
18338 ! je_ext) :: Tmpv401
18339 ! REAL,DIMENSION(i_start-is_ext:i_end+ie_ext,kts+1:min(kte,kde-1),j_start-js_ext:j_end+ &
18340 ! je_ext) :: Tmpv402
18341 REAL,DIMENSION(its-1:ite+1,kts:kte,jts-1:jte+1) :: Tmpv400, Tmpv401, Tmpv402
18343 !PART II: CALCULATIONS OF B. S. TRAJECTORY
18347 ktf = MIN( kte, kde-1 )
18351 j_end = MIN( jte, jde-1 )
18354 IF ( config_flags%open_xs .OR. config_flags%specified .OR. &
18355 config_flags%nested) i_start = MAX( ids+1, its )
18360 IF ( config_flags%open_xe .OR. config_flags%specified .OR. &
18361 config_flags%nested) i_end = MIN( ide-1, ite )
18366 IF ( config_flags%open_ys .OR. config_flags%specified .OR. &
18367 config_flags%nested) j_start = MAX( jds+1, jts )
18372 IF ( config_flags%open_ye .OR. config_flags%specified .OR. &
18373 config_flags%nested) j_end = MIN( jde-2, jte )
18378 IF ( config_flags%periodic_x ) i_start = its
18383 IF ( config_flags%periodic_x ) i_end = ite
18386 i_start = i_start - is_ext
18387 i_end = i_end + ie_ext
18388 j_start = j_start - js_ext
18389 j_end = j_end + je_ext
18392 DO j = j_start, j_end
18395 DO i = i_start, i_end
18396 xkxavg(i,k,j) = 0.5 * ( fnm(k) * ( xkx(i,k ,j) + xkx(i-1,k ,j) ) + &
18397 fnp(k) * ( xkx(i,k-1,j) + xkx(i-1,k-1,j) ) )
18404 DO j = j_start, j_end
18406 DO i = i_start, i_end
18407 muavg(i,j) = 0.5 * ( mu(i,j) + mu(i-1,j) )
18418 ! ! Keep_Lpb16_mtau(IX1,IX2,IX3) =mtau(IX1,IX2,IX3)
18423 ! IF ( config_flags%sfs_opt .GT. 0 ) THEN
18425 ! DO j = j_start, j_end
18426 ! DO k = kts+1, ktf
18427 ! DO i = i_start, i_end
18428 ! titau(i,k,j) = muavg(i,j) * mtau(i,k,j)
18433 ! IF ( config_flags%m_opt .EQ. 1 ) THEN
18435 ! DO j = j_start, j_end
18436 ! DO k = kts+1, ktf
18437 ! DO i = i_start, i_end
18438 ! titau(i,k,j) = - muavg(i,j) * xkxavg(i,k,j) * defor(i,k,j)
18439 ! mtau(i,k,j) = - xkxavg(i,k,j) * defor(i,k,j)
18445 ! DO j = j_start, j_end
18446 ! DO k = kts+1, ktf
18447 ! DO i = i_start, i_end
18448 ! titau(i,k,j) = - muavg(i,j) * xkxavg(i,k,j) * defor(i,k,j)
18457 ! DO j = j_start, j_end
18460 ! DO i = i_start, i_end
18461 ! titau(i,kts ,j) = 0.0
18462 ! titau(i,ktf+1,j) = 0.0
18467 !PART III: INITIALIZATION OF LOCAL ADJOINT PERTURBATIONS
18469 Do K2_ADJ =jts-1, jte+1
18470 Do K1_ADJ =kts, kte
18471 Do K0_ADJ =its-1, ite+1
18472 a_xkxavg(K0_ADJ,K1_ADJ,K2_ADJ) =0.0
18477 Do K1_ADJ =jts-1, jte+1
18478 Do K0_ADJ =its-1, ite+1
18479 a_muavg(K0_ADJ,K1_ADJ) =0.0
18483 !PART IV: REVERSE/BACKWARD ACCUMULATIONS
18486 DO j =j_end, j_start, -1
18488 ! DO i =i_start, i_end
18489 ! titau(i,kts,j) =0.0
18491 ! titau(i,ktf+1,j) =0.0
18495 DO i =i_end, i_start, -1
18496 a_titau(i,ktf+1,j) =0.0
18497 a_titau(i,kts,j) =0.0
18506 ! mtau(IX1,IX2,IX3) =Keep_Lpb16_mtau(IX1,IX2,IX3)
18511 IF( config_flags%sfs_opt .GT. 0 ) THEN
18512 ! Remarked by Ning Pan, 2010-08-10
18513 ! DO j =j_start, j_end
18515 ! DO i =i_start, i_end
18516 ! Tmpv001 =muavg(i,j)*mtau(i,k,j)
18517 ! titau(i,k,j) =Tmpv001
18523 IF( config_flags%m_opt .EQ. 1 ) THEN
18524 DO j =j_start, j_end
18526 DO i =i_start, i_end
18527 Tmpv001 =-muavg(i,j)*xkxavg(i,k,j)
18528 Tmpv400(i,k,j) =Tmpv001
18529 ! Remarked by Ning Pan, 2010-08-10
18530 ! Tmpv002 =Tmpv400(i,k,j)*defor(i,k,j)
18531 ! titau(i,k,j) =Tmpv002
18533 ! Remarked by Ning Pan, 2010-08-10
18534 ! Tmpv001 =-xkxavg(i,k,j)*defor(i,k,j)
18535 ! Tmpv401(i,k,j) =mtau(i,k,j)
18536 ! mtau(i,k,j) =Tmpv001
18542 DO j =j_start, j_end
18544 DO i =i_start, i_end
18545 Tmpv001 =-muavg(i,j)*xkxavg(i,k,j)
18546 Tmpv402(i,k,j) =Tmpv001
18547 ! Remarked by Ning Pan, 2010-08-10
18548 ! Tmpv002 =Tmpv402(i,k,j)*defor(i,k,j)
18549 ! titau(i,k,j) =Tmpv002
18557 IF( config_flags%sfs_opt .GT. 0 ) THEN
18559 DO j =j_end, j_start, -1
18560 DO k =ktf, kts+1, -1
18561 DO i =i_end, i_start, -1
18562 a_Tmpv1 =a_titau(i,k,j)
18563 a_titau(i,k,j) =0.0
18564 a_muavg(i,j) =a_muavg(i,j) +mtau(i,k,j)*a_Tmpv1
18565 a_mtau(i,k,j) =a_mtau(i,k,j) +muavg(i,j)*a_Tmpv1
18572 IF( config_flags%m_opt .EQ. 1 ) THEN
18574 DO j =j_end, j_start, -1
18575 DO k =ktf, kts+1, -1
18576 DO i =i_end, i_start, -1
18578 ! mtau(i,k,j) =Tmpv401(i,k,j) ! Remarked by Ning Pan, 2010-08-10
18580 a_Tmpv1 =a_mtau(i,k,j)
18582 a_xkxavg(i,k,j) =a_xkxavg(i,k,j) -defor(i,k,j)*a_Tmpv1
18583 a_defor(i,k,j) =a_defor(i,k,j) -xkxavg(i,k,j)*a_Tmpv1
18584 a_Tmpv2 =a_titau(i,k,j)
18585 a_titau(i,k,j) =0.0
18586 a_Tmpv1 =defor(i,k,j)*a_Tmpv2
18587 a_defor(i,k,j) =a_defor(i,k,j) +Tmpv400(i,k,j)*a_Tmpv2
18588 a_muavg(i,j) =a_muavg(i,j) -xkxavg(i,k,j)*a_Tmpv1
18589 a_xkxavg(i,k,j) =a_xkxavg(i,k,j) -muavg(i,j)*a_Tmpv1
18596 DO j =j_end, j_start, -1
18597 DO k =ktf, kts+1, -1
18598 DO i =i_end, i_start, -1
18599 a_Tmpv2 =a_titau(i,k,j)
18600 a_titau(i,k,j) =0.0
18601 a_Tmpv1 =defor(i,k,j)*a_Tmpv2
18602 a_defor(i,k,j) =a_defor(i,k,j) +Tmpv402(i,k,j)*a_Tmpv2
18603 a_muavg(i,j) =a_muavg(i,j) -xkxavg(i,k,j)*a_Tmpv1
18604 a_xkxavg(i,k,j) =a_xkxavg(i,k,j) -muavg(i,j)*a_Tmpv1
18616 DO j =j_end, j_start, -1
18618 ! DO i =i_start, i_end
18619 ! Tmpv001 =mu(i,j) +mu(i-1,j)
18620 ! Tmpv002 =0.5*Tmpv001
18621 ! muavg(i,j) =Tmpv002
18625 DO i =i_end, i_start, -1
18626 a_Tmpv2 =a_muavg(i,j)
18628 a_Tmpv1 =0.5*a_Tmpv2
18629 a_mu(i,j) =a_mu(i,j) +a_Tmpv1
18630 a_mu(i-1,j) =a_mu(i-1,j) +a_Tmpv1
18636 DO j =j_end, j_start, -1
18639 ! DO i =i_start, i_end
18640 ! Tmpv001 =xkx(i,k,j) +xkx(i-1,k,j)
18641 ! Tmpv002 =fnm(k)*Tmpv001
18642 ! Tmpv003 =xkx(i,k-1,j) +xkx(i-1,k-1,j)
18643 ! Tmpv004 =fnp(k)*Tmpv003
18644 ! Tmpv005 =Tmpv002 +Tmpv004
18645 ! Tmpv006 =0.5*Tmpv005
18646 ! xkxavg(i,k,j) =Tmpv006
18651 DO k =ktf, kts+1, -1
18652 DO i =i_end, i_start, -1
18653 a_Tmpv6 =a_xkxavg(i,k,j)
18654 a_xkxavg(i,k,j) =0.0
18655 a_Tmpv5 =0.5*a_Tmpv6
18658 a_Tmpv3 =fnp(k)*a_Tmpv4
18659 a_xkx(i,k-1,j) =a_xkx(i,k-1,j) +a_Tmpv3
18660 a_xkx(i-1,k-1,j) =a_xkx(i-1,k-1,j) +a_Tmpv3
18661 a_Tmpv1 =fnm(k)*a_Tmpv2
18662 a_xkx(i,k,j) =a_xkx(i,k,j) +a_Tmpv1
18663 a_xkx(i-1,k,j) =a_xkx(i-1,k,j) +a_Tmpv1
18670 ! i_start =i_start-is_ext
18671 ! i_end =i_end+ie_ext
18672 ! j_start =j_start-js_ext
18673 ! j_end =j_end+je_ext
18677 ! IF( config_flags%periodic_x ) THEN
18681 ! IF( config_flags%periodic_x ) THEN
18689 ! IF( config_flags%periodic_x ) THEN
18693 ! IF( config_flags%periodic_x ) THEN
18701 ! IF( config_flags%open_ye .OR. config_flags%specified .OR. config_flags%nested) THEN
18702 ! j_end =min(jde-2, jte)
18705 ! IF( config_flags%open_ye .OR. config_flags%specified .OR. &
18706 ! config_flags%nested) THEN
18714 ! IF( config_flags%open_ys .OR. config_flags%specified .OR. config_flags%nested) THEN
18715 ! j_start =max(jds+1, jts)
18718 ! IF( config_flags%open_ys .OR. config_flags%specified .OR. &
18719 ! config_flags%nested) THEN
18727 ! IF( config_flags%open_xe .OR. config_flags%specified .OR. config_flags%nested) THEN
18728 ! i_end =min(ide-1, ite)
18731 ! IF( config_flags%open_xe .OR. config_flags%specified .OR. &
18732 ! config_flags%nested) THEN
18740 ! IF( config_flags%open_xs .OR. config_flags%specified .OR. config_flags%nested) THEN
18741 ! i_start =max(ids+1, its)
18744 ! IF( config_flags%open_xs .OR. config_flags%specified .OR. &
18745 ! config_flags%nested) THEN
18750 ! ktf =min(kte, kde-1)
18754 ! j_end =min(jte, jde-1)
18756 END SUBROUTINE a_cal_titau_13_31
18758 SUBROUTINE a_cal_titau_23_32(config_flags,titau,a_titau,defor,a_defor,mtau, &
18759 a_mtau,mu,a_mu,xkx,a_xkx,fnm,fnp,rho,a_rho,is_ext,ie_ext,js_ext,je_ext,ids,ide,jds,jde, &
18760 kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
18762 !PART I: DECLARATION OF VARIABLES
18766 INTEGER :: K0_ADJ,K1_ADJ,K2_ADJ,K3_ADJ
18767 TYPE(grid_config_rec_type) :: config_flags
18768 INTEGER :: ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte
18769 INTEGER :: is_ext,ie_ext,js_ext,je_ext
18770 REAL,DIMENSION(kms:kme) :: fnm,fnp
18771 REAL,DIMENSION(its-1:ite+1,kts:kte,jts-1:jte+1) :: titau,a_titau
18772 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: defor,a_defor,xkx,a_xkx
18773 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: rho, a_rho
18774 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: mtau,a_mtau
18775 REAL,DIMENSION(ims:ime,jms:jme) :: mu,a_mu
18776 INTEGER :: i,j,k,ktf,i_start,i_end,j_start,j_end
18777 REAL,DIMENSION(its-1:ite+1,kts:kte,jts-1:jte+1) :: xkxavg,a_xkxavg
18778 REAL,DIMENSION(its-1:ite+1,jts-1:jte+1) :: muavg,a_muavg
18780 ! REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: Keep_Lpb16_mtau
18781 INTEGER :: IX1,IX2,IX3
18783 REAL :: a_Tmpv1,Tmpv001,a_Tmpv2,Tmpv002,a_Tmpv3,Tmpv003,a_Tmpv4,Tmpv004, &
18784 a_Tmpv5,Tmpv005,a_Tmpv6,Tmpv006
18785 ! Revised by Ning Pan, 2010-08-10
18786 ! REAL,DIMENSION(i_start-is_ext:i_end+ie_ext,kts+1:min(kte,kde-1),j_start-js_ext:j_end+ &
18787 ! je_ext) :: Tmpv400
18788 ! REAL,DIMENSION(i_start-is_ext:i_end+ie_ext,kts+1:min(kte,kde-1),j_start-js_ext:j_end+ &
18789 ! je_ext) :: Tmpv401
18790 ! REAL,DIMENSION(i_start-is_ext:i_end+ie_ext,kts+1:min(kte,kde-1),j_start-js_ext:j_end+ &
18791 ! je_ext) :: Tmpv402
18792 REAL,DIMENSION(its-1:ite+1,kts:kte,jts-1:jte+1) :: Tmpv400, Tmpv401, Tmpv402
18794 !PART II: CALCULATIONS OF B. S. TRAJECTORY
18797 ktf = MIN( kte, kde-1 )
18799 i_end = MIN( ite, ide-1 )
18804 IF ( config_flags%open_xs .OR. config_flags%specified .OR. &
18805 config_flags%nested) i_start = MAX( ids+1, its )
18810 IF ( config_flags%open_xe .OR. config_flags%specified .OR. &
18811 config_flags%nested) i_end = MIN( ide-2, ite )
18816 IF ( config_flags%open_ys .OR. config_flags%specified .OR. &
18817 config_flags%nested) j_start = MAX( jds+1, jts )
18822 IF ( config_flags%open_ye .OR. config_flags%specified .OR. &
18823 config_flags%nested) j_end = MIN( jde-1, jte )
18828 IF ( config_flags%periodic_x ) i_start = its
18833 IF ( config_flags%periodic_x ) i_end = MIN( ite, ide-1 )
18836 i_start = i_start - is_ext
18837 i_end = i_end + ie_ext
18838 j_start = j_start - js_ext
18839 j_end = j_end + je_ext
18842 DO j = j_start, j_end
18845 DO i = i_start, i_end
18846 xkxavg(i,k,j) = 0.5 * ( fnm(k) * ( xkx(i,k ,j) + xkx(i,k ,j-1) ) + &
18847 fnp(k) * ( xkx(i,k-1,j) + xkx(i,k-1,j-1) ) )
18854 DO j = j_start, j_end
18856 DO i = i_start, i_end
18857 muavg(i,j) = 0.5 * ( mu(i,j) + mu(i,j-1) )
18868 ! ! Keep_Lpb16_mtau(IX1,IX2,IX3) =mtau(IX1,IX2,IX3)
18873 ! IF ( config_flags%sfs_opt .EQ. 1 ) THEN
18875 ! DO j = j_start, j_end
18876 ! DO k = kts+1, ktf
18877 ! DO i = i_start, i_end
18878 ! titau(i,k,j) = muavg(i,j) * mtau(i,k,j)
18883 ! IF ( config_flags%m_opt .EQ. 1 ) THEN
18885 ! DO j = j_start, j_end
18886 ! DO k = kts+1, ktf
18887 ! DO i = i_start, i_end
18888 ! titau(i,k,j) = - muavg(i,j) * xkxavg(i,k,j) * defor(i,k,j)
18889 ! mtau(i,k,j) = - xkxavg(i,k,j) * defor(i,k,j)
18895 ! DO j = j_start, j_end
18896 ! DO k = kts+1, ktf
18897 ! DO i = i_start, i_end
18898 ! titau(i,k,j) = - muavg(i,j) * xkxavg(i,k,j) * defor(i,k,j)
18907 ! DO j = j_start, j_end
18910 ! DO i = i_start, i_end
18911 ! titau(i,kts ,j) = 0.0
18912 ! titau(i,ktf+1,j) = 0.0
18917 !PART III: INITIALIZATION OF LOCAL ADJOINT PERTURBATIONS
18919 Do K2_ADJ =jts-1, jte+1
18920 Do K1_ADJ =kts, kte
18921 Do K0_ADJ =its-1, ite+1
18922 a_xkxavg(K0_ADJ,K1_ADJ,K2_ADJ) =0.0
18927 Do K1_ADJ =jts-1, jte+1
18928 Do K0_ADJ =its-1, ite+1
18929 a_muavg(K0_ADJ,K1_ADJ) =0.0
18933 !PART IV: REVERSE/BACKWARD ACCUMULATIONS
18936 DO j =j_end, j_start, -1
18938 ! DO i =i_start, i_end
18939 ! titau(i,kts,j) =0.0
18941 ! titau(i,ktf+1,j) =0.0
18945 DO i =i_end, i_start, -1
18946 a_titau(i,ktf+1,j) =0.0
18947 a_titau(i,kts,j) =0.0
18956 ! mtau(IX1,IX2,IX3) =Keep_Lpb16_mtau(IX1,IX2,IX3)
18961 IF( config_flags%sfs_opt .EQ. 1 ) THEN
18962 ! Remarked by Ning Pan, 2010-08-10
18963 ! DO j =j_start, j_end
18965 ! DO i =i_start, i_end
18966 ! Tmpv001 =muavg(i,j)*mtau(i,k,j)
18967 ! titau(i,k,j) =Tmpv001
18973 IF( config_flags%m_opt .EQ. 1 ) THEN
18974 DO j =j_start, j_end
18976 DO i =i_start, i_end
18977 Tmpv001 =-muavg(i,j)*xkxavg(i,k,j)
18978 Tmpv400(i,k,j) =Tmpv001
18979 ! Remarked by Ning Pan, 2010-08-10
18980 ! Tmpv002 =Tmpv400(i,k,j)*defor(i,k,j)
18981 ! titau(i,k,j) =Tmpv002
18983 ! Remarked by Ning Pan, 2010-08-10
18984 ! Tmpv001 =-xkxavg(i,k,j)*defor(i,k,j)
18985 ! Tmpv401(i,k,j) =mtau(i,k,j)
18986 ! mtau(i,k,j) =Tmpv001
18992 DO j =j_start, j_end
18994 DO i =i_start, i_end
18995 Tmpv001 =-muavg(i,j)*xkxavg(i,k,j)
18996 Tmpv402(i,k,j) =Tmpv001
18997 ! Remarked by Ning Pan, 2010-08-10
18998 ! Tmpv002 =Tmpv402(i,k,j)*defor(i,k,j)
18999 ! titau(i,k,j) =Tmpv002
19007 IF( config_flags%sfs_opt .EQ. 1 ) THEN
19009 DO j =j_end, j_start, -1
19010 DO k =ktf, kts+1, -1
19011 DO i =i_end, i_start, -1
19012 a_Tmpv1 =a_titau(i,k,j)
19013 a_titau(i,k,j) =0.0
19014 a_muavg(i,j) =a_muavg(i,j) +mtau(i,k,j)*a_Tmpv1
19015 a_mtau(i,k,j) =a_mtau(i,k,j) +muavg(i,j)*a_Tmpv1
19022 IF( config_flags%m_opt .EQ. 1 ) THEN
19024 DO j =j_end, j_start, -1
19025 DO k =ktf, kts+1, -1
19026 DO i =i_end, i_start, -1
19028 ! mtau(i,k,j) =Tmpv401(i,k,j) ! Remarked by Ning Pan, 2010-08-10
19030 a_Tmpv1 =a_mtau(i,k,j)
19032 a_xkxavg(i,k,j) =a_xkxavg(i,k,j) -defor(i,k,j)*a_Tmpv1
19033 a_defor(i,k,j) =a_defor(i,k,j) -xkxavg(i,k,j)*a_Tmpv1
19034 a_Tmpv2 =a_titau(i,k,j)
19035 a_titau(i,k,j) =0.0
19036 a_Tmpv1 =defor(i,k,j)*a_Tmpv2
19037 a_defor(i,k,j) =a_defor(i,k,j) +Tmpv400(i,k,j)*a_Tmpv2
19038 a_muavg(i,j) =a_muavg(i,j) -xkxavg(i,k,j)*a_Tmpv1
19039 a_xkxavg(i,k,j) =a_xkxavg(i,k,j) -muavg(i,j)*a_Tmpv1
19046 DO j =j_end, j_start, -1
19047 DO k =ktf, kts+1, -1
19048 DO i =i_end, i_start, -1
19049 a_Tmpv2 =a_titau(i,k,j)
19050 a_titau(i,k,j) =0.0
19051 a_Tmpv1 =defor(i,k,j)*a_Tmpv2
19052 a_defor(i,k,j) =a_defor(i,k,j) +Tmpv402(i,k,j)*a_Tmpv2
19053 a_muavg(i,j) =a_muavg(i,j) -xkxavg(i,k,j)*a_Tmpv1
19054 a_xkxavg(i,k,j) =a_xkxavg(i,k,j) -muavg(i,j)*a_Tmpv1
19066 DO j =j_end, j_start, -1
19068 ! DO i =i_start, i_end
19069 ! Tmpv001 =mu(i,j) +mu(i,j-1)
19070 ! Tmpv002 =0.5*Tmpv001
19071 ! muavg(i,j) =Tmpv002
19075 DO i =i_end, i_start, -1
19076 a_Tmpv2 =a_muavg(i,j)
19078 a_Tmpv1 =0.5*a_Tmpv2
19079 a_mu(i,j) =a_mu(i,j) +a_Tmpv1
19080 a_mu(i,j-1) =a_mu(i,j-1) +a_Tmpv1
19086 DO j =j_end, j_start, -1
19089 ! DO i =i_start, i_end
19090 ! Tmpv001 =xkx(i,k,j) +xkx(i,k,j-1)
19091 ! Tmpv002 =fnm(k)*Tmpv001
19092 ! Tmpv003 =xkx(i,k-1,j) +xkx(i,k-1,j-1)
19093 ! Tmpv004 =fnp(k)*Tmpv003
19094 ! Tmpv005 =Tmpv002 +Tmpv004
19095 ! Tmpv006 =0.5*Tmpv005
19096 ! xkxavg(i,k,j) =Tmpv006
19101 DO k =ktf, kts+1, -1
19102 DO i =i_end, i_start, -1
19103 a_Tmpv6 =a_xkxavg(i,k,j)
19104 a_xkxavg(i,k,j) =0.0
19105 a_Tmpv5 =0.5*a_Tmpv6
19108 a_Tmpv3 =fnp(k)*a_Tmpv4
19109 a_xkx(i,k-1,j) =a_xkx(i,k-1,j) +a_Tmpv3
19110 a_xkx(i,k-1,j-1) =a_xkx(i,k-1,j-1) +a_Tmpv3
19111 a_Tmpv1 =fnm(k)*a_Tmpv2
19112 a_xkx(i,k,j) =a_xkx(i,k,j) +a_Tmpv1
19113 a_xkx(i,k,j-1) =a_xkx(i,k,j-1) +a_Tmpv1
19120 ! i_start =i_start-is_ext
19121 ! i_end =i_end+ie_ext
19122 ! j_start =j_start-js_ext
19123 ! j_end =j_end+je_ext
19127 ! IF( config_flags%periodic_x ) THEN
19128 ! i_end =min(ite, ide-1)
19131 ! IF( config_flags%periodic_x ) THEN
19139 ! IF( config_flags%periodic_x ) THEN
19143 ! IF( config_flags%periodic_x ) THEN
19151 ! IF( config_flags%open_ye .OR. config_flags%specified .OR. config_flags%nested) THEN
19152 ! j_end =min(jde-1, jte)
19155 ! IF( config_flags%open_ye .OR. config_flags%specified .OR. &
19156 ! config_flags%nested) THEN
19164 ! IF( config_flags%open_ys .OR. config_flags%specified .OR. config_flags%nested) THEN
19165 ! j_start =max(jds+1, jts)
19168 ! IF( config_flags%open_ys .OR. config_flags%specified .OR. &
19169 ! config_flags%nested) THEN
19177 ! IF( config_flags%open_xe .OR. config_flags%specified .OR. config_flags%nested) THEN
19178 ! i_end =min(ide-2, ite)
19181 ! IF( config_flags%open_xe .OR. config_flags%specified .OR. &
19182 ! config_flags%nested) THEN
19190 ! IF( config_flags%open_xs .OR. config_flags%specified .OR. config_flags%nested) THEN
19191 ! i_start =max(ids+1, its)
19194 ! IF( config_flags%open_xs .OR. config_flags%specified .OR. &
19195 ! config_flags%nested) THEN
19200 ! ktf =min(kte, kde-1)
19202 ! i_end =min(ite, ide-1)
19206 END SUBROUTINE a_cal_titau_23_32
19208 END MODULE a_module_diffusion_em