Dear People,
My question can be distilled to this specific example. I need to write the interface for a subroutine that calculates the gradient of an arbitrary scalar function of a vector argument x. This should work in general for a function of 2 variables , 3 variables, etc. Thus, I am tempted to use an assumed shape for position argument x in the interface. In other words, I want to avoid having to put a specific dimension of argument x to the function being passed - otherwise the subroutine is not general for any dimension of space. The following attempts do not work, but I don't know why. I looked in the corresponding sections of Metcalf and two other books, but they do not cover this. Any comments will be gratefully received.
With many thanks, Ludwig
PS: The colon in the assumed shape is being turned into an emiticon, but you get the idea.
FIRST EXAMPLE (pass function as argument)
subroutine gradient (func,x,g) real, dimension(:), intent(in) :: x real, dimension(size(x)), intent(out) :: g interface function func (y) result (f) real, dimension(:), intent(in) :: y real :: f end function func end interface ... end subroutine gradient
SECOND EXAMPLE (pass function as argument)
subroutine gradient (func,x,g) real, dimension(:), intent(in) :: x real, dimension(size(x)), intent(out) :: g interface function func (y) result (f) real, dimension(size(x)), intent(in) :: y real :: f end function func end interface ... end subroutine gradient
THIRD EXAMPLE (pass subroutine as argument)
subroutine gradient (sbr,x,g) real, dimension(:), intent(in) :: x real, dimension(size(x)), intent(out) :: g interface subroutine sbr (y,f) real, dimension(:), intent(in) :: y real, intent(out) :: f end subroutine sbr end interface ... end subroutine gradient