Skip to main content
Engineering LibreTexts

4.2: Data Types

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

    \( \newcommand{\vectorA}[1]{\vec{#1}}      % arrow\)

    \( \newcommand{\vectorAt}[1]{\vec{\text{#1}}}      % arrow\)

    \( \newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vectorC}[1]{\textbf{#1}} \)

    \( \newcommand{\vectorD}[1]{\overrightarrow{#1}} \)

    \( \newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}} \)

    \( \newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}} \)

    \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

    \(\newcommand{\avec}{\mathbf a}\) \(\newcommand{\bvec}{\mathbf b}\) \(\newcommand{\cvec}{\mathbf c}\) \(\newcommand{\dvec}{\mathbf d}\) \(\newcommand{\dtil}{\widetilde{\mathbf d}}\) \(\newcommand{\evec}{\mathbf e}\) \(\newcommand{\fvec}{\mathbf f}\) \(\newcommand{\nvec}{\mathbf n}\) \(\newcommand{\pvec}{\mathbf p}\) \(\newcommand{\qvec}{\mathbf q}\) \(\newcommand{\svec}{\mathbf s}\) \(\newcommand{\tvec}{\mathbf t}\) \(\newcommand{\uvec}{\mathbf u}\) \(\newcommand{\vvec}{\mathbf v}\) \(\newcommand{\wvec}{\mathbf w}\) \(\newcommand{\xvec}{\mathbf x}\) \(\newcommand{\yvec}{\mathbf y}\) \(\newcommand{\zvec}{\mathbf z}\) \(\newcommand{\rvec}{\mathbf r}\) \(\newcommand{\mvec}{\mathbf m}\) \(\newcommand{\zerovec}{\mathbf 0}\) \(\newcommand{\onevec}{\mathbf 1}\) \(\newcommand{\real}{\mathbb R}\) \(\newcommand{\twovec}[2]{\left[\begin{array}{r}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\ctwovec}[2]{\left[\begin{array}{c}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\threevec}[3]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\cthreevec}[3]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\fourvec}[4]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\cfourvec}[4]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\fivevec}[5]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\cfivevec}[5]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\mattwo}[4]{\left[\begin{array}{rr}#1 \amp #2 \\ #3 \amp #4 \\ \end{array}\right]}\) \(\newcommand{\laspan}[1]{\text{Span}\{#1\}}\) \(\newcommand{\bcal}{\cal B}\) \(\newcommand{\ccal}{\cal C}\) \(\newcommand{\scal}{\cal S}\) \(\newcommand{\wcal}{\cal W}\) \(\newcommand{\ecal}{\cal E}\) \(\newcommand{\coords}[2]{\left\{#1\right\}_{#2}}\) \(\newcommand{\gray}[1]{\color{gray}{#1}}\) \(\newcommand{\lgray}[1]{\color{lightgray}{#1}}\) \(\newcommand{\rank}{\operatorname{rank}}\) \(\newcommand{\row}{\text{Row}}\) \(\newcommand{\col}{\text{Col}}\) \(\renewcommand{\row}{\text{Row}}\) \(\newcommand{\nul}{\text{Nul}}\) \(\newcommand{\var}{\text{Var}}\) \(\newcommand{\corr}{\text{corr}}\) \(\newcommand{\len}[1]{\left|#1\right|}\) \(\newcommand{\bbar}{\overline{\bvec}}\) \(\newcommand{\bhat}{\widehat{\bvec}}\) \(\newcommand{\bperp}{\bvec^\perp}\) \(\newcommand{\xhat}{\widehat{\xvec}}\) \(\newcommand{\vhat}{\widehat{\vvec}}\) \(\newcommand{\uhat}{\widehat{\uvec}}\) \(\newcommand{\what}{\widehat{\wvec}}\) \(\newcommand{\Sighat}{\widehat{\Sigma}}\) \(\newcommand{\lt}{<}\) \(\newcommand{\gt}{>}\) \(\newcommand{\amp}{&}\) \(\definecolor{fillinmathshade}{gray}{0.9}\)

    Fortran, like many other high level programming languages, supports several different data types to make data manipulation easier. The most frequently used data types are integer and floating-point. Other data types are complex numbers, characters and logical data.

    In a Fortran statement, data can appear either as a literal (e.g., an actual value such as 3.14159, 16, -5.4e-4) or as a variable name which identifies a location in memory to store the data.

    The five basic Fortran 95/2003/2008 data types are as follows:

    Type Description
    integer Variable that is an integer or whole number (not a fraction) that can be positive, negative, or zero.
    real Variable that can be set to a real number.
    complex Variable that can be set to a complex number
    character Variable that is a character or sequence of characters.
    logical Variable that can only be set to .true. or .false.

    It is also possible to have derived types and pointers. Both of these can be useful for more advanced programs and are described in later chapters.

    Integer

    An integer1 is a whole number (not a fraction) that can be positive, negative, or zero. Examples include the numbers 10, 0, -25, and 5,148. Integers are the numbers people are most familiar with, and they serve a crucial role in mathematics and computers. All integers are whole numbers, so operations like one divided by two (1/2) is 0 since the result must be a whole number. For integer division, no rounding will occur as the fractional part is truncated.

    Real

    A real number2 includes the fractional part, even if the fractional part is 0. Real numbers, also referred to as floating-point numbers, include both rational numbers and irrational numbers. Examples of irrational numbers or numbers with repeating decimals include \(\pi\), \(\sqrt{2}\) and \(e\). Additional examples include 1.5, 5.0, and 3.14159. Fortran 95/2003/2008 will accept 5. as 5.0. All examples in this text will include the “.0” to ensure clarity.

    Complex

    A complex number3, in mathematics, is a number comprising a real number and an imaginary number. It can be written in the form of \(a + bi\), where \(a\) and \(b\) are real numbers, and the \(i\) is the standard imaginary unit with the property that \(i^2 = −1.0\). The complex numbers contain the ordinary real numbers, but extend them by adding in extra numbers like an extra dimension. This data type is not used extensively, but can be useful when needed.

    Character

    A character4 is a symbol like a letter, numerical digit, or punctuation. A string5 is a sequence or set of characters. Characters and strings are typically enclosed in quotes. For example, the upper case letter “Z” is a character and “Hello World” is a string. The characters are represented in a standardized format referred to as ASCII.

    Logical

    A logical6 is only allowed to have two values, true or false. A logical can also be referred to as a boolean. In Fortran, the true and false values are formally expressed as .true. or .false. which are also called logical constants. The leading and trailing . (period) are required for the true and false constants.

    Historical Data Typing

    Unless a variable was explicitly typed, older versions of Fortran implicitly assumed a type for a variable depending on the first letter of its name. Thus, if not explicitly declared, a variable whose name started with one of the letters I through N was assumed to be an integer; otherwise it was assumed to be real. To allow older code to run, Fortran 95/2003/2008 permits implicit typing. However, this is poor practice, can be confusing, and often leads to errors. So, we will include the IMPLICIT NONE statement at the start of all programs. This turns off implicit typing and the compiler will identify and flag any variable not defined. This will help make some errors, such as misspelling a variable name, significantly easier to locate.


    1. For more information regarding integers, refer to: http://en.Wikipedia.org/wiki/Integer
    2. For more information regarding real numbers, refer to: http://en.Wikipedia.org/wiki/Real_numbers
    3. For more information regarding complex numbers, refer to: http://en.Wikipedia.org/wiki/Complex_number
    4. For more information regarding characters, refer to: http://en.Wikipedia.org/wiki/Character_(computing)
    5. For more information regarding strings, refer to: http://en.Wikipedia.org/wiki/String_(computer_science)
    6. For more information regarding logicals, refer to: http://en.Wikipedia.org/wiki/Boolean_data_type

    This page titled 4.2: Data Types 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.

    • Was this article helpful?