Internal procedures as dummy arguments in gfortran?
Miguel Hermanns
hermanns@tupi.dmt.upm.es
Thu Sep 24 08:02:00 GMT 2009
Hi Arjen,
thanks for the example, but as you say there are several limitations.
Additionally, the subroutine, in your case integrate_fg, must have
access to the eval_at function through host association, and that is a
very strong limitation, since every time you want to expand the
functionality, you need to copy the lines of the venerable subroutine to
each of the new subroutines you create, since otherwise you never have
access to the corresponding eval_at function through host association.
Imagine the extreme case where you want to use instead a compiled
subroutine, be it IMSL, MKL or what ever. That is the case I like to
think and design on, because there the code is perfectly separated in
its functionality and it is much easier to develop, structure, validate.
I know I'm picky :-)
Best regards,
Miguel
Arjen Markus wrote:
> Hi Miguel,
>
> it may not be completely satisfactory, but here is an example/sketch
> of how you can do
> that sort of things without passing internal procedures as actual arguments:
>
> ! integrate.f90 --
> ! Sketch of how to integrate f(g(x)) without resorting
> ! to internal procedures passed as actual arguments
> !
> module integration
>
> implicit none
>
> contains
> subroutine integrate_fg( xbegin, xend, f, g, result )
> real, intent(in) :: xbegin
> real, intent(in) :: xend
> real, intent(out) :: result
>
> interface
> real function f( x )
> real, intent(in) :: x
> end function f
>
> real function g( x )
> real, intent(in) :: x
> end function g
> end interface
>
> !
> ! Note: the venerable integration routine should not
> ! use a function argument, but instead use the
> ! function eval_at() - see below
> !
> call integrate_venerable( xbegin, xend, result )
>
> !
> ! Second level "contains"
> contains
>
> subroutine integrate_venerable( xbegin, xend, result )
>
> ...
>
> fvalue = eval_at( x ) ! This evaluates the integrand
>
> ...
>
> end subroutine integrate_venerable
>
> real function eval_at( x )
> real, intent(in) :: x
>
> real :: gx
>
> gx = g( x )
> eval_at = f( gx )
>
> end function eval_at
>
> end subroutine integrate_fg
>
> end module integration
>
>
> The problems with the above are:
> - A different interface for the integration routines (you can not use
> a dummy procedure argument)
> - The code for the integration needs to be available and possibly
> modified for use as an internal routine
>
> Nevertheless, the overall routine "integrate_fg" can be put into a
> library, making the distribution
> easier.
>
> Regards,
>
> Arjen
>
More information about the Fortran
mailing list