1 subroutine da_find_layer_adj (layer,tv,pre,pre_ma,tv_ma,ks,ke,ADJ_tv,ADJ_pre_ma,ADJ_tv_ma)
3 !-----------------------------------------------------------------------
4 ! Purpose: adjoint routine for da_find_layer
5 !-----------------------------------------------------------------------
9 integer, intent(in) :: ks, ke
10 integer, intent(out) :: layer
11 real, intent(in) :: pre_ma(ks-1:ke+1)
12 real, intent(in) :: tv_ma(ks-1:ke+1)
13 real, intent(inout) :: ADJ_pre_ma(ks-1:ke+1)
14 real, intent(inout) :: ADJ_tv_ma(ks-1:ke+1)
15 real, intent(in) :: pre, tv
16 real, intent(inout) :: ADJ_tv
19 real :: alpha, coef1, coef2
22 if (trace_use_frequent) call da_trace_entry("da_find_layer_adj")
24 if (pre >= pre_ma(ks)) then
26 coef1=log(pre/pre_ma(ks+1))/(pre_ma(ks)* &
27 (log(pre_ma(ks)/pre_ma(ks+1)))**2)
28 coef2=log(pre_ma(ks)/pre)/(pre_ma(ks+1)* &
29 (log(pre_ma(ks)/pre_ma(ks+1)))**2)
30 alpha = log(pre_ma(ks)/pre)/log(pre_ma(ks)/pre_ma(ks+1))
33 ADJ_tv_ma(ks) = ADJ_tv_ma(ks) + (1.0-alpha)*ADJ_tv
34 ADJ_alpha = (tv_ma(ks+1)-tv_ma(ks))*ADJ_tv
35 ADJ_tv_ma(ks+1) = ADJ_tv_ma(ks+1) + alpha*ADJ_tv
37 ADJ_pre_ma(ks) = ADJ_pre_ma(ks) + coef1 * ADJ_alpha
38 ADJ_pre_ma(ks+1) = ADJ_pre_ma(ks+1) + coef2 * ADJ_alpha
39 else if (pre <= pre_ma(ke)) then
41 coef1=log(pre/pre_ma(ke))/(pre_ma(ke-1)* &
42 (log(pre_ma(ke-1)/pre_ma(ke)))**2)
43 coef2=log(pre_ma(ke-1)/pre)/(pre_ma(ke)* &
44 (log(pre_ma(ke-1)/pre_ma(ke)))**2)
45 alpha = log(pre_ma(ke-1)/pre)/log(pre_ma(ke-1)/pre_ma(ke))
47 ADJ_pre_ma(ke+1) = 0.0
48 ADJ_tv_ma(ke-1) = ADJ_tv_ma(ke-1) + (1.0-alpha)*ADJ_tv
49 ADJ_alpha = (tv_ma(ke)-tv_ma(ke-1))*ADJ_tv
50 ADJ_tv_ma(ke) = ADJ_tv_ma(ke) + alpha*ADJ_tv
52 ADJ_pre_ma(ke-1) = ADJ_pre_ma(ke-1) + coef1 * ADJ_alpha
53 ADJ_pre_ma(ke) = ADJ_pre_ma(ke) + coef2 * ADJ_alpha
56 if (pre>=pre_ma(k+1) .and. pre<pre_ma(k)) then
58 coef1=log(pre/pre_ma(k+1))/(pre_ma(k)* &
59 (log(pre_ma(k)/pre_ma(k+1)))**2)
60 coef2=log(pre_ma(k)/pre)/(pre_ma(k+1)* &
61 (log(pre_ma(k)/pre_ma(k+1)))**2)
62 alpha = log(pre_ma(k)/pre)/log(pre_ma(k)/pre_ma(k+1))
64 ADJ_tv_ma(k) = ADJ_tv_ma(k) + (1.0-alpha)*ADJ_tv
65 ADJ_alpha = (tv_ma(k+1)-tv_ma(k))*ADJ_tv
66 ADJ_tv_ma(k+1) = ADJ_tv_ma(k+1) + alpha * ADJ_tv
68 ADJ_pre_ma(k) = ADJ_pre_ma(k) + coef1 * ADJ_alpha
69 ADJ_pre_ma(k+1) = ADJ_pre_ma(k+1) + coef2 * ADJ_alpha
77 if (trace_use_frequent) call da_trace_exit("da_find_layer_adj")
79 end subroutine da_find_layer_adj