Skip to main content
Engineering LibreTexts

15: Subprograms

  • Page ID
    54224
  • \( \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}}\)

    Until now, all of the programs have essentially been single, fairly small programs. However, as we scale up into larger programs, this methodology will become more difficult. When developing larger programs, it becomes necessary to break larger programs up into multiple, smaller more manageable pieces. Then, during program development, it is possible to focus on each subsection or piece individually and then combine the results into a final complete program. And, for very large projects, multiple people may work on different parts of the program simultaneously.

    Some of the key advantages of developing a program using functions and/or subroutines include:

    • Structured development of programs
    • Reuse of subprograms
    • Isolation of subprograms

    Fortran subprograms are the mechanism to break a large program into multiple smaller parts. This allows for a more comprehensive program design.

    • 15.1: Subprogram Types
      There are two types of Fortran subprograms: functions and subroutines.
    • 15.2: Program Layout
      The functions and subroutines can be defined as either internal or external.
    • 15.3: Arguments
      When writing and using Fortran subprograms, it is typically necessary to provide data to a subprogram and/or to obtain results back from the functions or subroutines. This information, in the form of variables, is referred to as an argument or arguments.
    • 15.4: Variable Scope
      The variable scope refers to where a given variable can be accessed.
    • 15.5: Using Functions and Subroutines
      Before a function or subroutine can be used, it must be defined or written. Once defined, the function or subroutine can be used or called.
    • 15.6: Functions
      A function is a special type of Fortran subprogram that is expected to return a single result or answer. A function will typically accept some kind of input information and based on that information, return a result.
    • 15.7: Subroutines
      A subroutine is a Fortran subprogram that can accept some kind of input information and based on that information, return a result or series of results.
    • 15.8: Example
      In this example, we will write a Fortran program to simulate the dice game of Twenty-Six, which is a single player betting game with 10 dice.
    • 15.9: Exercises


    This page titled 15: Subprograms 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?