Hello!
Assume that I have 2 procedure pointers, that can vary at runtime. Both procedures have the same interface. The interface takes in x,y,z real values in and returns also a real value. Now I would like to have procedure pointer to the product. Is this even possible?
I know that this is possible in matlab:
function func = get_linear_volume_basis(id)
switch id
case 1
func = @(x) 1-x(:,1)-x(:,2)-x(:,3);
case 2
func = @(x) x(:,1);
case 3
func = @(x) x(:,2);
case 4
func = @(x) x(:,3);
end
end
function prod = get_product(i,j)
func_i = get_linear_volume_basis(i)
func_j = get_linear_volume_basis(j)
prod = @(x) func_i(x) * func_j(x)
end
My current fortran code looks like this:
module BasisVolumeFunction_Module
implicit none
public :: get_linear_volume_basis_function
abstract interface
function integrand(x, y, z) result(val)
real*8, intent(in) :: x, y, z
real*8 :: val
end function integrand
end interface
private
contains
function get_product(i,j) result(ptr)
integer :: i,j
procedure(integrand), pointer :: ptr
procedure(integrand), pointer :: func_i, func_j
func_i = get_linear_volume_basis_function(i)
func_j = get_linear_volume_basis_function(j)
! what to do here?
end function get_product
function get_linear_volume_basis_function(id) result(ptr)
integer :: id
procedure(integrand), pointer :: ptr
select case (id)
case (1)
ptr => linear_volume_basis_1
case (2)
ptr => linear_volume_basis_2
case (3)
ptr => linear_volume_basis_3
case (4)
ptr => linear_volume_basis_4
case default
print *, 'Error: incorrect id for linear volume basis used:', id
end select
end function get_linear_volume_basis_function
function linear_volume_basis_1(x, y, z) result(val)
real*8, intent(in) :: x, y, z
real*8 :: val
val = 1.0d0 - x - y - z
end function linear_volume_basis_1
function linear_volume_basis_2(x, y, z) result(val)
real*8, intent(in) :: x, y, z
real*8 :: val
val = x
end function linear_volume_basis_2
function linear_volume_basis_3(x, y, z) result(val)
real*8, intent(in) :: x, y, z
real*8 :: val
val = y
end function linear_volume_basis_3
function linear_volume_basis_4(x, y, z) result(val)
real*8, intent(in) :: x, y, z
real*8 :: val
val = z
end function linear_volume_basis_4
end module BasisVolumeFunction_Module