I encounter a problem when I try to compile a source code with the following module: the Intel Visual Fortran compiler would show a runtime error saying that
error#8169: The specified interface is not declared. [FUNCTION_TEMPLATE] at line 15
while the Portland Visual Fortran compiler could run it without issuing any warning. What is wrong?
01 MODULE toolbox
02 IMPLICIT NONE
03 ABSTRACT INTERFACE
04 FUNCTION function_template(x) RESULT(y)
05 IMPLICIT NONE
06 REAL, DIMENSION(:) :: x
07 REAL, DIMENSION(SIZE(x)) :: y
08 END FUNCTION function_template
09
10 FUNCTION penalty_template(x,fvec_p,proc_p) RESULT(y)
11 IMPLICIT NONE
12 REAL, DIMENSION(:) :: x
13 REAL, DIMENSION(:), POINTER :: fvec_p
14 REAL :: y
15 PROCEDURE(function_template), POINTER :: proc_p
16 END FUNCTION penalty_template
17 END INTERFACE
18 CONTAINS
19 ...
20 END MODULE toolbox
In Fortran 2003 interface bodies do not, by default, inherit entities defined in their host scope. Therefore, while the name function_template
is defined in the host (through the first interface body), it is not defined in the second interface body.
You can import declarations from the host using an IMPORT statement. An IMPORT statement before the IMPLICIT NONE directs that all entities from the host scope are inherited by the interface body. You can restrict what is imported by listing the relevant identifiers after the import keyword which, from a style and code documentation point of view, I think is a good idea.
The Portland compiler is in error if it does not diagnose this.
(In Fortran 2008 interface bodies for separate module procedures do inherit from their host, but that is not applicable here.)