I have a subroutine that I use for root-finding. One of the inputs of the subroutine is the name of an objective function, which inside the subroutine is declared as an interface. I use this root-finding subroutine for several objective functions in my main program. So ideally, when the subroutine fails in solving the problem, I would like to see the name of the function for which it failed. Is this possible?
This is an example code
subroutine mysolver(xl,xr,FN, x_sol)
real, intent(inout) :: xl,xr
real, intent(out) :: x_sol
real :: fl,fr
interface
real function FN(y)
real, intent(in) :: y
end function FN
end interface
fl = FN(xl)
fr = FN(xr)
if (fl*fr > 0.0) then
print *, 'Error solving function'
end if
! More (non-relevant) stuff happens here
end subroutine mysolver
When the solver fails, i.e. when fl*fr>0
, the subroutine prints "Error solving function"
, but I would like it to print "Error solving function FN"
, for whatever FN
is. How can I achieve this?