Merge remote-tracking branch 'origin/release-v4.6.1'
[WRF.git] / var / da / da_lightning / da_div_profile.inc
blob91111124331fa55e9ca98a3f331d39389f2af3b8
1 subroutine da_div_profile(grid, info, n, k, div)
3    !--------------------------------------------------------------------------
4    ! Purpose: Calculates divergence (div) on each level at the observed location (i,j). 
5    ! dx, dxm, dy, dym are horizontal interpolation weighting.
6    !                        d   U      d   V
7    !           Div = m^2 *[---(---) + ---(---) ] 
8    !                        dx  m      dy  m
9    ! Authors: Z Chen (zchen@fjnu.edu.cn), Jenny Sun (NCAR), X Qie (IAP)
10    !--------------------------------------------------------------------------
12    implicit none
14    type (domain),         intent(in)  :: grid
15    type (infa_type),      intent(in)  :: info
16    integer,               intent(in)  :: n, k
17    real,                  intent(out) :: div
18                           
19    integer :: ii, jj         ! index dimension.
20    real    :: div_m(2,2)     ! divergence
22    integer :: i, j      ! OBS location
23    real    :: dx, dxm   ! interpolation weights.
24    real    :: dy, dym   ! interpolation weights.
25    real    :: coeff  
26    if (trace_use_dull) call da_trace_entry("da_div_profile")
28    i   = info%i(1,n)
29    j   = info%j(1,n)
30    dx  = info%dx(1,n)
31    dy  = info%dy(1,n)
32    dxm = info%dxm(1,n)
33    dym = info%dym(1,n)
34    
35    if(i == its) i = its + 1
36    if(i == ite) i = ite - 1
37    if(j == jts) j = jts + 1
38    if(j == jte) j = jte - 1
39    ! calculate layered divergence
41    do ii = i, i+1
42       do jj = j, j+1      
43          coeff = grid%xb%map_factor(ii,jj) * grid%xb%map_factor(ii,jj)*0.5/grid%xb%ds
44                  
45          div_m(ii-i+1,jj-j+1) = (grid%xb%u(ii+1,jj,k)/grid%xb%map_factor(ii+1,jj) - &
46                                  grid%xb%u(ii-1,jj,k)/grid%xb%map_factor(ii-1,jj) + &
47                                  grid%xb%v(ii,jj+1,k)/grid%xb%map_factor(ii,jj+1) - &
48                                  grid%xb%v(ii,jj-1,k)/grid%xb%map_factor(ii,jj-1))*coeff         
49       end do
50    end do
52    ! Horizontal interpolation to the obs. pt.
53    div = dym*(dxm*div_m(1,1)+dx*div_m(2,1))+dy*(dxm*div_m(1,2)+dx*div_m(2,2))
55    if (trace_use_dull) call da_trace_exit("da_div_profile")
57 end subroutine da_div_profile