16 PUBLIC :: two_power, two_power_gs, function_test
39 REAL(rprec)
PURE FUNCTION two_power(x, b)
44 REAL(rprec),
INTENT(in) :: x
45 REAL(rprec),
DIMENSION(0:20),
INTENT(in) :: b
48 two_power = b(0)*((1.0 - x**b(1))**b(2))
69 REAL(rprec)
PURE function two_power_gs(x, b)
74 REAL(rprec),
INTENT(in) :: x
75 REAL(rprec),
DIMENSION(0:20),
INTENT(in) :: b
83 two_power_gs = two_power_gs
84 & + b(i)*exp(-((x - b(i+1))/b(i+2))**2.0)
86 two_power_gs = two_power_gs*two_power(x,b)
105 REAL(rprec)
PURE function guassian(x, b)
110 REAL(rprec),
INTENT(in) :: x
111 REAL(rprec),
DIMENSION(0:20),
INTENT(in) :: b
114 guassian = b(0)*exp(-((x - b(1))/b(2))**2.0)
136 REAL(rprec)
PURE function guassian_int(x, b)
137 USE stel_constants,
only : pi
142 REAL(rprec),
INTENT(in) :: x
143 REAL(rprec),
DIMENSION(0:20),
INTENT(in) :: b
146 REAL(rprec),
PARAMETER :: sqrpi = 0.5*sqrt(pi)
150 guassian_int = sqrpi*b(0)*b(1)*(erf(b(1)/b(2)) -
151 & erf((b(1) - x)/b(2)))
165 FUNCTION function_test()
170 LOGICAL :: function_test
173 REAL(rprec) :: result
174 REAL(rprec),
DIMENSION(0:20) :: b(0:20) = 0
178 b(0:2) = (/ 1.0d+0, 10.0d+0, 2.0d+0 /)
179 result = two_power(0.0d+0, b)
180 function_test = check(1.0d+0,result,1,
"two_power()")
181 IF (.not.function_test)
RETURN
184 result = two_power(1.0d+0, b)
185 function_test = check(0.0d+0,result,2,
"two_power()")
186 IF (.not.function_test)
RETURN
189 b(0:2) = (/ 1.0d+0, 1.0d+0, 1.0d+0 /)
190 result = two_power(0.5d+0, b)
191 function_test = check(0.5d+0,result,3,
"two_power()")
192 IF (.not.function_test)
RETURN
195 b(0:2) = (/ 1.0d+0, 1.0d+0, 2.0d+0 /)
196 result = two_power(0.5d+0, b)
197 function_test = check(0.25d+0,result,4,
"two_power()")
198 IF (.not.function_test)
RETURN
201 b(0:5) = (/ 1.0d+0, 1.0d+0, 1.0d+0, 0.0d+0, 0.0d+0, 1.0d+0 /)
202 result = two_power_gs(0.4d+0, b)
203 function_test = check(two_power(0.4d+0, b),
204 & result,1,
"two_power_gs")
205 IF (.not.function_test)
RETURN
208 b(0:5) = (/ 1.0d+0, 1.0d+0, 0.0d+0, 1.0d+0, 0.8d+0, 0.1d+0 /)
209 result = two_power_gs(0.8d+0, b)
210 function_test = check(2.0d+0,result,1,
"two_power_gs")
211 IF (.not.function_test)
RETURN
230 FUNCTION check(expected, received, testNum, name)
236 REAL(rprec),
INTENT(in) :: expected, received
237 INTEGER,
INTENT(in) :: testnum
238 CHARACTER (LEN=*),
INTENT(in) :: name
241 check = expected .eq. received
243 write(*,*)
"functions.f: ", name,
" test", testnum,
245 write(*,*)
"Expected", expected,
"Received", received