I have transformed a problem from a more complex f90-code into the following:
module userfunctions
implicit none
contains
function Function1(Argument,ArgumentSize)
! Input
integer, intent(in) :: ArgumentSize
real,dimension(ArgumentSize),intent(in) :: Argument
! Output
real,dimension(ArgumentSize) :: Function1
! Local
integer :: i
Function1 = Argument
! Random operation on argument, resembling generic vector function
do i=1,ArgumentSize
Function1(i) = Function1(i)**2
end do
end function Function1
function Function2(RandomFunction,Argument,ArgumentSize)
! Input
integer, intent(in) :: ArgumentSize
real,dimension(ArgumentSize), intent(in) :: Argument
! Array-type function of dimension ArgumentSize
real,external :: RandomFunction
! Evaluate RandomFunction to
real,dimension(ArgumentSize) :: Value
! Output
real :: Function2
! assign evaluation of RandomFunction to Value
Value = RandomFunction(Argument,ArgumentSize)
Function2 = dot_product(Value,Value)
end function Function2
end module userfunctions
program Fortran_Console_002
use userfunctions
implicit none
real :: Result1
real,dimension(6) :: Vector1
Vector1 = 2
Result1 = Function2(Function1,Vector1,6)
write(*,*) Result1
end program Fortran_Console_002
The result should be "96". Compiling this with Visual Studio 2013 and Intel Fortran produces the following error:
Error 1 error #6634: The shape matching rules of actual arguments and dummy arguments have been violated. [FUNCTION1]
In real context I do need to pass an array-valued function from a subroutine to a function defined in a module (a solver for nonlinear functions which takes functions as arguments). I do know how to do this for a scalar-valued function, but failed to apply this to an array.
I use Visual Studio 2013 for this because of convenience. The real piece has to be compiled using Compaq Visual Fortran 6 on a virtual machine which is, as of my knowledge, only compatible up to fortran90.