0

I have many functions defined as below:

function f1(x) result (y)
    ...
end function

function f2(x) result (y)
    ...
end function

...

function fn(x) result (y)
    ...
end function

I'm looking for an automatic way to call each one over some input x(i) and print the results. A prototype would be:

f = (/f1, f2, ..., fn/)
do i=1,m
    do j=1,n
        y = f(j)(x(i))
        write(*, *) y
    end do
end do

Of course, this doesn't work. I've triede some goto approach, but aliasing function names doesn't seem to be allowed at all.

Note: I'm using Fortran95.

Pedro
  • 1,121
  • 7
  • 16
  • Even though the title of the linked answer is different, you can see that it actually tries to do the same, first to make an array, as you tried, and then tries to call it in sequence, as you tried as well. – Vladimir F Героям слава Oct 03 '20 at 18:15
  • Note that function pointers are a Fortran 2003 feature. However, there is no other feature in Fortran 95 that you could use instead. Your compiler will very likely support it. If you want modern advanced structures and objects, you need Fortran 2003 or later. (We have year 2020 now.) – Vladimir F Героям слава Oct 03 '20 at 18:16

0 Answers0