Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28456 Discussions

Passing user-defined function as argument

hugochief
Beginner
291 Views
Hello,
I am somewhat new to Fortran and I just bought a subscription for ifort on Mac OS X. When I try compiling my code something goes wrong.
Here is my main program:
...
use func
use mult
...
print*, my_function(func,dfunc)
...

where both func and dfunc are defined in module "func":
...
function func(x)
real :: func
...
endfunction func

function dfunc
real, dimension(2) :: dfunc
...
endfunction dfunc

Also, "my_function" is defined in module "mult" likewise:
...
function my_function(func,dfunc)
real, external :: func
real, external :: dfunc
...
endfunction my_function

I get this error at compile-time:
"The shape matching rules of actual arguments and dummy arguments have been violated" referring to dfunc, which is an array of size 2.
What should I do to fix my problem?

Thanks!!
0 Kudos
1 Reply
jimdempseyatthecove
Honored Contributor III
291 Views

my_func defines return type as scalar real for both external arguments. Whereas call to my_func passes two arguments each a rank 1 array of real dimensioned to 2. I have not tried the following to see if it is valid

function my_function(func,dfunc)
real, dimension(2), external :: func
real, dimension(2), external :: dfunc


You must resolve the shape matching rules.

Jim Dempsey
0 Kudos
Reply