1 subroutine da_interpolate_regcoeff (iy, iys, kz, kzs, meanl_stats, meanl_xb, meanp_stats, meanp_xb, &
2 pb_vert_reg_stats, pb_vert_reg)
4 !---------------------------------------------------------------------------
5 ! Purpose: Interpolate statistical regression coefficient to new domain.
7 ! Method: i,k,k Interpolation.
8 !---------------------------------------------------------------------------
12 integer, intent(in) :: iy ! Number of rows in xb.
13 integer, intent(in) :: iys ! Number of rows in stats.
14 integer, intent(in) :: kz ! Number of levels in xb.
15 integer, intent(in) :: kzs ! Number of levels in stats.
16 real, intent(in) :: meanl_stats(:) ! Mean latitude on stats rows.
17 real, intent(in) :: meanl_xb(:) ! Mean latitude on xb rows.
18 real, intent(in) :: meanp_stats(:) ! Mean pressure on stats levs.
19 real, intent(in) :: meanp_xb(:) ! Mean pressure on xb levs.
20 real*8, intent(in) :: pb_vert_reg_stats(:,:,:) ! Coefficient on stats grid.
21 real*8, intent(out) :: pb_vert_reg(:,:,:) ! Coefficient on xb grid.
23 integer :: i, is, i_south ! Loop counters.
24 integer :: k1, k2, k, ks ! Loop counters.
28 integer :: k_above(1:kz)
29 real :: pb_vert_reg_temp(1:iys,1:kz,1:kz)
32 if (trace_use) call da_trace_entry("da_interpolate_regcoeff")
36 !------------------------------------------------------------------------
37 ! [1.0] Find xb levels/rows bounded by stats domain:
38 !------------------------------------------------------------------------
41 if (meanp_xb(k) <= meanp_stats(1)) then
44 else if (meanp_xb(k) >= meanp_stats(kzs)) then
45 weight(k) = 1.0-1.0e-6
49 if (meanp_xb(k) >= meanp_stats(ks) .AND. meanp_xb(k) <= meanp_stats(ks+1)) then
50 weight(k) = (meanp_xb(k) - meanp_stats(ks)) / (meanp_stats(ks+1) - meanp_stats(ks))
58 !------------------------------------------------------------------------
59 ! [3.0] Interpolate regression coefficient from stats to xb levels:
60 !------------------------------------------------------------------------
62 pb_vert_reg_temp(1:iys,1:kz,1:kz) = 0.0
70 pb_vert_reg_temp(is,k1,k2) = (1.0-weight(k1)) * (1.0-weight(k2)) * &
71 pb_vert_reg_stats(is,k1s,k2s) + &
72 weight(k1) * (1.0-weight(k2)) * &
73 pb_vert_reg_stats(is,k1s+1,k2s) + &
74 weight(k2) * (1.0-weight(k1)) * &
75 pb_vert_reg_stats(is,k1s,k2s+1) + &
76 weight(k2) * weight(k1) * &
77 pb_vert_reg_stats(is,k1s+1,k2s+1)
82 !------------------------------------------------------------------------
83 ! [4.0] Interpolate to from statistics latitudes to xb latitudes:
84 !------------------------------------------------------------------------
90 ! Find position of xb latitude in statistics rows:
92 if (meanl_xb(i) <= meanl_stats(2)) then
95 else if (meanl_xb(i) >= meanl_stats(iys-1)) then
100 if (meanl_xb(i) >= meanl_stats(is) .AND. meanl_xb(i) <= meanl_stats(is+1)) then
102 lat_wgt = (meanl_xb(i) - meanl_stats(is)) / (meanl_stats(is+1) - meanl_stats(is))
111 pb_vert_reg(i,k1,k2) = lat_wgt * pb_vert_reg_temp(i_south+1,k1,k2) + &
112 (1.0 - lat_wgt) * pb_vert_reg_temp(i_south,k1,k2)
117 if (print_detail_regression) then
118 call da_array_print(1, pb_vert_reg_stats(1,:,:), 'pb_vert_reg_stats(1,:,:)')
119 call da_array_print(1, pb_vert_reg(1,:,:), 'pb_vert_reg(1,:,:)')
120 call da_array_print(1, pb_vert_reg_stats(:,1,:), 'pb_vert_reg_stats(:,1,:)')
121 call da_array_print(1, pb_vert_reg(:,1,:), 'pb_vert_reg(:,1,:)')
124 if (trace_use) call da_trace_exit("da_interpolate_regcoeff")
126 end subroutine da_interpolate_regcoeff