-
Notifications
You must be signed in to change notification settings - Fork 0
/
PSfunc.f
221 lines (216 loc) · 6.93 KB
/
PSfunc.f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
c***********************************************************************
double precision function Scalc(x,m,n,y,rKL,LMAX)
c** At the position 'x', Scalc is returned as the value of the m'th
c of the 'n' Sm(x) function defining a natural cubic spline through the
c mesh points located at x= y(x_i), for i=1,n. LMAX specifies the
c maximum number of mesh points x= y(x_i) allowed by the calling program
c---------------------------------------------------------------------
INTEGER LMAX,I,K,KK,M,N
REAL*8 x,y1,y2,y(1:LMAX),rKL(1:LMAX,1:LMAX)
k= 0
kk= 0
do i=2,n
c... select interval
if ((x.gt.y(i-1)).and.(x.le.y(i))) k=i
end do
if (x.lt.y(1)) then
k=2
kk=1
end if
if (x.gt.y(n)) then
k=n
kk=1
end if
if(x.eq.y(1)) k=2
y1=y(k-1)
y2=y(k)
Scalc= 0.d0
IF(kk.eq.0)
1 Scalc= rKL(m,k)*((y1-x)*(((y1-x)/(y1-y2))**2-1)/6)*(y1-y2)
2 + rKL(m,k-1)*((x-y2)*(((x-y2)/(y1-y2))**2-1)/6)*(y1-y2)
IF(k.EQ.m) Scalc= Scalc + (y1-x)/(y1-y2)
IF(k-1.EQ.m) Scalc= Scalc + (x-y2)/(y1-y2)
c... Asen's original coding ...
cc Scalc=ndirac(k,m)*A(x,y1,y2)+ndirac(k-1,m)*B(x,y1,y2)+
cc + C(x,y1,y2)*rKL(m,k)+D(x,y1,y2)*rKL(m,k-1)
cc else
cc Scalc=ndirac(k,m)*A(x,y1,y2)+ndirac(k-1,m)*B(x,y1,y2)
cc A=(x1-z)/(x1-x2)
cc B=(z-x2)/(x1-x2)
cc C=((x1-z)*(((x1-z)/(x1-x2))**2-1)/6)*(x1-x2)
cc D=((z-x2)*(((z-x2)/(x1-x2))**2-1)/6)*(x1-x2)
c... Asen's original coding ...
end
c23456789 123456789 123456789 123456789 123456789 123456789 123456789 12
c***********************************************************************
double precision function Sprime(x,m,n,y,rKL,LMAX)
c** At the position 'x', evaluate the derivative w.r.t. x of the m'th
c Sm(x) function contributing the definition of the the natural cubic
c spline defined by function values at the n points y(i) [i=1,n]
INTEGER i,k,kk,m,n,LMAX
REAL*8 x,del,y1,y2,y(1:LMAX),rKL(1:LMAX,1:LMAX)
k=0
kk=0
do i=2,n
if((x.gt.y(i-1)).and.(x.le.y(i))) k=i
enddo
if(x.lt.y(1)) then
k=2
kk=1
end if
if (x.gt.y(n)) then
k=n
kk=1
end if
if (x.eq.y(1)) k=2
y1=y(k-1)
y2=y(k)
del=y1-y2
Sprime= 0.d0
if(kk.eq.0) Sprime= (del-3.d0*(y1-x)**2/del)*rKL(m,k)/6.d0 +
1 (3.d0*(x-y2)**2/del-del)*rKL(m,k-1)/6.d0
IF(k-1.eq.m) Sprime= Sprime + 1.d0/del
IF(k.eq.m) Sprime= Sprime - 1.d0/del
ccc if(kk.eq.0) then
ccc Sprim=ndirac(k-1,m)/del-ndirac(k,m)/del+
ccc + (del-3*(y1-x)**2/del)*rKL(m,k)/6+
ccc + (3*(x-y2)**2/del-del)*rKL(m,k-1)/6
ccc else
ccc Sprim=ndirac(k-1,m)/del-ndirac(k,m)/del
ccc end if
end
c23456789 123456789 123456789 123456789 123456789 123456789 123456789 12
c***********************************************************************
subroutine Lkoef(n,x,A,LMAX)
c** Call this subroutine with list of the 'n' spline x_i values in array
c 'x' with maximum dimension 'LMAX' and it will return the LMAX x LMAX
c array of 'rKL' coefficients used for generating the 'n' S_n(x)
c spline coefficient functions
c-----------------------------------------------------------------------
c
c*** Based on nespl subroutine
INTEGER LMAX
INTEGER I,J,N,INDX(1:LMAX)
REAL*8 X(1:LMAX),A(1:LMAX,1:LMAX),B(1:LMAX,1:LMAX), d
c
DO i= 1,LMAX
DO j= 1,LMAX
A(i,j)= 0.d0
B(i,j)= 0.d0
ENDDO
ENDDO
A(1,1)= (x(3)-x(1))/3.d0
A(1,2)= (x(3)-x(2))/6.d0
do i= 2,n-3
A(i,i-1)= (x(i+1)-x(i))/6.d0
A(i,i)= (x(i+2)-x(i))/3.d0
A(i,i+1)= (x(i+2)-x(i+1))/6.d0
end do
A(n-2,n-3)= (x(n-1)-x(n-2))/6.d0
A(n-2,n-2)= (x(n)-x(n-2))/3.d0
do i= 1,n-2
B(i,i)= 1.d0/(x(i+1)-x(i))
B(i,i+1)= -1.d0/(x(i+2)-x(i+1))-1.d0/(x(i+1)-x(i))
B(i,i+2)= 1.d0/(x(i+2)-x(i+1))
end do
call ludcmp(A,n-2,LMAX,indx,d)
do i= 1,n
call lubksb(A,n-2,LMAX,indx,B(1,i))
end do
do i= 1,n-2
do j= 1,n
A(j,i+1)= B(i,j)
end do
end do
do i= 1,n
A(i,1)= 0.0d0
A(i,n)= 0.0d0
end do
end
c23456789 123456789 123456789 123456789 123456789 123456789 123456789 12
c***********************************************************************
SUBROUTINE ludcmp(a,n,np,indx,d)
INTEGER n,np,indx(n),NMAX
double precision d,a(np,np),TINY
PARAMETER (NMAX= 500,TINY= 1.0e-20)
INTEGER i,imax,j,k
double precision aamax,dum,sum,vv(NMAX)
d= 1.d0
do i= 1,n
aamax= 0.d0
do j= 1,n
if (abs(a(i,j)).gt.aamax) aamax= abs(a(i,j))
enddo
if (aamax.eq.0.) WRITE(6,*) 'singular matrix in ludcmp'
vv(i)= 1.d0/aamax
enddo
do j= 1,n
do i= 1,j-1
sum= a(i,j)
do k= 1,i-1
sum= sum-a(i,k)*a(k,j)
enddo
a(i,j)= sum
enddo
aamax= 0.d0
do i= j,n
sum= a(i,j)
do k= 1,j-1
sum= sum-a(i,k)*a(k,j)
enddo
a(i,j)= sum
dum= vv(i)*abs(sum)
if (dum.ge.aamax) then
imax= i
aamax= dum
endif
enddo
if(j.ne.imax)then
do k= 1,n
dum= a(imax,k)
a(imax,k)= a(j,k)
a(j,k)= dum
enddo
d= -d
vv(imax)= vv(j)
endif
indx(j)= imax
if(a(j,j).eq.0.)a(j,j)= TINY
if(j.ne.n)then
dum= 1.d0/a(j,j)
do i= j+1,n
a(i,j)= a(i,j)*dum
enddo
endif
enddo
return
END
c23456789 123456789 123456789 123456789 123456789 123456789 123456789 12
c***********************************************************************
SUBROUTINE lubksb(a,n,np,indx,b)
INTEGER i,ii,j,ll, n,np,indx(n)
double precision a(np,np),b(n), sum
ii= 0
do i= 1,n
ll= indx(i)
sum= b(ll)
b(ll)= b(i)
if (ii.ne.0)then
do j= ii,i-1
sum= sum-a(i,j)*b(j)
enddo
else if (sum.ne.0.) then
ii= i
endif
b(i)= sum
enddo
do i= n,1,-1
sum= b(i)
do j= i+1,n
sum= sum-a(i,j)*b(j)
enddo
b(i)= sum/a(i,i)
enddo
return
END
c23456789 123456789 123456789 123456789 123456789 123456789 123456789 12