Merge remote-tracking branch 'origin/release-v4.6.1'
[WRF.git] / var / da / da_lightning / da_jo_and_grady_lightning.inc
blob5741a5714f5e286fc83c0fadec30c564d842952c
1 subroutine da_jo_and_grady_lightning(iv, re, jo, jo_grad_y)
3    !-----------------------------------------------------------------------
4    ! Purpose: TBD
5    ! Authors: Z Chen (zchen@fjnu.edu.cn), Jenny Sun (NCAR), X Qie (IAP) 
6    !-----------------------------------------------------------------------
8    implicit none
10    type (iv_type), intent(in)    :: iv          ! Innovation vector.
11    type (y_type),  intent(in)    :: re          ! Residual vector.
12    type (y_type),  intent(inout) :: jo_grad_y   ! Grad_y(Jo)
13    type (jo_type), intent(inout) :: jo          ! Obs cost function.
14    integer :: n, k
16    if (trace_use_dull) call da_trace_entry("da_jo_and_grady_lightning")
17    
18    ! defined in da_define_structure.f90
19    jo % lightning_w   = 0.0
20    jo % lightning_div = 0.0
21    jo % lightning_qv  = 0.0 
22   
23    do n = 1, iv%info(lightning)%nlocal
24       do k = 2, iv%info(lightning)%levels(n)
25          if(use_lightning_w) then
26            jo_grad_y%lightning(n)%w(k) = -re%lightning(n)%w(k)/(iv%lightning(n)%w(k)%error * iv%lightning(n)%w(k)%error)
27          end if
28                 
29          if(use_lightning_div) then
30            jo_grad_y%lightning(n)%div(k) = -re%lightning(n)%div(k)/(iv%lightning(n)%div(k)%error * iv%lightning(n)%div(k)%error)
31          end if
33          if(use_lightning_qv) then
34            jo_grad_y%lightning(n)%qv(k) = -re%lightning(n)%qv(k)/(iv%lightning(n)%qv(k)%error * iv%lightning(n)%qv(k)%error)
35          end if          
36       end do
38       if(iv%info(lightning)%proc_domain(1,n)) then
39         do k = 2, iv%info(lightning)%levels(n)
41            if(use_lightning_w) then
42              jo%lightning_w = jo%lightning_w-re%lightning(n)%w(k)*jo_grad_y%lightning(n)%w(k)
43            end if                           
45            if(use_lightning_div) then
46              jo%lightning_div = jo%lightning_div-re%lightning(n)%div(k) * jo_grad_y%lightning(n)%div(k)
47            end if                           
49            if(use_lightning_qv) then
50              jo%lightning_qv = jo%lightning_qv-re%lightning(n)%qv(k)*jo_grad_y%lightning(n)%qv(k)
51            end if               
53         end do
54       end if
55    
56    end do
58    jo%lightning_w   = 0.5 * jo % lightning_w
59    jo%lightning_div = 0.5 * jo % lightning_div
60    jo%lightning_qv  = 0.5 * jo % lightning_qv
62    if (trace_use_dull) call da_trace_exit("da_jo_and_grady_lightning")
64 end subroutine da_jo_and_grady_lightning