Ask a question
Fuel your AI at the ultimate IBM learning event
IBM TechXchange Conference October 21-24, 2024 Mandalay Bay - Las Vegas
Originally posted by: Ka_Lin
Authors: Ka Lin, Daniel Chen
A submodule extends a module or another submodule. It can also have its descendant submodules. You can declare a module procedure interface body in a module and define it in one of the descendant submodules. A submodule access entities in its ancestor module or submodules through host association. Here is an example: MODULE m ! The ancestor module m INTEGER :: i ! Two module procedure interface bodies, sub1 and sub2, are declared in module m. INTERFACE MODULE SUBROUTINE sub1(arg1) ! Module procedure interface body for sub1 INTEGER :: arg1 END SUBROUTINE MODULE SUBROUTINE sub2(arg2) ! Module procedure interface body for sub2 INTEGER :: arg2 END SUBROUTINE END INTERFACE END MODULE SUBMODULE (m) n ! Submodule n that extends module m. INTEGER :: j INTERFACE MODULE SUBROUTINE sub3(arg3) ! Module procedure interface body for sub3 INTEGER :: arg3 END SUBROUTINE END INTERFACE CONTAINS ! Module procedure interface body sub1 is defined as follows in submodule n." MODULE SUBROUTINE sub1(arg1) INTEGER :: arg 1 arg1 = 1 i = 2 ! i declared in module m is accessed by host association. j = 3 ! Host association END SUBROUTINE ! You can also define a module procedure interface body using the module procedure subprogram ! statement that allows you to omit the argument list and the function result type if the module ! procedure is a function. ! Module procedure interface body sub2 is defined using the module procedure subprogram statement ! as follows in submodule n. MODULE PROCEDURE sub2 arg2 = 1 END PROCEDURE END SUBMODULE SUBMODULE (m:n) p ! Submodule p that extends the parent submodule n. INTEGER :: k CONTAINS ! Module procedure interface body sub3 is defined as follows in submodule p. MODULE SUBROUTINE sub3(arg3) INTEGER :: arg 3 arg3 = 3 k = 4 ! Host association END SUBROUTINE END SUBMODULE For syntax details and rules of a submodule, see: http://www.ibm.com/support/knowledgecenter/SSAT4T_15.1.0/com.ibm.xlf151.linux.doc/language_ref/submodules.html
Originally posted by: JackLee1