1 subroutine da_interpolate_regcoeff( kzs, kz, meanp_stats, meanp_xb, &
2 stats_regcoeff1, stats_regcoeff2, stats_regcoeff3, &
3 xb_regcoeff1, xb_regcoeff2, xb_regcoeff3 )
5 !------------------------------------------------------------------------------
6 ! PURPOSE: Interpolate statistical regression coefficient to new domain.
8 !------------------------------------------------------------------------------
12 integer, intent(in) :: kzs ! Number of levels in stats.
13 integer, intent(in) :: kz ! Number of levels in xb.
14 real, dimension(kzs), intent(in) :: meanp_stats ! Mean pressure on stats levs.
15 real, dimension(kz), intent(in) :: meanp_xb ! Mean pressure on xb levs.
16 real, dimension(kzs), intent(in) :: stats_regcoeff1, stats_regcoeff2
17 real, dimension(kzs,kzs), intent(in) :: stats_regcoeff3
18 real, dimension(kz), intent(out) :: xb_regcoeff1, xb_regcoeff2
19 real, dimension(kz,kz), intent(out) :: xb_regcoeff3
21 integer :: k1, k2, k, ks ! Loop counters.
22 integer :: ktrap_min, ktrap_max ! Max/min limits of xb rows.
24 integer :: k_above(1:kz)
27 !---------------------------------------------------------------------------
28 ! [1.0] Compare stats/xb levels and compute interpolation weights:
29 !---------------------------------------------------------------------------
35 if ( meanp_xb(k) <= meanp_stats(1) ) then
40 print*,' problem in determining ktrap_min'
45 if ( meanp_xb(k) >= meanp_stats(kzs) ) then
50 print*,' problem in determining ktrap_max'
54 do k = ktrap_min, ktrap_max
56 if ( meanp_xb(k) > meanp_stats(ks+1) .AND. &
57 meanp_xb(k) <= meanp_stats(ks) ) then
59 weight(k) = ( meanp_xb(k) - meanp_stats(ks+1) ) / &
60 ( meanp_stats(ks) - meanp_stats(ks+1) )
67 do k = 1, ktrap_min - 1
71 do k = ktrap_max + 1, kz
76 !---------------------------------------------------------------------------
77 ! [3.0] Interpolate regression coefficient from stats to xb levels:
78 !---------------------------------------------------------------------------
81 !print*,k1,' interpolating between ',k1s-1,k1s,' weights ',weight(k1),' stats ',stats_regcoeff1(k1s-1),stats_regcoeff1(k1s)
82 ! xb_regcoeff1(kz-k1+1) = &
84 (1.0-weight(k1)) * stats_regcoeff1(k1s) + &
85 weight(k1) * stats_regcoeff1(k1s-1)
86 ! xb_regcoeff2(kz-k1+1) = &
88 (1.0-weight(k1)) * stats_regcoeff2(k1s) + &
89 weight(k1) * stats_regcoeff2(k1s-1)
94 ! xb_regcoeff3(kz-k1+1,kz-k2+1) = &
95 xb_regcoeff3(k1,k2) = &
96 (1.0-weight(k1)) * (1.0-weight(k2)) * stats_regcoeff3(k1s,k2s) + &
97 weight(k1) * (1.0-weight(k2)) * stats_regcoeff3(k1s-1,k2s ) + &
98 (1.0-weight(k1)) * weight(k2) * stats_regcoeff3(k1s ,k2s-1) + &
99 weight(k1) * weight(k2) * stats_regcoeff3(k1s-1,k2s-1)
104 end subroutine da_interpolate_regcoeff