The Elk Code
splint.f90
Go to the documentation of this file.
1 
2 ! Copyright (C) 2018 J. K. Dewhurst, S. Sharma and E. K. U. Gross.
3 ! This file is distributed under the terms of the GNU General Public License.
4 ! See the file COPYING for license details.
5 
6 real(8) function splint(n,x,f)
7 implicit none
8 ! arguments
9 integer, intent(in) :: n
10 real(8), intent(in) :: x(n),f(n)
11 ! local variables
12 integer i
13 real(8) x0,x1,x2,x3,y0,y1,y2,y3
14 real(8) t0,t1,t2,t3,t4,t5,t6,t7
15 ! external functions
16 real(8), external :: polynm
17 if (n <= 4) then
18  splint=polynm(-1,n,x,f,x(n))
19  return
20 end if
21 ! fit piecewise cubic spline to data and integrate
22 x0=x(1)
23 x1=x(2)-x0; x2=x(3)-x0; x3=x(4)-x0
24 t4=x1-x2; t5=x1-x3; t6=x2-x3
25 y0=f(1)
26 y1=f(2)-y0; y2=f(3)-y0; y3=f(4)-y0
27 t1=x1*x2*y3; t2=x2*x3*y1; t3=x1*x3
28 t0=0.5d0/(t3*t4*t5*t6)
29 t3=t3*y2
30 t7=t1*t4+t2*t6-t3*t5
31 t4=x1**2; t5=x2**2; t6=x3**2
32 y1=t3*t6-t1*t5; y3=t2*t5-t3*t4; y2=t1*t4-t2*t6
33 t1=x1*y1+x2*y2+x3*y3
34 t2=y1+y2+y3
35 splint=x2*(y0+t0*(t1+x2*(0.5d0*t7*x2-0.6666666666666666667d0*t2)))
36 do i=3,n-3
37  x0=x(i)
38  x1=x(i-1)-x0; x2=x(i+1)-x0; x3=x(i+2)-x0
39  t4=x1-x2; t5=x1-x3; t6=x2-x3; t3=x1*x3
40  y0=f(i)
41  y1=f(i-1)-y0; y2=f(i+1)-y0; y3=f(i+2)-y0
42  t1=x1*x2*y3; t2=x2*x3*y1
43  t0=0.5d0/(t3*t4*t5*t6)
44  t3=t3*y2
45  t7=t1*t4+t2*t6-t3*t5
46  t4=x1**2; t5=x2**2; t6=x3**2
47  y1=t3*t6-t1*t5; y2=t1*t4-t2*t6; y3=t2*t5-t3*t4
48  t1=x1*y1+x2*y2+x3*y3
49  t2=y1+y2+y3
50  splint=splint+x2*(y0+t0*(t1+x2*(0.5d0*t7*x2-0.6666666666666666667d0*t2)))
51 end do
52 x0=x(n-2)
53 x1=x(n-3)-x0; x2=x(n-1)-x0; x3=x(n)-x0
54 t4=x1-x2; t5=x1-x3; t6=x2-x3
55 y0=f(n-2)
56 y1=f(n-3)-y0; y2=f(n-1)-y0; y3=f(n)-y0
57 t1=x1*x2; t2=x2*x3*y1; t3=x1*x3*y2
58 t0=0.5d0/(t1*t4*t5*t6)
59 t1=t1*y3
60 t7=t1*t4+t2*t6-t3*t5
61 t4=x1**2; t5=x2**2; t6=x3**2
62 y1=t3*t6-t1*t5; y2=t1*t4-t2*t6; y3=t2*t5-t3*t4
63 t1=x1*y1+x2*y2+x3*y3
64 t2=y1+y2+y3
65 splint=splint+x3*(y0+t0*(t1+x3*(0.5d0*t7*x3-0.6666666666666666667d0*t2)))
66 end function
67 
real(8) function splint(n, x, f)
Definition: splint.f90:7
pure real(8) function polynm(m, np, xa, ya, x)
Definition: polynm.f90:10