Skip to main content
Engineering LibreTexts

3.2: Program Formats

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

    Fortran 95/2003/2008 programs must be written and formatted in a specific manner. The following sections summarize the basic program elements followed by a simple example.

    Program Statement

    A Fortran 95/2003/2008 program is started with a program statement, 'program <name>', and ended with an end program statement, 'end program <name>'. Refer to the example first program to see an example of these statements. The program name for <name> is chosen by the program author and would typically reflect something related to what the program does.

    The name used may not be used again for other program elements (such as variables described in the next chapter). The program name must start with a letter, followed by letters, numbers, or an underscore (“_”) and may not be longer than 32 characters. Capital letters are treated the same way as lower-case letters. Refer to the sample program in the following sections for an example.

    Comments

    Comments are information for the programmer and are not read by the computer. For example, comments typically include information about the program. For programming assignments, the comments should include the programmer name, assignment number, and a brief description of the program. In Fortran, the exclamation mark (!) denotes a comment. Any characters after the exclamation mark (!) are ignored by the compiler and thus are comments as shown in following example.

    Simple Output

    A program can display a simple message to the screen by using the write statement. For example:

    write (*,*) "Hello World"
    

    Will display the message Hello World to the screen. Additional information regarding the write statement and outputting information is provided in later chapters.

    Example — First Program

    The following trivial program illustrates the initial formatting requirements.

    ! Simple Example Program
    program first
        write (*,*) "Hello World."
    end program first
    

    In this example, the program is named 'first'. This file, provided as input to the compiler, is typically referred to as the source file.


    This page titled 3.2: Program Formats 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?