Skip to main content
Engineering LibreTexts

10.6: Logical Format Specifier

  • Page ID
    54290
  • \( \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 logical format specifier rLw is used tell the system exactly how many positions should be used to either read or write an logical variable. The w is the width or how many total places are used. The r is the number of times the format specifier should be repeated. Since a logical variable can only be set to the logical constants .true. or .false. the width will specify how many of the characters logical constants will be read or displayed.

    For example, given the declarations,

    logical :: dooropen=.true., windowopen=.false.
    

    the following write statement can be used to display the value in the logical variables dooropen and windowopen with no leading or trailing spaces. It should be noted that only a T or F will be displayed. The following write statement,

    write (*,'(l1,1x,l1)') dooropen, windowopen
    

    will display “T F”. Note, the l1 format is lower-case L and number 1.

    The size or width can be adjusted as needed. For example, the following write statement,

    write (*,'(l3,2x,l3)') dooropen, windowopen
    

    will display “ T F” , which will display a total of 8 characters; two spaces and a T from the right justified L3 (__T), followed by 2 spaces from the 2X (__), and then two spaces followed by an F from the L3 (__F).


    This page titled 10.6: Logical Format Specifier 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.