Internal procedures
External subprograms, module subprograms, and main programs can have internal subprograms, whether the internal subprograms are functions or subroutines, as long as the internal subprograms follow the CONTAINS statement.
An internal procedure is defined by an internal subprogram. Internal
subprograms cannot appear in other internal subprograms. A module
procedure is defined by a module subprogram or an entry in a module
subprogram. Internal procedures and module procedures are the same
as external procedures except that:
- The name of an internal procedure or module procedure is not a global entity.
- An internal procedure must not contain an ENTRY statement.
- The name of an internal procedure must not be an argument associated with a dummy procedure.
- The internal procedure has access to host entities by host association.
- The BIND attribute with the NAME= specifier is not allowed on an internal procedure.
Migration Tip:
Turn your external procedures into internal subprograms or put them into modules. The explicit interface provides type checking.
FORTRAN 77 source
PROGRAM MAIN
INTEGER A
A=58
CALL SUB(A) ! A must be passed
END
SUBROUTINE SUB(A)
INTEGER A,B,C ! A must be redeclared
C=A+B
END
Fortran 90/95/2003 source:
PROGRAM MAIN
INTEGER :: A=58
CALL SUB
CONTAINS
SUBROUTINE SUB
INTEGER B,C
C=A+B ! A is accessible by host association
END SUBROUTINE
END