Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29418 Discussions

Is it possible to have an optional, external subroutine argument?

OP1
New Contributor III
867 Views
I would like to do something like this:

SUBROUTINE MY_SUB(I,J,K,SUB)
INTEGER,INTENT(INOUT) :: I,J,K
EXTERNAL,OPTIONAL :: SUB
INTERFACE
SUBROUTINE SUB(H)
INTEGER,INTENT(IN) ::H
END SUBROUTINE SUB
END INTERFACE
... do some work here...
END SUBROUTINE MY_SUB

In other words, I want to pass an external subroutine as an optional argument. The example above will not compile in IVF 10. Is there another way to do this?

Thanks!

Olivier
0 Kudos
2 Replies
Steven_L_Intel1
Employee
867 Views
Drop the EXTERNAL - that's the real problem. You can use either EXTERNAL or INTERFACE - not both. INTERFACE is preferred.
0 Kudos
OP1
New Contributor III
867 Views
Drop the EXTERNAL - that's the real problem. You can use either EXTERNAL or INTERFACE - not both. INTERFACE is preferred.

Oh, I see. Thanks Steve. I also had forgotten that OPTIONAL can be used by itself (as a statement) in addition to being used as part of a type declaration statement.
This works great.

Thanks!

Olivier
0 Kudos
Reply