Can I load inline functions using the USE statement?

I am currently playing with passing functions as arguments.

In the program below, I use the built-in function EXPas an argument for an integral function. My compiler gives me the following error:

integrate1.f90:22.26:

r = integral(-1.0,1.0,EXP,1000);
                      1
Error: Expected a procedure for argument 'f' at (1)

If I uncomment the use EXPof a variable in a declaration r, I do not get this error.

So it seems that if I do not use the built-in function, I cannot use it as an argument, which is kind of strange, because the β€œbuilt-in” type assumes that the function is loaded no matter what.

How to prevent this error without using the function explicitly EXP? Do I need to use the instructions USEto download the built-in? If there is no other way around this, I would be interested to know if this is due to the Fortran specification or the compiler problem?

I use GNU Fortran (Ubuntu/Linaro 4.7.3-1ubuntu1) 4.7.3.

Example:

MODULE MINTEGRATE
CONTAINS
FUNCTION integral(from,to,f,n)
    INTERFACE
        FUNCTION f(y); REAL, INTENT(IN) :: y; END FUNCTION
    END INTERFACE
    REAL :: from,to,integral,width;
    INTEGER :: n;

    width=ABS(to-from)/n;
    integral = 0.0;
    DO i=0,n
        integral = integral+f(from+width*i)*width;
    END DO
END
END

PROGRAM INTEGRATE
USE MINTEGRATE;

!PROCEDURE(EXP), POINTER :: f => EXP; ! using the variable f below works without error
REAL :: r!=EXP(0.0);
r = integral(-1.0,1.0,EXP,1000);
WRITE(*,*) r;
END
+4
source share
1 answer

" , , . . ( , . , )." Intel Fortran.

, exp exp, , . , , alog.

, exp:

intrinsic exp

.

+6

All Articles