Go to main content
Oracle® Developer Studio 12.6: Fortran User's Guide

Exit Print View

Updated: July 2017

4.8 Directives

A compiler directive directs the compiler to do some special action. Directives are also called pragmas.

A compiler directive is inserted into the source program as one or more lines of text. Each line looks like a comment, but has additional characters that identify it as more than a comment for this compiler. For most other compilers, it is treated as a comment, so there is some code portability.

A complete summary of Fortran directives appears in Fortran Directives Summary.

4.8.1 Form of Special f95 Directive Lines

f95 recognizes its own special directives in addition to those described in Command-Line Help. These have the following syntax:

!DIR$ d1, d2, … Fixed-Form Source

  • Put CDIR$ or !DIR$ in columns 1 through 5.

  • Directives are listed in columns 7 and beyond.

  • Columns beyond 72 are ignored.

  • An initial directive line has a blank in column 6.

  • A continuation directive line has a nonblank in column 6. Free-Form Source

  • Put !DIR$ followed by a space anywhere in the line.

    The !DIR$ characters are the first nonblank characters in the line (actually, non-whitespace).

  • Directives are listed after the space.

  • An initial directive line has a blank, tab, or newline in the position immediately after the !DIR$.

  • A continuation directive line has a character other than a blank, tab, or newline in the position immediately after the !DIR$.

Thus, !DIR$ in columns 1 through 5 works for both free-form source and fixed-form source.

4.8.2 FIXED and FREE Directives

These directives specify the source form of lines following the directive line. Scope

They apply to the rest of the file in which they appear, or until the next FREE or FIXED directive is encountered. Uses

  • They allow you to switch source forms within a source file.

  • They allow you to switch source forms for an INCLUDE file. You insert the directive at the start of the INCLUDE file. After the INCLUDE file has been processed, the source form reverts back to the form being used prior to processing the INCLUDE file. Restrictions

The FREE/FIXED directives:

  • Each must appear alone on a compiler directive line (not continued).

  • Each can appear anywhere in your source code. Other directives must appear within the program unit they affect.

Example: A FREE directive.

    DO i = 1, n
        a(i) = b(i) * c(i)
    END DO

4.8.3 Parallelization Directives

A parallelization directive is a special comment that directs the compiler to attempt to parallelize a region of code. Both Sun and Cray style parallelization directives are now deprecated as obsolete. The OpenMP directives and parallelization model are preferred. OpenMP parallelization is described in the Oracle Developer Studio 12.6: OpenMP API User’s Guide.