Skip to main content
Engineering LibreTexts

17.2: Use Statement

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

    Once the module is defined, the routines from the module can be included by using the use statement. The use statement or statements must be at the beginning of the applicable source file. For example, below is a simple main that uses the previous stats module.

    program average
    use stats
    
    implicit none
    real, dimension(1000) :: arr
    integer :: i, count
    real :: ave
    
    ! -----
    !  Initialize array with some values.
    
        count = 0
        do i = 1, 20
            arr(i) = real(i) + 10.0
            count = count + 1
        end do
    
    ! -----
    ! Call function to find average and display result.
    
        ave = arraverage(arr, count)
        
        write (*, '(/, a, f10.2, /)') "Average = ", ave
    
    end program average
    

    The use statement is included before the variable declarations. Any number of use statements for defined modules may be included.


    This page titled 17.2: Use Statement 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.