Skip to main content
Engineering LibreTexts

16.1: Definition

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

    Before a derived data type can be used, it must be defined. The definition will establish which pieces of information will be grouped together. Each piece of information included in the definition is referred to as a component.

    type type_name
        <component definitions>
    end type type_name
    

    For example, to declare the student type described previously, the following declaration would be appropriate:

    type student
        character(50) :: name
        integer :: id
        real :: score
        character(2) :: grade
    end type student
    

    The indentation is not required, but does make the definition easier to read. The fields (name, id, score, grade) are called components. These components together make up the information for a 'student'.

    The type definition is required only once at the beginning of the program. Once defined, the type definition cannot be changed. More specifically, additional components cannot be added unless the definition is updated and the program is recompiled.

    This definition will establish a template as follows:

    A derived data type template.

    Once defined, the template can be used to declare variables. Each variable declared with this definition will be created based on the definition which includes these four components.


    This page titled 16.1: Definition 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?