The Elk Code
 
Loading...
Searching...
No Matches
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
6real(8) function splint(n,x,f)
7implicit none
8! arguments
9integer, intent(in) :: n
10real(8), intent(in) :: x(n),f(n)
11! local variables
12integer i
13real(8) x0,x1,x2,x3,y0,y1,y2,y3
14real(8) t0,t1,t2,t3,t4,t5,t6,t7
15! external functions
16real(8), external :: polynm
17if (n <= 4) then
18 splint=polynm(-1,n,x,f,x(n))
19 return
20end if
21! fit piecewise cubic spline to data and integrate
22x0=x(1)
23x1=x(2)-x0; x2=x(3)-x0; x3=x(4)-x0
24t4=x1-x2; t5=x1-x3; t6=x2-x3
25y0=f(1)
26y1=f(2)-y0; y2=f(3)-y0; y3=f(4)-y0
27t1=x1*x2*y3; t2=x2*x3*y1; t3=x1*x3
28t0=0.5d0/(t3*t4*t5*t6)
29t3=t3*y2
30t7=t1*t4+t2*t6-t3*t5
31t4=x1**2; t5=x2**2; t6=x3**2
32y1=t3*t6-t1*t5; y3=t2*t5-t3*t4; y2=t1*t4-t2*t6
33t1=x1*y1+x2*y2+x3*y3
34t2=y1+y2+y3
35splint=x2*(y0+t0*(t1+x2*(0.5d0*t7*x2-0.6666666666666666667d0*t2)))
36do 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)))
51end do
52x0=x(n-2)
53x1=x(n-3)-x0; x2=x(n-1)-x0; x3=x(n)-x0
54t4=x1-x2; t5=x1-x3; t6=x2-x3
55y0=f(n-2)
56y1=f(n-3)-y0; y2=f(n-1)-y0; y3=f(n)-y0
57t1=x1*x2; t2=x2*x3*y1; t3=x1*x3*y2
58t0=0.5d0/(t1*t4*t5*t6)
59t1=t1*y3
60t7=t1*t4+t2*t6-t3*t5
61t4=x1**2; t5=x2**2; t6=x3**2
62y1=t3*t6-t1*t5; y2=t1*t4-t2*t6; y3=t2*t5-t3*t4
63t1=x1*y1+x2*y2+x3*y3
64t2=y1+y2+y3
65splint=splint+x3*(y0+t0*(t1+x3*(0.5d0*t7*x3-0.6666666666666666667d0*t2)))
66end function
67
pure real(8) function polynm(m, np, xa, ya, x)
Definition polynm.f90:10
real(8) function splint(n, x, f)
Definition splint.f90:7