67 '$Id: CRTM_Interpolation.f90 60152 2015-08-13 19:19:13Z paul.vandelst@noaa.gov $' 68 REAL(fp),
PARAMETER ::
zero = 0.0_fp
69 REAL(fp),
PARAMETER ::
one = 1.0_fp
154 WRITE(*,
'(1x,"LPoly OBJECT")')
155 WRITE(*,
'(3x,"Order : ",i0)') self%Order
156 WRITE(*,
'(3x,"nPts : ",i0)') self%nPts
157 WRITE(*,
'(3x,"Left-side :")')
158 WRITE(*,
'(5x,"Weighting factor : ",es13.6)') self%w_left
159 WRITE(*,
'(5x,"Polynomial :")')
160 WRITE(*,
'(5(1x,es13.6,:))') self%lp_left
161 WRITE(*,
'(5x,"Numerator differences :")')
162 WRITE(*,
'(5(1x,es13.6,:))') self%dxi_left
163 WRITE(*,
'(5x,"Denominator differences :")')
164 WRITE(*,
'(5(1x,es13.6,:))') self%dx_left
165 WRITE(*,
'(3x,"Right-side :")')
166 WRITE(*,
'(5x,"Weighting factor : ",es13.6)') self%w_right
167 WRITE(*,
'(5x,"Polynomial :")')
168 WRITE(*,
'(5(1x,es13.6,:))') self%lp_right
169 WRITE(*,
'(5x,"Numerator differences :")')
170 WRITE(*,
'(5(1x,es13.6,:))') self%dxi_right
171 WRITE(*,
'(5x,"Denominator differences :")')
172 WRITE(*,
'(5(1x,es13.6,:))') self%dx_right
231 REAL(fp),
INTENT(IN) :: z(:)
233 REAL(fp),
INTENT(IN OUT) :: z_int
235 z_int = ( ulp%w_left * ( ulp%lp_left(1) *z(1) + &
236 ulp%lp_left(2) *z(2) + &
237 ulp%lp_left(3) *z(3) ) ) + &
238 ( ulp%w_right * ( ulp%lp_right(1)*z(2) + &
239 ulp%lp_right(2)*z(3) + &
240 ulp%lp_right(3)*z(4) ) )
244 SUBROUTINE interp_2d(z, ulp, vlp, & ! Input
247 REAL(fp),
INTENT(IN) :: z(:,:)
249 REAL(fp),
INTENT(IN OUT) :: z_int
262 SUBROUTINE interp_3d(z, ulp, vlp, wlp, & ! Input
265 REAL(fp),
INTENT(IN) :: z(:,:,:)
267 REAL(fp),
INTENT(IN OUT) :: z_int
280 SUBROUTINE interp_4d(z, ulp, vlp, wlp, xlp, & ! Input
283 REAL(fp),
INTENT(IN) :: z(:,:,:,:)
284 TYPE(
lpoly_type),
INTENT(IN) :: ulp, vlp, wlp, xlp
285 REAL(fp),
INTENT(IN OUT) :: z_int
291 CALL interp_3d(z(:,:,:,i),ulp,vlp,wlp,a(i))
365 z_TL, ulp_TL, & ! TL Input
368 REAL(fp),
INTENT(IN) :: z(:)
370 REAL(fp),
INTENT(IN) :: z_tl(:)
372 REAL(fp),
INTENT(IN OUT) :: z_int_tl
374 z_int_tl = ( ulp%w_left * ( ulp%lp_left(1) * z_tl(1) + &
375 ulp_tl%lp_left(1) * z(1) + &
376 ulp%lp_left(2) * z_tl(2) + &
377 ulp_tl%lp_left(2) * z(2) + &
378 ulp%lp_left(3) * z_tl(3) + &
379 ulp_tl%lp_left(3) * z(3) ) ) + &
380 ( ulp_tl%w_left * ( ulp%lp_left(1) * z(1) + &
381 ulp%lp_left(2) * z(2) + &
382 ulp%lp_left(3) * z(3) ) ) + &
384 ( ulp%w_right * ( ulp%lp_right(1) * z_tl(2) + &
385 ulp_tl%lp_right(1) * z(2) + &
386 ulp%lp_right(2) * z_tl(3) + &
387 ulp_tl%lp_right(2) * z(3) + &
388 ulp%lp_right(3) * z_tl(4) + &
389 ulp_tl%lp_right(3) * z(4) ) ) + &
390 ( ulp_tl%w_right * ( ulp%lp_right(1) * z(2) + &
391 ulp%lp_right(2) * z(3) + &
392 ulp%lp_right(3) * z(4) ) )
398 z_TL, ulp_TL, vlp_TL, & ! TL Input
400 REAL(fp),
INTENT(IN) :: z(:,:)
402 REAL(fp),
INTENT(IN) :: z_tl(:,:)
403 TYPE(
lpoly_type),
INTENT(IN) :: ulp_tl, vlp_tl
404 REAL(fp),
INTENT(IN OUT) :: z_int_tl
418 SUBROUTINE interp_3d_tl( z , ulp , vlp , wlp , & ! FWD Input
419 z_TL, ulp_TL, vlp_TL, wlp_TL, & ! TL Input
422 REAL(fp),
INTENT(IN) :: z(:,:,:)
424 REAL(fp),
INTENT(IN) :: z_tl(:,:,:)
425 TYPE(
lpoly_type),
INTENT(IN) :: ulp_tl, vlp_tl, wlp_tl
426 REAL(fp),
INTENT(IN OUT) :: z_int_tl
433 CALL interp_2d_tl(z(:,:,i),ulp,vlp,z_tl(:,:,i),ulp_tl,vlp_tl,a_tl(i))
440 SUBROUTINE interp_4d_tl( z , ulp , vlp , wlp , xlp , & ! FWD Input
441 z_TL, ulp_TL, vlp_TL, wlp_TL, xlp_TL, & ! TL Input
444 REAL(fp),
INTENT(IN) :: z(:,:,:,:)
445 TYPE(
lpoly_type),
INTENT(IN) :: ulp, vlp, wlp, xlp
446 REAL(fp),
INTENT(IN) :: z_tl(:,:,:,:)
447 TYPE(
lpoly_type),
INTENT(IN) :: ulp_tl, vlp_tl, wlp_tl, xlp_tl
448 REAL(fp),
INTENT(IN OUT) :: z_int_tl
454 CALL interp_3d(z(:,:,:,i),ulp,vlp,wlp,a(i))
455 CALL interp_3d_tl(z(:,:,:,i),ulp,vlp,wlp,z_tl(:,:,:,i),ulp_tl,vlp_tl,wlp_tl,a_tl(i))
538 z_int_AD , & ! AD Input
541 REAL(fp),
INTENT(IN) :: z(:)
543 REAL(fp),
INTENT(IN OUT) :: z_int_ad
544 REAL(fp),
INTENT(IN OUT) :: z_ad(:)
547 REAL(fp) :: wl_z_int_ad, wr_z_int_ad
549 ulp_ad%w_right = ulp_ad%w_right + &
550 ( z_int_ad * ( ( ulp%lp_right(1) * z(2) ) + &
551 ( ulp%lp_right(2) * z(3) ) + &
552 ( ulp%lp_right(3) * z(4) ) ) )
554 ulp_ad%w_left = ulp_ad%w_left + &
555 ( z_int_ad * ( ( ulp%lp_left(1) * z(1) ) + &
556 ( ulp%lp_left(2) * z(2) ) + &
557 ( ulp%lp_left(3) * z(3) ) ) )
559 wr_z_int_ad = ulp%w_right * z_int_ad
560 ulp_ad%lp_right(1) = ulp_ad%lp_right(1) + ( wr_z_int_ad * z(2) )
561 ulp_ad%lp_right(2) = ulp_ad%lp_right(2) + ( wr_z_int_ad * z(3) )
562 ulp_ad%lp_right(3) = ulp_ad%lp_right(3) + ( wr_z_int_ad * z(4) )
564 wl_z_int_ad = ulp%w_left * z_int_ad
565 ulp_ad%lp_left(1) = ulp_ad%lp_left(1) + ( wl_z_int_ad * z(1) )
566 ulp_ad%lp_left(2) = ulp_ad%lp_left(2) + ( wl_z_int_ad * z(2) )
567 ulp_ad%lp_left(3) = ulp_ad%lp_left(3) + ( wl_z_int_ad * z(3) )
569 z_ad(1) = z_ad(1) + ( wl_z_int_ad * ulp%lp_left(1) )
571 z_ad(2) = z_ad(2) + ( wr_z_int_ad * ulp%lp_right(1) ) + &
572 ( wl_z_int_ad * ulp%lp_left(2) )
574 z_ad(3) = z_ad(3) + ( wr_z_int_ad * ulp%lp_right(2) ) + &
575 ( wl_z_int_ad * ulp%lp_left(3) )
577 z_ad(4) = z_ad(4) + ( wr_z_int_ad * ulp%lp_right(3) )
583 z_int_AD , & ! AD Input
584 z_AD, ulp_AD, vlp_AD )
586 REAL(fp),
INTENT(IN) :: z(:,:)
588 REAL(fp),
INTENT(IN OUT) :: z_int_ad
589 REAL(fp),
INTENT(IN OUT) :: z_ad(:,:)
590 TYPE(
lpoly_type),
INTENT(IN OUT) :: ulp_ad, vlp_ad
611 SUBROUTINE interp_3d_ad( z , ulp , vlp , wlp , & ! FWD Input
612 z_int_AD , & ! AD Input
613 z_AD, ulp_AD, vlp_AD, wlp_AD )
615 REAL(fp),
INTENT(IN) :: z(:,:,:)
617 REAL(fp),
INTENT(IN OUT) :: z_int_ad
618 REAL(fp),
INTENT(IN OUT) :: z_ad(:,:,:)
619 TYPE(
lpoly_type),
INTENT(IN OUT) :: ulp_ad, vlp_ad, wlp_ad
637 CALL interp_2d_ad(z(:,:,i),ulp,vlp,a_ad(i),z_ad(:,:,i),ulp_ad,vlp_ad)
642 SUBROUTINE interp_4d_ad( z , ulp , vlp , wlp , xlp , & ! FWD Input
643 z_int_AD , & ! AD Input
644 z_AD, ulp_AD, vlp_AD, wlp_AD, xlp_AD )
646 REAL(fp),
INTENT(IN) :: z(:,:,:,:)
647 TYPE(
lpoly_type),
INTENT(IN) :: ulp, vlp, wlp, xlp
648 REAL(fp),
INTENT(IN OUT) :: z_int_ad
649 REAL(fp),
INTENT(IN OUT) :: z_ad(:,:,:,:)
650 TYPE(
lpoly_type),
INTENT(IN OUT) :: ulp_ad, vlp_ad, wlp_ad, xlp_ad
658 CALL interp_3d(z(:,:,:,i),ulp,vlp,wlp,a(i))
668 CALL interp_3d_ad(z(:,:,:,i),ulp,vlp,wlp,a_ad(i),z_ad(:,:,:,i),ulp_ad,vlp_ad,wlp_ad)
749 REAL(fp),
INTENT(IN) :: x(:)
750 REAL(fp),
INTENT(IN) :: dx
751 REAL(fp),
INTENT(IN OUT) :: x_int
752 INTEGER ,
INTENT(IN OUT) :: i1, i2
753 LOGICAL ,
INTENT(IN OUT) :: out_of_bounds
756 out_of_bounds = .false.
757 IF ( x_int < x(1) .OR. x_int > x(n) ) out_of_bounds = .true.
758 i1 = floor((x_int-x(1))/dx)+1-(
npoly_pts/2)
761 IF (out_of_bounds .AND. i1==1)
THEN 763 ELSE IF (out_of_bounds .AND. i2==n)
THEN 772 REAL(fp),
INTENT(IN) :: x(:)
773 REAL(fp),
INTENT(IN OUT) :: x_int
774 INTEGER ,
INTENT(IN OUT) :: i1, i2
775 LOGICAL ,
INTENT(IN OUT) :: out_of_bounds
778 out_of_bounds = .false.
779 IF ( x_int < x(1) .OR. x_int > x(n) ) out_of_bounds = .true.
781 IF (x_int <= x(k) )
EXIT 785 IF (out_of_bounds .AND. i1==1)
THEN 787 ELSE IF (out_of_bounds .AND. i2==n)
THEN 834 SUBROUTINE lpoly(x, x_int, p)
835 REAL(fp),
INTENT(IN) :: x(:)
836 REAL(fp),
INTENT(IN) :: x_int
852 IF ( x_int < x(2) )
THEN 855 ELSE IF ( x_int > x(3) )
THEN 859 p%w_right = p%dxi_left(2) / (-p%dx_left(3))
860 p%w_left =
one - p%w_right
929 SUBROUTINE lpoly_tl(x , x_int , p , &
930 x_TL, x_int_TL, p_TL)
931 REAL(fp),
INTENT(IN) :: x(:)
932 REAL(fp),
INTENT(IN) :: x_int
934 REAL(fp),
INTENT(IN) :: x_tl(:)
935 REAL(fp),
INTENT(IN) :: x_int_tl
948 p_tl%dxi_left, p_tl%dx_left , p_tl%lp_left)
950 p_tl%dxi_right, p_tl%dx_right, p_tl%lp_right)
953 IF ( x_int < x(2) .OR. x_int > x(3) )
THEN 957 p_tl%w_right = -( p_tl%dxi_left(2) + (p%w_right*p_tl%dx_left(3)) ) / p%dx_left(3)
958 p_tl%w_left = -p_tl%w_right
1026 SUBROUTINE lpoly_ad(x , x_int , p , &
1027 p_AD, x_AD, x_int_AD)
1028 REAL(fp),
INTENT(IN) :: x(:)
1029 REAL(fp),
INTENT(IN) :: x_int
1032 REAL(fp),
INTENT(IN OUT) :: x_ad(:)
1033 REAL(fp),
INTENT(IN OUT) :: x_int_ad
1036 IF ( x_int < x(2) .OR. x_int > x(3) )
THEN 1040 p_ad%w_right = p_ad%w_right - p_ad%w_left
1042 p_ad%dx_left(3) = p_ad%dx_left(3) - (p%w_right*p_ad%w_right/p%dx_left(3))
1043 p_ad%dxi_left(2) = p_ad%dxi_left(2) - (p_ad%w_right/p%dx_left(3))
1051 p_ad%dxi_right, p_ad%dx_right)
1057 p_ad%dxi_left, p_ad%dx_left)
1082 REAL(fp),
INTENT(IN) :: dxi(:)
1083 REAL(fp),
INTENT(IN) :: dx(:)
1084 REAL(fp),
INTENT(IN OUT) :: lp(:)
1085 lp(1) = dxi(2)*dxi(3) / ( dx(1)*dx(2))
1086 lp(2) = dxi(1)*dxi(3) / (-dx(1)*dx(3))
1087 lp(3) = dxi(1)*dxi(2) / ( dx(2)*dx(3))
1092 dxi_TL, dx_TL, lp_TL)
1093 REAL(fp),
INTENT(IN) :: dxi(:)
1094 REAL(fp),
INTENT(IN) :: dx(:)
1095 REAL(fp),
INTENT(IN) :: lp(:)
1096 REAL(fp),
INTENT(IN) :: dxi_TL(:)
1097 REAL(fp),
INTENT(IN) :: dx_TL(:)
1098 REAL(fp),
INTENT(IN OUT) :: lp_TL(:)
1099 lp_tl(1) = ( (dxi(3)*dxi_tl(2) ) + &
1100 (dxi(2)*dxi_tl(3) ) - &
1101 (dx(2) *dx_tl(1) *lp(1)) - &
1102 (dx(1) *dx_tl(2) *lp(1)) ) / (dx(1)*dx(2))
1103 lp_tl(2) = ( (dxi(3)*dxi_tl(1) ) + &
1104 (dxi(1)*dxi_tl(3) ) + &
1105 (dx(3) *dx_tl(1) *lp(2)) + &
1106 (dx(1) *dx_tl(3) *lp(2)) ) / (-dx(1)*dx(3))
1107 lp_tl(3) = ( (dxi(2)*dxi_tl(1) ) + &
1108 (dxi(1)*dxi_tl(2) ) - &
1109 (dx(3) *dx_tl(2) *lp(3)) - &
1110 (dx(2) *dx_tl(3) *lp(3)) ) / (dx(2)*dx(3))
1118 REAL(fp),
INTENT(IN) :: dxi(:)
1119 REAL(fp),
INTENT(IN) :: dx(:)
1120 REAL(fp),
INTENT(IN) :: lp(:)
1121 REAL(fp),
INTENT(IN OUT) :: lp_AD(:)
1122 REAL(fp),
INTENT(IN OUT) :: dxi_AD(:)
1123 REAL(fp),
INTENT(IN OUT) :: dx_AD(:)
1126 d = lp_ad(3)/(dx(2)*dx(3))
1127 dxi_ad(1) = dxi_ad(1) + d*dxi(2)
1128 dxi_ad(2) = dxi_ad(2) + d*dxi(1)
1129 dx_ad(2) = dx_ad(2) - d*dx(3)*lp(3)
1130 dx_ad(3) = dx_ad(3) - d*dx(2)*lp(3)
1133 d = lp_ad(2)/(-dx(1)*dx(3))
1134 dxi_ad(1) = dxi_ad(1) + d*dxi(3)
1135 dxi_ad(3) = dxi_ad(3) + d*dxi(1)
1136 dx_ad(2) = dx_ad(2) + d*dx(3)*lp(2)
1137 dx_ad(3) = dx_ad(3) + d*dx(2)*lp(2)
1140 d = lp_ad(1)/(dx(1)*dx(2))
1141 dxi_ad(2) = dxi_ad(2) + d*dxi(3)
1142 dxi_ad(3) = dxi_ad(3) + d*dxi(2)
1143 dx_ad(1) = dx_ad(1) - d*dx(2)*lp(1)
1144 dx_ad(2) = dx_ad(2) - d*dx(1)*lp(1)
1155 REAL(fp),
INTENT(IN) :: x(:)
1156 REAL(fp),
INTENT(IN OUT) :: dx(:)
1164 REAL(fp),
INTENT(IN) :: x_TL(:)
1165 REAL(fp),
INTENT(IN OUT) :: dx_TL(:)
1166 dx_tl(1) = x_tl(1)-x_tl(2)
1167 dx_tl(2) = x_tl(1)-x_tl(3)
1168 dx_tl(3) = x_tl(2)-x_tl(3)
1173 REAL(fp),
INTENT(IN OUT) :: dx_AD(:)
1174 REAL(fp),
INTENT(IN OUT) :: x_AD(:)
1175 x_ad(3) = x_ad(3) - dx_ad(3)
1176 x_ad(2) = x_ad(2) + dx_ad(3)
1178 x_ad(3) = x_ad(3) - dx_ad(2)
1179 x_ad(1) = x_ad(1) + dx_ad(2)
1181 x_ad(2) = x_ad(2) - dx_ad(1)
1182 x_ad(1) = x_ad(1) + dx_ad(1)
1192 REAL(fp),
INTENT(IN) :: x(:)
1193 REAL(fp),
INTENT(IN) :: xi
1194 REAL(fp),
INTENT(IN OUT) :: dxi(:)
1202 REAL(fp),
INTENT(IN) :: x_TL(:)
1203 REAL(fp),
INTENT(IN) :: xi_TL
1204 REAL(fp),
INTENT(IN OUT) :: dxi_TL(:)
1205 dxi_tl(1) = xi_tl - x_tl(1)
1206 dxi_tl(2) = xi_tl - x_tl(2)
1207 dxi_tl(3) = xi_tl - x_tl(3)
1212 REAL(fp),
INTENT(IN OUT) :: dxi_AD(:)
1213 REAL(fp),
INTENT(IN OUT) :: x_AD(:)
1214 REAL(fp),
INTENT(IN OUT) :: xi_AD
1215 x_ad(1) = x_ad(1) - dxi_ad(1)
1216 xi_ad = xi_ad + dxi_ad(1)
1218 x_ad(2) = x_ad(2) - dxi_ad(2)
1219 xi_ad = xi_ad + dxi_ad(2)
1221 x_ad(3) = x_ad(3) - dxi_ad(3)
1222 xi_ad = xi_ad + dxi_ad(3)
subroutine, public interp_3d_ad(z, ulp, vlp, wlp, z_int_AD, z_AD, ulp_AD, vlp_AD, wlp_AD)
subroutine, public interp_3d_tl(z, ulp, vlp, wlp, z_TL, ulp_TL, vlp_TL, wlp_TL, z_int_TL)
subroutine find_regular_index(x, dx, x_int, i1, i2, out_of_bounds)
character(*), parameter module_rcs_id
subroutine, public interp_4d(z, ulp, vlp, wlp, xlp, z_int)
subroutine compute_dxi_ad(dxi_AD, x_AD, xi_AD)
integer, parameter, public fp
subroutine, public interp_4d_tl(z, ulp, vlp, wlp, xlp, z_TL, ulp_TL, vlp_TL, wlp_TL, xlp_TL, z_int_TL)
subroutine compute_qpoly_ad(dxi, dx, lp, lp_AD, dxi_AD, dx_AD)
subroutine compute_dxi(x, xi, dxi)
subroutine, public interp_1d_ad(z, ulp, z_int_AD, z_AD, ulp_AD)
subroutine, public interp_4d_ad(z, ulp, vlp, wlp, xlp, z_int_AD, z_AD, ulp_AD, vlp_AD, wlp_AD, xlp_AD)
subroutine, public clear_lpoly(p)
subroutine, public lpoly_ad(x, x_int, p, p_AD, x_AD, x_int_AD)
subroutine compute_qpoly(dxi, dx, lp)
subroutine, public lpoly_inspect(self)
subroutine, public interp_1d_tl(z, ulp, z_TL, ulp_TL, z_int_TL)
subroutine, public lpoly_init(self)
subroutine, public interp_2d_ad(z, ulp, vlp, z_int_AD, z_AD, ulp_AD, vlp_AD)
subroutine, public lpoly(x, x_int, p)
integer, parameter, public npts
subroutine compute_dx(x, dx)
subroutine compute_qpoly_tl(dxi, dx, lp, dxi_TL, dx_TL, lp_TL)
subroutine compute_dxi_tl(x_TL, xi_TL, dxi_TL)
subroutine, public interp_3d(z, ulp, vlp, wlp, z_int)
integer, parameter, public order
subroutine compute_dx_ad(dx_AD, x_AD)
subroutine compute_dx_tl(x_TL, dx_TL)
subroutine, public lpoly_tl(x, x_int, p, x_TL, x_int_TL, p_TL)
subroutine, public interp_1d(z, ulp, z_int)
subroutine, public interp_2d_tl(z, ulp, vlp, z_TL, ulp_TL, vlp_TL, z_int_TL)
subroutine find_random_index(x, x_int, i1, i2, out_of_bounds)
integer, parameter npoly_pts
subroutine, public interp_2d(z, ulp, vlp, z_int)