Hello everyone

I am quite experienced with FORTRAN but I really have problems with this issue.

I am trying to make the following code, where I want to use something

like function overloading, by setting one argument of one function to a

definite value when it is called (see NON working line)

I do not want to put the variable a as a global one for

parallel-processing reasons, but I cannot think of any way to make this

code work

Any help would be greatly appreciated

Best regards

Vincent

program dbg

implicit none

integer, parameter :: N = 10

real, dimension(N) :: xval

real :: junk

integer :: i

interface

function f1(x) result(res)

implicit none

real :: x, res

end function f1

end interface

interface

function f2(x, a) result(res)

implicit none

real :: x, res, a

end function f2

end interface

do i = 1, N

xval(i) = (i-1.)/N*5.

print *, "INIT :", xval(i), f1(x=xval(i)), f2(x=xval(i), a=2.)

end do

call print_values(xval, N, f=f1)

! call print_values(xval, N, f=f2(SOMETHING, a=2.)) <=== WILL NOT WORK

contains

subroutine print_values(x, npts, f)

implicit none

interface

function f(x) result(res)

implicit none

real :: x

real :: res

end function f

end interface

real :: junk

integer :: i, npts

real, dimension(:) :: x

do i = 1, npts

junk = f(x(i))

print *, x(i), junk

end do

end subroutine print_values

end program dbg

function f1(x) result(res)

real :: res, x

res = 2.*x

end function f1

function f2(x, a) result(res)

real :: res, x

real :: a

res = 2.*x*a

end function f2