Separate module subprograms (Fortran 2008)

A separate module subprogram defines a separate module procedure that is declared by a corresponding module procedure interface body.

Syntax

Separate module subprogram
Read syntax diagramSkip visual syntax diagram
>>-separate_module_subprogram_statement------------------------><

Read syntax diagramSkip visual syntax diagram
>>-+--------------------+--------------------------------------><
   '-specification_part-'   

Read syntax diagramSkip visual syntax diagram
>>-+----------------+------------------------------------------><
   '-execution_part-'   

Read syntax diagramSkip visual syntax diagram
>>-+--------------------------+--------------------------------><
   '-internal_subprogram_part-'   

Read syntax diagramSkip visual syntax diagram
>>-end_separate_module_subprogram_statement--------------------><

separate_module_subprogram_statement
For syntax details, see MODULE PROCEDURE.
specification_part
It is a sequence of statements from the statement groups numbered  2 ,  4  and  5  in Order of statements and execution sequence.
execution_part
It is a sequence of statements from the statement groups numbered  4  and  6  in Order of statements and execution sequence, which must begin with a statement from statement group  6 .
internal_subprogram_part
For details, see Internal procedures.
end_separate_module_subprogram_statement
For syntax details, see END.

Rules

The interface of a separate module subprogram must be declared by a module procedure interface body in one of the following places:
  • The specification_part of the program unit where the separate module procedure is defined.
  • The ancestor module.
  • An ancestor submodule.

If a separate module procedure that is defined by a separate module subprogram is a function, the variable name of the function result is determined by the FUNCTION statement in the corresponding module procedure interface body.

Example

This example shows how a separate module procedure is defined by a separate module subprogram in a submodule.

MODULE m
  INTEGER :: i

  INTERFACE
    MODULE SUBROUTINE sub(arg)
      INTEGER :: arg
    END SUBROUTINE
  END INTERFACE
END MODULE

SUBMODULE (m) n
  INTEGER :: j

  CONTAINS
    MODULE PROCEDURE sub       ! Separate module subprogram
      arg = 1
      i = 2
      j = 3
    END PROCEDURE
END SUBMODULE  


Voice your opinion on getting help information Ask IBM compiler experts a technical question in the IBM XL compilers forum Reach out to us