Skip to main content
Engineering LibreTexts

15.2: Program Layout

  • Page ID
    54358
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    The functions and subroutines can be defined as either internal or external. Internal functions and subroutines are defined within the program statement (i.e., before the “end program <name>” statement). The basic layout for both internal and external subprograms are as follows:

    program <name>
    
        <declarations>
        <program statements>
        
    contains
    
        <internal functions or subroutines>
        
    end program <name>
    
        <external functions or subroutines>
    

    Where a combination of both or either internal or external routines is allowed.

    Internal Routines

    Internal routines require the keyword “contains” to separate them from the program code. Primarily, internal routines will be used in this text for simplicity. There is no limit to the number of internal routines. However, if too many routines are included the file will become large and such large files can be difficult to work with.

    External Routines

    External functions are defined outside the program statement (i.e., after the “end program <name>” statement) or in another file. For larger programs, external routines would be used extensively. However, additional set-up statements, including an external declaration and an interface block, are required. The definition and use of external routines are not addressed in this chapter.


    This page titled 15.2: Program Layout is shared under a CC BY-NC-SA 3.0 license and was authored, remixed, and/or curated by Ed Jorgensen via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.

    • Was this article helpful?