Fortran Internal subprograms


Example

A program unit which is not an internal subprogram may contain other program units, called internal subprograms.

program prog
  implicit none
contains
  function f()
  end function f
  subroutine g()
  end subroutine g
end program

Such an internal subprogram has a number of features:

  • there is host association between entities in the subprogram and the outer program
  • implicit typing rules are inherited (implicit none is in effect in f above)
  • internal subprograms have an explicit interface available in the host

Module subprograms and external subprograms may have internal subprograms, such as

module mod
  implicit none
contains
  function f()
  contains
    subroutine s()
    end subroutine s
  end function f
end module mod