Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass an elemental procedure to another elemental procedure

Tags:

fortran

I would like to pass an elemental procedure to another elemental procedure. A minimum working example might be something like this:

elemental real function func(x, f_dummy)
    implicit none

    real, intent(in) :: x
    interface
        elemental real function f_dummy(x)
            real, intent(in) :: x
        end function f_dummy
    end interface

    func = 2.0 * f_dummy(x)

    return
end function func

The compiler says:

Error: Dummy procedure ‘f_dummy’ not allowed in elemental procedure ‘func’ at (1)

If I delete all instances of elemental, then it compiles.

Is there a legal way to pass an elemental procedure to another elemental procedure?

like image 268
David Hansen Avatar asked Dec 13 '25 13:12

David Hansen


1 Answers

No, the arguments of an elemantal procedure must be scalars, not arrays, not procedures. As a workaround you can write a procedure that deals with an array and the procedure and is just pure, not elemental.

Elemental procedures can be dummy arguments. But an argument of an elemental procedure cannot be a procedure. Perhaps it could be a procedure pointer, but then you would have to pass an array of pointers when calling it elementally on an array.

like image 155
Vladimir F Героям слава Avatar answered Dec 16 '25 22:12

Vladimir F Героям слава