module test_splsubs use fruit implicit none INTEGER, PARAMETER :: n = 11 REAL, DIMENSION(n) :: x = (/ 0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10./) REAL, DIMENSION(n) :: y = (/ 0., 0., 1., 2., 1., 0., -1., -2., -1., 0., 0. /) contains subroutine test_splsubs_spline_splint_exact_points REAL, DIMENSION(n) :: y2 INTEGER :: i REAL :: z REAL :: tension REAL :: yp1, ypn, yout y2 = 0 yp1 = 0 ypn = 0 yout = 0 call spline(x, y, n, yp1, ypn, y2) ! check that input values are returned from interp correctly do i = 0, n-1 z = real(i) tension = 1. call splintt(x, y, y2, n, z, tension, yout) call assert_equals( yout, y(i+1)) end do end subroutine test_splsubs_spline_splint_exact_points subroutine test_splsubs_spline_splint_mid_points REAL, DIMENSION(n) :: y2 INTEGER :: i REAL :: z REAL :: tension REAL :: yp1, ypn, yout, miny, maxy y2 = 0 yp1 = 0 ypn = 0 yout = 0 call spline(x, y, n, yp1, ypn, y2) ! Dumb test to check that mid points are between the input ! values. Skip first and last points where both do i = 0, n-2 z = real(i) + 0.5 tension = 1. call splintt(x, y, y2, n, z, tension, yout) miny = MIN(y(i+1), y(i+2)) maxy = MAX(y(i+1), y(i+2)) if (miny .ne. maxy) then call assert_true(yout.gt.miny .and. yout.lt.maxy) else call assert_equals(yout, miny, 0.05) endif end do end subroutine test_splsubs_spline_splint_mid_points subroutine test_splsubs_spline_splint_tension_limit REAL, DIMENSION(n) :: y2 REAL :: z REAL :: tension REAL :: yp1, ypn, yout z = 4.5 y2 = 0 yp1 = 0 ypn = 0 yout = 0 call spline(x, y, n, yp1, ypn, y2) tension = 2. call splintt(x, y, y2, n, z, tension, yout) call assert_equals(tension, 1., 0.05) tension = -0.1 call splintt(x, y, y2, n, z, tension, yout) call assert_equals(tension, 1., 0.05) end subroutine test_splsubs_spline_splint_tension_limit end module