summaryrefslogtreecommitdiff
path: root/src/labat/deriv.f
diff options
context:
space:
mode:
Diffstat (limited to 'src/labat/deriv.f')
-rw-r--r--src/labat/deriv.f65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/labat/deriv.f b/src/labat/deriv.f
new file mode 100644
index 0000000..b440070
--- /dev/null
+++ b/src/labat/deriv.f
@@ -0,0 +1,65 @@
1 function deriv(r,x,x2,spin,i,imin,imax)
2c deriv calculates the derivative of x with respect to r, at
3c position r(i).
4c input r : radial coordinate (array)
5c input x : function to be derivated (array)
6c input x2 : second derivative of x (array)
7c input spin : -1 if spin-down, 1 if spin-up, 0 otherwise
8c input i : counter, i.e. current position = r(i)
9c input imin : min value of i
10c input imax : max value of i
11 implicit logical (a-z)
12 double precision deriv,r,x,x2
13 double precision h,d,dforw,dback,dforup,dfordn,dbacup,dbacdn
14 integer spin,i,imin,imax
15 dimension r(561),x(2,561),x2(2,561)
16 if (i.eq.imin) then
17 h = (r(i+1)-r(i))/2.d0
18 if (spin.eq.-1) then
19 d = x(2,i)
20 call splint(r,x,x2,-1,imin,imax,r(i)+h,dforw)
21 elseif (spin.eq.1) then
22 d = x(1,i)
23 call splint(r,x,x2,1,imin,imax,r(i)+h,dforw)
24 else
25 d = (x(1,i) + x(2,i))
26 call splint(r,x,x2,1,imin,imax,r(i)+h,dforup)
27 call splint(r,x,x2,-1,imin,imax,r(i)+h,dfordn)
28 dforw = dforup + dfordn
29 endif
30 deriv = (dforw-d)/h
31 elseif (i.eq.imax) then
32 h = (r(i)-r(i-1))/2.d0
33 if (spin.eq.-1) then
34 call splint(r,x,x2,-1,imin,imax,r(i)-h,dback)
35 d = x(2,i)
36 elseif (spin.eq.1) then
37 call splint(r,x,x2,1,imin,imax,r(i)-h,dback)
38 d = x(1,i)
39 else
40 call splint(r,x,x2,1,imin,imax,r(i)-h,dbacup)
41 call splint(r,x,x2,-1,imin,imax,r(i)-h,dbacdn)
42 dback = dbacup + dbacdn
43 d = x(1,i) + x(2,i)
44 endif
45 deriv = (d-dback)/h
46 else
47 h = (r(i)-r(i-1))/2.d0
48 if (spin.eq.-1) then
49 call splint(r,x,x2,-1,imin,imax,r(i)+h,dforw)
50 call splint(r,x,x2,-1,imin,imax,r(i)-h,dback)
51 elseif (spin.eq.1) then
52 call splint(r,x,x2,1,imin,imax,r(i)+h,dforw)
53 call splint(r,x,x2,1,imin,imax,r(i)-h,dback)
54 else
55 call splint(r,x,x2,-1,imin,imax,r(i)+h,dfordn)
56 call splint(r,x,x2,-1,imin,imax,r(i)-h,dbacdn)
57 call splint(r,x,x2,1,imin,imax,r(i)+h,dforup)
58 call splint(r,x,x2,1,imin,imax,r(i)-h,dbacup)
59 dback = dbacup + dbacdn
60 dforw = dforup + dfordn
61 endif
62 deriv = (dforw-dback)/(2.d0*h)
63 endif
64 return
65 end