MONC
test_interpolation.F90
Go to the documentation of this file.
1 ! Tests the logging_mod utility functions
3  use fruit, only : assert_equals, assert_not_equals, &
4  assert_true
7  implicit none
8 
9 contains
10 
11  ! Test random produces a non zero value
13 
14  real(kind=DEFAULT_PRECISION) :: zvals(0), vals(2)
15  real(kind=DEFAULT_PRECISION) :: zgrid(2)
16  real(kind=DEFAULT_PRECISION) :: field(2)
17  integer :: i
18  do i=1,2
19  vals(i)=10.0_default_precision
20  zgrid(i)=10.0_default_precision
21  field(i)=10.0_default_precision
22  enddo
23  call piecewise_linear_1d(zvals, vals, zgrid, field)
24 
25  do i=1,2
26  call assert_equals(10.0_default_precision, field(i), "Test no change in field")
27  enddo
28  end subroutine test_piecewise_zero_nnodes
29 
30  ! Test value obtain when the product result is zero
32 
33  real(kind=DEFAULT_PRECISION) :: zvals(2), vals(2)
34  real(kind=DEFAULT_PRECISION) :: zgrid(2)
35  real(kind=DEFAULT_PRECISION) :: field(2)
36  integer :: i
37  zgrid(1) = 10.0_default_precision
38  zgrid(2) = 9.0_default_precision
39  do i=1,2
40  vals(i)=50.0_default_precision
41  zvals(i)=11.0_default_precision
42  enddo
43  zvals(1) = 10.0_default_precision
44  call piecewise_linear_1d(zvals, vals, zgrid, field)
45 
46  call assert_equals(50.0_default_precision, field(1), "Test field(k) = vals(nn-1) when (zgrid(k)=zvals(nn-1)")
47 
48  end subroutine test_piecewise_zgrid_eq_zvals
49 
50  ! Test random produces a non zero value
51  subroutine test_interpolate_linear
52 
53  real(kind=DEFAULT_PRECISION) :: zvals(2), vals(2)
54  integer :: i
55  real(kind=DEFAULT_PRECISION) :: z,f1,f2
56  character(12) :: extrapolate
57 
58  extrapolate = 'linear'
59  z = 0.0_default_precision
60  do i=1,2
61  vals(i)=50.0_default_precision
62  zvals(i)=11.0_default_precision
63  enddo
64  zvals(1) = 10.0_default_precision
65  call interpolate_point_linear_1d(zvals, vals, z, f1)
66  call interpolate_point_linear_1d(zvals, vals, z, f2, extrapolate)
67 
68  call assert_equals(f1, f2, "Test linear is used by default")
69  end subroutine test_interpolate_linear
70 
71 ! Test random produces a non zero value
72  subroutine test_no_interpolation
73 
74  real(kind=DEFAULT_PRECISION) :: zvals(2), vals(2)
75  integer :: i
76  real(kind=DEFAULT_PRECISION) :: z,f
77  character(12) :: extrapolate
78 
79  extrapolate = 'linear'
80  z = 0.0_default_precision
81  f = 7.0_default_precision
82  do i=1,2
83  vals(i)=50.0_default_precision
84  zvals(i)=11.0_default_precision
85  enddo
86  zvals(1) = 0.0_default_precision
87  call interpolate_point_linear_1d(zvals, vals, z, f)
88 
89 
90  call assert_equals(7.0_default_precision, f, "Test linear is used by default")
91  end subroutine test_no_interpolation
92 
93 
94 end module test_interpolation_mod
95 
96 
97 
98  ! Driver for maths_mod utility tests
100  use fruit, only : init_fruit, run_test_case, fruit_summary
101  use maths_mod, only : random
104 
105  implicit none
106 
107  call init_fruit
108  call run_test_case(test_piecewise_zero_nnodes, "Test piecewise when zvals is empty")
109  call run_test_case(test_piecewise_zgrid_eq_zvals, "Test piecewise when zgrid=zvals(nn-1)")
110  call run_test_case(test_interpolate_linear, "Test results with linear extrapolation")
111  call run_test_case(test_no_interpolation, "Test there is no interpolation if z=zvals(1)=zvals(nn)")
112  call fruit_summary
113  end program test_interpolation_driver
subroutine interpolate_point_linear_1d(zvals, vals, z, f, extrapolate)
Does a simple 1d linear interpolation to a point.
integer, parameter, public default_precision
MPI communication type which we use for the prognostic and calculation data.
Definition: datadefn.F90:17
Contains common definitions for the data and datatypes used by MONC.
Definition: datadefn.F90:2
subroutine test_piecewise_zgrid_eq_zvals
subroutine piecewise_linear_1d(zvals, vals, zgrid, field)
Does a simple 1d piecewise linear interpolation.
real(kind=default_precision) function, public random(idum)
returns a scalar random number, the initial seed idum must be negative usage: idum = -k !(set idum < ...
Definition: maths.F90:23
program test_interpolation_driver