Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP Fortran 90 Programmer's Reference: HP Series 700/800 Computers > Chapter 2 Language elements

Source program forms

» 

Technical documentation

» Feedback
Content starts here

 » Table of Contents

 » Glossary

 » Index

Fortran 90 has a free source form, but also accepts FORTRAN 77's fixed source form (as it must, since FORTRAN 77 is a subset of Fortran 90). Although the two forms are quite different, it is possible to use an "intersection" form that satisfies both. This would be necessary, for example, when preparing Fortran text that was intended to be INCLUDEd (see “INCLUDE line”) in a Fortran program whose source form, fixed or free, was not known.

The fixed source form, the free source form, and the intersection form are described below.

The HP Fortran 90 compilation system assumes that source files are in the fixed format form, unless the source file being compiled has the suffix .f90 or the free-format compile-line option, the +source={fixed|free}option, is specified when the compiler is invoked (see Chapter 13 for further details on the option).

Fixed source form

Statements or parts of statements must be written between character positions 7 and 72. Any text following position 72 is ignored. The +[no]extend_source option (see Chapter 13) extends the statement to position 254. Positions 1-6 are reserved for special use. Blanks are not significant except within a character context.

For example:

RETURN
R E T U R N

are equivalent, but:

c = "abc"
c = "a b c"

are not equivalent.

Multiple statements may appear on one line separated by a semicolon (;).

There are three classes of lines in Fortran 90 fixed source form:

  1. Initial line

  2. Continuation line

  3. Comment line

Initial line

An initial line has the following form:

  • Positions 1 to 5 may contain a statement label.

  • Position 6 contains a space or the digit 0.

  • Positions 7 to 72 (optionally, to 254) can contain the statement.

Continuation line

A continuation line has the following form:

  • Positions 1 to 5 are blank.

  • Position 6 contains any character other than 0 or a space. One practice is to number continuation lines consecutively from 1.

  • Positions 7 to 72 (optionally, to 254) contain the continuation of a statement.

The Fortran 90 Standard specifies that a statement must not have more than 19 continuation lines. In HP Fortran 90, a statement consists of an initial line and up to 99 continuation lines.

Comment line

Comment lines may be included in a program. Such lines do not affect the program in any way but can be used by the programmer to include explanatory notes. The letter C, or c , or an asterisk (*) in position 1 of a line, designates that line as a comment line; the comment text is written in positions 1 to 72. A line containing only blank characters in positions 1 to 72 is also treated as a comment line.

An exclamation mark (!) in position 1 or in any position except position 6, causes the rest of the line to be treated as a comment.

In HP Fortran 90 a line with D or d in position 1 is by default treated as a comment . A compile-line option, the +[no]dlines option, treats lines with D or d in position 1 as statements to be compiled. This facility is useful in program debugging. See Chapter 13 for more information about the +dlines option.

In HP Fortran 90, a line with # in position 1 is treated as a comment. This allows source files which have been preprocessed with cpp to be compiled.

Tab-format lines

In HP Fortran 90 a tab character in the first position of a line can be used to skip past the statement label positions. If the character following the tab character is a digit, this is assumed to be in position 6, the continuation indicator position. Any other character following the tab character is assumed to be in position 7, the start of a new statement. A tab character in any other position of a line is treated as a space.

Free source form

In this form the source line is not divided into fields of predefined width, as in the fixed form. This makes it more convenient for input of text at an interactive terminal. The details of the free source form are as follows.

Source lines

Lines can contain from 0 to 132 characters. A compile-line option, the +extend_source option (see Chapter 13), extends the statement to position 254. Several Fortran 90 statements can be placed on a single source line, separated by ";" characters, and a single Fortran 90 statement can extend over more than one source line, as described below in “Statement continuation”.

Statement labels

Statement labels are not required to be in columns 1-5, but must be separated from the statement proper by at least one space.

Spaces

Spaces are significant:

  • They may not appear within a lexical token, such as a name or an operator.

  • In general one or more spaces are required to separate adjacent statement keywords, names, constants, or labels. Within the keyword pairs listed in Table 2-2 “Keywords allowing optional spacing”, however, the space is optional.

    Table 2-2 Keywords allowing optional spacing

    BLOCK DATA

    GO TO

    DOUBLE PRECISION

    IN OUT

    ELSE IF

    SELECT CASE

    END keyword

     

    The keyword after END can be any allowed by the Fortran 90 syntax, including the following: BLOCK DATA, DO, FILE, FUNCTION, IF, INTERFACE, MAP, MODULE, PROGRAM, SELECT, SUBROUTINE, STRUCTURE, TYPE, UNION, or WHERE.

  • Spaces are not required between a name and an operator because the latter begins and ends with special symbols that cannot be part of a name. Multiple spaces, unless in a character context, are equivalent to a single space.

Examples using spaces

Spaces are denoted here (and throughout this manual where it is necessary to stress their presence) by b.

IFbb(TEXT.EQ.'bbbYES') ...     ! Valid

Valid: the two spaces after IF are equivalent to one space. No spaces are required before or after .EQ., because there is no ambiguity. Note that the three spaces in the character constant are significant.

IF(MbARY.bGE.MIKE) ...         ! Faulty

Faulty: the space is invalid in MbARY, and the space is invalid in .bGE.. (This example would be valid in the fixed form.)

Comments

In free source form, the only way of indicating a comment is by use of the "!" symbol. Unless it appears in a character context, the occurrence of a "!" symbol defines the start of a comment, which always continues to the end of the source line. It is thus not possible to embed a comment inside program text within a single source line, but it can follow program text on a source line. Furthermore, a Fortran 90 statement on a line with a trailing comment can be continued on subsequent lines.

Statement continuation

A statement can be split over two or more source lines by appending an "&" symbol to each source line involved except the last. The ampersand must not be within a character constant.

In this way, in Standard Fortran 90, a statement can occupy up to 40 source lines. As an extension, HP Fortran 90 increases this limit to 100 source lines.

The END statement cannot be split by means of a continuation line.

The text of the source statement in a continuation line is assumed to resume from column 1, unless the first nonblank symbol in the line is an "&", in which case the text resumes from the first position after the "&".

Example of statement continuation

Consider the following two statements:

       INTEGER   marks, total, difference,&        ! work variables
                     mean, average   
       INTEGER   marks, total, difference, mean_&  ! work variables
                     &value  average     

The second of these statements declares an integer variable called mean_value. Any spaces appearing in the variable name as a result of the continuation would have been invalid, which is why another "&" was used in the continuation line. (Alternatively "value" could have been positioned at column 1.) Splitting lexical tokens, including character constants, across source lines in this way, is permitted but should be avoided if possible.

Comments cannot be continued.

Intersection source form

It is possible to write programs in a way that is acceptable as both free source form and fixed source form, unless in extended fixed format source mode. The rules are:

  • Put labels in positions 1-5.

  • Put statement bodies in positions 7-72.

  • Begin comments with an exclamation mark (!) in any position except 6.

  • Indicate all continuations with an ampersand in position 73 of the line to be continued and an ampersand in position 6 of the continuing line.

  • Do not insert blanks in tokens.

  • Separate adjacent names and keywords with a space.

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© 1996 Hewlett-Packard Development Company, L.P.