XL Fortran for AIX 8.1

Language Reference


Lines and Source Formats

A line is a horizontal arrangement of characters. By contrast, a column is a vertical arrangement of characters, where each character, or each byte of a multibyte character, in a given column shares the same line position.

+-------------------------------IBM Extension--------------------------------+

Because XL Fortran measures lines in bytes, these definitions apply only to lines containing single-byte characters. Each byte of a multibyte character occupies one column.

+----------------------------End of IBM Extension----------------------------+

The kinds of lines are:

Initial Line Is the first line of a statement.
Continuation Line Continues a statement beyond its initial line.
Comment Line Does not affect the executable program and can be used for documentation. The comment text continues to the end of a line. Although comment lines can follow one another, a comment line cannot be continued. A line of all white space or a zero-length line is a comment line without any text. Comment text can contain any characters allowed in a character context.

If an initial line or continuation line is not continued, or if it is continued but not in a character context, an inline comment can be placed on the same line, to the right of any statement label, statement text, and continuation character that may be present. An exclamation mark (!) begins an inline comment.

* Conditional Compilation Line Indicates that the line should only be compiled if recognition of conditional compilation lines is enabled. A conditional compilation sentinel should appear on a conditional compilation line. (See Conditional Compilation) *
* Debug Line Indicates that the line is for debugging code (for fixed source form only). In XL Fortran the letter D or X must be specified in column 1. (See Debug Lines) *
* Directive Line Provides instructions or information to the compiler in XL Fortran (see Chapter 11, Directives). *

+-------------------------------IBM Extension--------------------------------+

Note:
* Debug Line and DirectiveLine are used in XL Fortran

In XL Fortran, source lines can be in fixed source form or free source form format. Use the SOURCEFORM directive to mix source formats within the same program unit. Fixed source form is the default when using the f77, fort77, xlf, xlf_r or xlf_r7 invocation commands. Fortran 90 free source form is the default when using the xlf90, xlf90_r, xlf90_r7, xlf95, xlf95_r or xlf95_r7 invocation commands.

See "Compiling an XL Fortran Program" in the User's Guide for details on invocation commands.

+----------------------------End of IBM Extension----------------------------+

Fixed Source Form

+-------------------------------IBM Extension--------------------------------+

A fixed source form line is a sequence of 1 to 132 characters. The default line size (as stipulated in Fortran 95) is 72 characters, but can be changed in XL Fortran by using the -qfixed=right_margin compiler option (see the User's Guide).

+----------------------------End of IBM Extension----------------------------+

Columns beyond the right margin are not part of the line and can be used for identification, sequencing, or any other purpose.

Except within a character context, white space is insignificant; that is, you can imbed white space between and within lexical tokens, without affecting the way the compiler will treat them.

+-------------------------------IBM Extension--------------------------------+

Tab formatting means there is a tab character in columns 1 through 6 of an initial line in XL Fortran, which directs the compiler to interpret the next character as being in column 7.

+----------------------------End of IBM Extension----------------------------+

Requirements for lines and for items on those lines are:

A semicolon (;) separates statements on a single source line, except when it appears in a character context, in a comment, or in columns 1 through 6. Two or more semicolon separators that are on the same line and are themselves separated by only white space or other semicolons are considered to be a single separator. A separator that is the last character on a line or before an inline comment is ignored. Statements following a semicolon on the same line cannot be labeled. Additional statements cannot follow a program unit END statement on the same line.

Debug Lines

+-------------------------------IBM Extension--------------------------------+

A debug line, allowed only for fixed source form, contains source code used for debugging and is specified in XL Fortran by the letter D, or the letter X in column 1. The handling of debug lines depends on the -qdlines or the -qxlines compiler options:

If you continue a debugging statement on more than one line, every continuation line must have a D in column 1 and a continuation character. If the initial line is not a debugging line, you can designate any continuation lines as debug lines provided that the statement is syntactically correct, whether or not you specify the -qdlines or -qxlines compiler option.

+----------------------------End of IBM Extension----------------------------+

Example of Fixed Source Form
C Column Numbers:
C        1         2         3         4         5         6         7
C23456789012345678901234567890123456789012345678901234567890123456789012
 
!IBM* SOURCEFORM (FIXED)
      CHARACTER ABC ; LOGICAL X          ! 2 statements on 1 line
      DO 10 I=1,10
        PRINT *,'this is the index',I  ! with an inline comment
10    CONTINUE
C
       CHARSTR="THIS IS A CONTINUED
     X CHARACTER STRING"
       ! There will be 38 blanks in the string between "CONTINUED"
       ! and "CHARACTER". You cannot have an inline comment on
       ! the initial line because it would be interpreted as part
       ! of CHARSTR (character context).
  100 PRINT *, IERROR
! The following debug lines are compiled as source lines if
! you use -qdlines
D     IF (I.EQ.IDEBUG.AND.
D    +    J.EQ.IDEBUG)     WRITE(6,*) IERROR
D     IF (I.EQ.
D    +  IDEBUG )
D    +  WRITE(6,*) INFO
       END

Free Source Form

+-------------------------------IBM Extension--------------------------------+

XL Fortran allows any line length and number of continuation lines, so long as the number of characters does not exceed 6700.

+----------------------------End of IBM Extension----------------------------+

A free source form line can specify up to 132 characters on each line, with a maximum of 39 continuation lines for a statement.

Items can begin in any column of a line, subject to the following requirements for lines and items on those lines:

A semicolon separates statements on a single source line, except when it appears in a character context or in a comment. Two or more separators that are on the same line and are themselves separated by only white space or other semicolons are considered to be a single separator. A separator that is the last character on a line or before an inline comment is ignored. Additional statements cannot follow a program unit END statement on the same line.

White Space

White space must not appear within lexical tokens, except in a character context or in a format specification. White space can be inserted freely between tokens to improve readability, although it must separate names, constants, and labels from adjacent keywords, names, constants, and labels.

Certain adjacent keywords may require white space. The following table lists keywords that require white space, and keywords for which white space is optional.

Table 1. Keywords Where White Space is Optional

BLOCK DATA END FUNCTION END SUBROUTINE
DOUBLE COMPLEX END IF END TYPE
DOUBLE PRECISION END INTERFACE END UNION
ELSE IF END MAP END WHERE
END BLOCK DATA END MODULE GO TO
END DO END PROGRAM IN OUT
END FILE END SELECT SELECT CASE
END FORALL END STRUCTURE

See Type Declaration for details about type_spec.

Example of Free Source Form
!IBM* SOURCEFORM (FREE(F90))
!
! Column Numbers:
!        1         2         3         4         5         6         7
!23456789012345678901234567890123456789012345678901234567890123456789012
 DO I=1,20
   PRINT *,'this statement&
   & is continued' ; IF (I.LT.5) PRINT *, I
 
 ENDDO
 EN&
         &D              ! A lexical token can be continued

+-------------------------------IBM Extension--------------------------------+

IBM Free Source Form

An IBM free source form line or statement is a sequence of up to 6700 characters. Items can begin in any column of a line, subject to the following requirements for lines and items on those lines:

If statement text on an initial line or continuation line is to be continued, a minus sign indicates continuation of the statement text on the next line. In a character context, if the rightmost character of the statement text to be continued is a minus sign, a second minus sign must be entered as a continuation character.

Except within a character context, white space is insignificant; that is, you can imbed white space between and within lexical tokens, without affecting the way the compiler will treat them.

Example of IBM Free Source Form

!IBM* SOURCEFORM (FREE(IBM))
"
" Column Numbers:
"        1         2         3         4         5         6         7
"23456789012345678901234567890123456789012345678901234567890123456789012
 DO I=1,10
  PRINT *,'this is -
             the index',I   ! There will be 14 blanks in the string
                            ! between "is" and "the"
 END DO
 END

+----------------------------End of IBM Extension----------------------------+

+-------------------------------IBM Extension--------------------------------+

Conditional Compilation

You can use sentinels to mark specific lines of an XL Fortran program for conditional compilation. This support allows you to port code that contains statements that are only valid or needed in an SMP environment to a non-SMP environment. You can do this by using conditional compilation lines or by using the _OPENMP C preprocessor macro.

The syntax for conditional compilation lines is as follows:



>>-cond_comp_sentinel--fortran_source_line---------------------><
 
 

cond_comp_sentinel
is a conditional compilation sentinel that is defined by the current source form and is either:

fortran_source_line
is an XL Fortran source line

The syntax rules for conditional compilation lines are very similar to the syntax rules for fixed source form and free source form lines. The rules are as follows:

Another way to conditionally include code, other than using conditional compilation lines, is to use the C preprocessor macro _OPENMP. This macro is defined when the C preprocessor is invoked and you specify the -qsmp=omp compiler option. See the section on passing Fortran files through the C preprocessor in the "Editing, Compiling, Linking, and Running XL Fortran Programs" chapter of the User's Guide for an example of using this macro.

Valid Example of Conditional Compilation Lines

In the following example, conditional compilation lines are used to hide OpenMP run-time routines. Code that calls OpenMP run-time routines cannot easily be compiled in a non-OpenMP environment without using conditional compilation. Since calls to the run-time routines are not directives, they cannot be hidden by the !$OMP trigger. If the code below is not compiled with the -qsmp=omp compiler option, the variable used to store the number of threads will be assigned the value of 8.

      PROGRAM PAR_MAT_MUL
      IMPLICIT NONE
      INTEGER(KIND=8)                 ::I,J,NTHREADS
      INTEGER(KIND=8),PARAMETER       ::N=60
      INTEGER(KIND=8),DIMENSION(N,N)  ::AI,BI,CI
      INTEGER(KIND=8)                 ::SUMI
!$    INTEGER OMP_GET_NUM_THREADS
 
      COMMON/DATA/ AI,BI,CI
!$OMP THREADPRIVATE (/DATA/)
 
!$OMP PARALLEL
      FORALL(I=1:N,J=1:N) AI(I,J) = (I-N/2)**2+(J+N/2)
      FORALL(I=1:N,J=1:N) BI(I,J) = 3-((I/2)+(J-N/2)**2)
!$OMP MASTER
      NTHREADS=8
!$    NTHREADS=OMP_GET_NUM_THREADS()
!$OMP END MASTER
!$OMP END PARALLEL
 
!$OMP PARALLEL DEFAULT(PRIVATE),COPYIN(AI,BI),SHARED(NTHREADS)
!$OMP DO
      DO I=1,NTHREADS
      CALL IMAT_MUL(SUMI)
      ENDDO
!$OMP END DO
!$OMP END PARALLEL
 
      END
 

+----------------------------End of IBM Extension----------------------------+


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]