172 use,
intrinsic :: iso_fortran_env
207 real(real64) :: x_limit(2)
208 type(c_ptr) :: spl, acc
209 real(real64),
public :: x_threshold
252 type(c_ptr),
intent(inout) :: spl, acc
257 use,
intrinsic :: iso_fortran_env
259 integer,
intent(in) :: nrc
260 real(real64),
intent(in) :: x
261 real(real64),
intent(in) :: y
262 type(c_ptr),
intent(inout) :: spl
263 type(c_ptr),
intent(inout) :: acc
268 use,
intrinsic :: iso_fortran_env
270 real(real64),
intent(in) :: x
271 type(c_ptr),
intent(in) :: spl
272 type(c_ptr),
intent(in) :: acc
277 use,
intrinsic :: iso_fortran_env
279 integer,
intent(in) :: nn
280 real(real64),
intent(inout) :: xf
281 type(c_ptr),
intent(in) :: spl
282 type(c_ptr),
intent(in) :: acc
287 use,
intrinsic :: iso_fortran_env
289 integer,
intent(in) :: nn
290 complex(real64),
intent(inout) :: xf
291 type(c_ptr),
intent(in) :: spl
292 type(c_ptr),
intent(in) :: acc
297 use,
intrinsic :: iso_fortran_env
299 real(real64),
intent(in) :: x
300 type(c_ptr),
intent(in) :: spl
301 type(c_ptr),
intent(in) :: acc
306 use,
intrinsic :: iso_fortran_env
308 real(real64),
intent(in) :: x
309 type(c_ptr),
intent(in) :: spl
310 type(c_ptr),
intent(in) :: acc
313 integer pure function oct_spline_npoints(spl, acc)
316 type(c_ptr),
intent(in) :: spl
317 type(c_ptr),
intent(in) :: acc
322 use,
intrinsic :: iso_fortran_env
324 type(c_ptr),
intent(in) :: spl
325 real(real64),
intent(out) :: x
330 use,
intrinsic :: iso_fortran_env
332 type(c_ptr),
intent(in) :: spl
333 real(real64),
intent(out) :: y
336 real(real64)
pure function oct_spline_eval_integ(spl, a, b, acc)
338 use,
intrinsic :: iso_fortran_env
340 type(c_ptr),
intent(in) :: spl
341 real(real64),
intent(in) :: a
342 real(real64),
intent(in) :: b
343 type(c_ptr),
intent(in) :: acc
346 real(real64)
pure function oct_spline_eval_integ_full(spl, acc)
348 use,
intrinsic :: iso_fortran_env
350 type(c_ptr),
intent(in) :: spl
351 type(c_ptr),
intent(in) :: acc
355 real(real64),
parameter :: tol_x = 1e-14_real64
369 spl%x_limit(1) = -1_real64
370 spl%x_limit(2) = -2_real64
372 spl%x_threshold = m_zero
379 type(
spline_t),
intent(out) :: spl(:)
395 type(
spline_t),
intent(out) :: spl(:, :)
401 do i = 1,
size(spl, 1)
402 do j = 1,
size(spl, 2)
413 type(
spline_t),
intent(inout) :: spl
417 if (c_associated(spl%spl) .and. c_associated(spl%acc))
then
428 type(
spline_t),
intent(inout) :: spl(:)
444 type(
spline_t),
intent(inout) :: spl(:, :)
450 do i = 1,
size(spl, 1)
451 do j = 1,
size(spl, 2)
462 integer,
intent(in) :: nrc
463 real(real64),
intent(in) :: rofi(:)
464 real(real64),
intent(in) :: ffit(:)
465 type(
spline_t),
intent(inout) :: spl
466 real(real64),
optional,
intent(in) :: threshold
472 spl%x_limit(1) = rofi(1)
473 spl%x_limit(2) = rofi(nrc)
476 if (
present(threshold))
then
477 if (threshold > m_zero)
then
480 spl%x_threshold = spl%x_limit(2)
483 spl%x_threshold = m_zero
491 real(real64),
intent(in) :: x
500 integer,
intent(in) :: nn
501 real(real64),
intent(inout) :: xf(:)
512 integer,
intent(in) :: nn
513 complex(real64),
intent(inout) :: xf(:)
522 real(real64),
intent(in) :: a
523 type(
spline_t),
intent(inout) :: spl
524 real(real64),
intent(in) :: threshold
526 integer :: npoints, i
527 real(real64),
allocatable :: x(:), y(:)
534 safe_allocate(x(1:npoints))
535 safe_allocate(y(1:npoints))
544 call spline_fit(npoints, x, y, spl, threshold)
568 real(real64),
intent(in) :: a
569 real(real64),
intent(in) :: b
577 type(
spline_t),
intent(inout) :: splw
578 real(real64),
intent(in) :: threshold
579 real(real64),
optional,
intent(in) :: gmax
582 real(real64) :: g, dg
584 integer :: npoints, i, j
585 real(real64),
allocatable :: x(:), y(:), y2(:), xw(:), yw(:)
592 safe_allocate( x(1:npoints))
593 safe_allocate( y(1:npoints))
594 safe_allocate(y2(1:npoints))
600 if (c_associated(splw%spl))
then
602 safe_allocate(xw(1:np))
603 safe_allocate(yw(1:np))
608 assert(
present(gmax))
611 safe_allocate(xw(1:np))
612 safe_allocate(yw(1:np))
622 y2(j) = m_four*m_pi*y(j)*x(j)**2
632 y2(j) = (m_four*m_pi/xw(i))*y(j)*x(j)*
sin(xw(i)*x(j))
645 safe_deallocate_a(y2)
646 safe_deallocate_a(xw)
647 safe_deallocate_a(yw)
656 type(
spline_t),
intent(inout) :: splw
657 integer,
intent(in) :: l
658 real(real64),
optional,
intent(in) :: threshold
659 real(real64),
optional,
intent(in) :: gmax
664 integer :: npoints, i, j
665 real(real64),
allocatable :: x(:), y(:), y2(:), xw(:), yw(:)
672 safe_allocate( x(1:npoints))
673 safe_allocate( y(1:npoints))
674 safe_allocate(y2(1:npoints))
680 if (c_associated(splw%spl))
then
682 safe_allocate(xw(1:np))
683 safe_allocate(yw(1:np))
688 assert(
present(gmax))
691 safe_allocate(xw(1:np))
692 safe_allocate(yw(1:np))
702 y2(j) = y(j) * x(j)**2 * loct_sph_bessel(l, x(j)*xw(i))
716 safe_deallocate_a(y2)
717 safe_deallocate_a(xw)
718 safe_deallocate_a(yw)
726 type(
spline_t),
intent(inout) :: spl
727 real(real64),
intent(in) :: cutoff
728 real(real64),
intent(in) :: beta
729 real(real64),
optional,
intent(in) :: threshold
731 integer :: npoints, i
732 real(real64),
allocatable :: x(:), y(:)
733 real(real64) :: exp_arg
740 safe_allocate(x(1:npoints))
741 safe_allocate(y(1:npoints))
747 do i = npoints, 1, -1
748 if (x(i)<cutoff)
then
752 exp_arg = -beta*(x(i)/cutoff - m_one)**2
754 if (exp_arg > m_min_exp_arg)
then
755 y(i) = y(i) *
exp(exp_arg)
760 call spline_fit(npoints, x, y, spl, threshold)
775 type(
spline_t),
intent(inout) :: spla
777 real(real64),
optional,
intent(in) :: threshold
779 integer :: npoints, i, new_npoints
780 real(real64),
allocatable :: x(:), y(:)
788 safe_allocate(x(1:npoints))
789 safe_allocate(y(1:npoints))
795 assert(splb%x_limit(2) >= splb%x_limit(1))
800 do i = npoints, 1, -1
801 if (x(i) > splb%x_limit(2)-
tol_x) cycle
804 new_npoints = new_npoints + 1
806 assert(new_npoints > 0)
808 call spline_fit(new_npoints, x, y, spla, threshold)
820 type(
spline_t),
intent(inout) :: spl
821 real(real64),
intent(in) :: threshold
823 integer :: npoints, i
824 real(real64),
allocatable :: x(:), y(:)
831 safe_allocate(x(1:npoints))
832 safe_allocate(y(1:npoints))
839 do i = npoints, 1, -1
840 y(i) = max(y(i),m_zero)
843 call spline_fit(npoints, x, y, spl, threshold)
854 type(
spline_t),
intent(inout) :: spla
856 real(real64),
intent(in) :: threshold
858 integer :: npoints, i, new_npoints
859 real(real64),
allocatable :: x(:), y(:)
865 if(npoints <= 0)
then
870 safe_allocate(x(1:npoints))
871 safe_allocate(y(1:npoints))
877 assert(splb%x_limit(2) >= splb%x_limit(1))
882 do i = npoints, 1, -1
883 if (x(i) > splb%x_limit(2) -
tol_x) cycle
886 new_npoints = new_npoints + 1
889 call spline_fit(new_npoints, x, y, spla, threshold)
901 type(
spline_t),
intent(inout) :: dspl
902 real(real64),
intent(in) :: threshold
904 integer :: npoints, i
905 real(real64),
allocatable :: x(:), y(:)
910 if (.not. c_associated(dspl%spl))
then
913 safe_allocate(x(1:npoints))
914 safe_allocate(y(1:npoints))
919 safe_allocate(x(1:npoints))
920 safe_allocate(y(1:npoints))
926 call spline_fit(npoints, x, y, dspl, threshold)
939 type(
spline_t),
intent(inout) :: dspl
940 real(real64),
intent(in) :: threshold
941 real(real64),
optional,
intent(in) :: grid(:)
943 integer :: npoints, i
944 real(real64),
allocatable :: x(:), y(:)
949 if (.not. c_associated(dspl%spl))
then
952 safe_allocate(x(1:npoints))
953 safe_allocate(y(1:npoints))
954 if (
present(grid))
then
962 safe_allocate(x(1:npoints))
963 safe_allocate(y(1:npoints))
969 call spline_fit(npoints, x, y, dspl, threshold)
981 integer,
intent(in) :: iunit
984 real(real64),
allocatable :: x(:), y(:)
990 safe_allocate(x(1:np))
991 safe_allocate(y(1:np))
996 write(iunit,
'(2es18.8E3)') x(i), y(i)
1000 safe_deallocate_a(y)
1009 type(
spline_t),
intent(in) :: spl(:)
1010 integer,
intent(in) :: iunit
1012 integer :: np, i, n, j
1013 real(real64),
allocatable :: x(:)
1014 real(real64) :: x_limit
1015 integer :: max_x_index
1025 x_limit = spl(1)%x_limit(2)
1030 if (x_limit < spl(i)%x_limit(2))
then
1031 x_limit = spl(i)%x_limit(2)
1037 safe_allocate(x(1:np))
1041 write(iunit,
'(es18.8E3)', advance=
'no') x(i)
1043 if (x(i) <= spl(j)%x_limit(2))
then
1044 write(iunit,
'(es18.8E3)', advance=
'no')
spline_eval(spl(j), x(i))
1046 write(iunit,
'(es18.8E3)', advance=
'no') m_zero
1049 write(iunit,
'(a)', advance=
'yes')
''
1052 safe_deallocate_a(x)
1061 type(
spline_t),
intent(in) :: spl(:, :)
1062 integer,
intent(in) :: iunit
1064 integer :: np, i, n1, n2, j, k
1065 real(real64),
allocatable :: x(:)
1066 real(real64) :: x_limit
1067 integer :: max_x_index(2)
1073 if (n1 * n2 <= 0)
then
1080 x_limit = spl(1,1)%x_limit(2)
1083 if (x_limit < spl(i,j)%x_limit(2))
then
1084 x_limit = spl(i,j)%x_limit(2)
1085 max_x_index = (/i,j/)
1090 np =
oct_spline_npoints(spl(max_x_index(1), max_x_index(2))%spl, spl(max_x_index(1), max_x_index(2))%acc)
1091 safe_allocate(x(1:np))
1093 call oct_spline_x(spl(max_x_index(1), max_x_index(2))%spl, x(1))
1096 write(iunit,
'(es18.8E3)', advance=
'no') x(i)
1099 if (x(i) <= spl(j,k)%x_limit(2))
then
1100 write(iunit,
'(es18.8E3)', advance=
'no')
spline_eval(spl(j, k), x(i))
1102 write(iunit,
'(es18.8E3)', advance=
'no') m_zero
1106 write(iunit,
'(a)', advance=
'yes')
''
1109 safe_deallocate_a(x)
1120 real(real64),
intent(in) :: threshold
1123 real(real64),
parameter :: dx = 0.01_real64
1126 assert(spl%x_limit(2) >= spl%x_limit(1))
1128 call profiling_in(
'SPLINE_CUTOFF_RADIUS')
1130 jj =
floor(spl%x_limit(2)/dx) + 1
1133 do while(dx*(jj-1) > spl%x_limit(2) - m_half * dx)
1142 call profiling_out(
'SPLINE_CUTOFF_RADIUS')
1151 range = this%x_limit(1)
1160 range = this%x_limit(2)
1167 real(real64),
allocatable,
intent(inout) :: x_shifted(:)
1169 real(real64),
allocatable :: x(:)
1170 integer :: npoints, i
1177 safe_allocate(x(1:npoints))
1178 safe_allocate(x_shifted(1:npoints))
1180 do i = 1, npoints -1
1181 x_shifted(i) = m_half*(x(i) + x(i+1))
1183 x_shifted(npoints) = x(npoints)
1184 safe_deallocate_a(x)
Both the filling of the function, and the retrieval of the values may be done using single- or double...
Some operations may be done for one spline-function, or for an array of them.
The integral may be done with or without integration limits, but we want the interface to be common.
double exp(double __x) __attribute__((__nothrow__
double sin(double __x) __attribute__((__nothrow__
double sqrt(double __x) __attribute__((__nothrow__
double floor(double __x) __attribute__((__nothrow__
subroutine, public spline_der(spl, dspl, threshold)
subroutine spline_end_0(spl)
subroutine, public spline_force_pos(spl, threshold)
real(real64) pure function spline_integral_limits(spl, a, b)
subroutine, public spline_fit(nrc, rofi, ffit, spl, threshold)
real(real64) function, public spline_x_threshold(spl, threshold)
Determines the largest value of x for which the spline values are above the threshold.
subroutine, public spline_3dft(spl, splw, threshold, gmax)
subroutine, public spline_der2(spl, dspl, threshold, grid)
Returns a spline that contains the second derivative of the original spline.
subroutine spline_end_2(spl)
real(real64), parameter tol_x
Tolerance for checking if x is inside or outside the limits of the splines.
subroutine, public spline_besselft(spl, splw, l, threshold, gmax)
real(real64) pure function, public spline_range_min(this)
subroutine spline_end_1(spl)
subroutine spline_print_1(spl, iunit)
Print debug information for a 1D array of splines.
real(real64) function spline_integral_full(spl)
real(real64) function, public spline_eval(spl, x)
subroutine spline_init_0(spl)
subroutine spline_print_0(spl, iunit)
subroutine spline_print_2(spl, iunit)
Print debug information for a 2D array of splines.
subroutine spline_eval8_array(spl, nn, xf)
subroutine spline_init_1(spl)
subroutine, public spline_cut(spl, cutoff, beta, threshold)
subroutine, public spline_div(spla, splb, threshold)
Returns the values of spla divided by the values of splb.
real(real64) pure function, public spline_range_max(this)
subroutine, public spline_times(a, spl, threshold)
subroutine spline_init_2(spl)
subroutine, public spline_mult(spla, splb, threshold)
subroutine spline_evalz_array(spl, nn, xf)
subroutine, public spline_generate_shifted_grid(this, x_shifted)
the basic spline datatype