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 Compiler for HP-UX: HP Fortran Programmer's Reference > Chapter 2 Language elements

Source format of program file

» 

Technical documentation

Complete book in PDF
» Feedback
Content starts here

 » Table of Contents

 » Glossary

 » Index

The HP Fortran compiler accepts source files in fixed form (the standard source form for FORTRAN 77 programs) or free form. The following sections describe both forms.

The compiler assumes that source files whose names end in the .f90 extension are in free source form and that files whose names end in the .f or .F extension are in fixed form. You can override these assumptions by compiling with the +source=free or +source=free option. See the HP Fortran Programmer’s Guide for more information.

Although the two forms are quite different, you can format a Fortran 90 source file so that the compiler would accept it as either fixed or free form. This would be necessary, for example, when preparing a source file containing code that will be inserted through the INCLUDE line into a file for which the form is not known. To format a source file to be acceptable as either free or fixed source form, use the following rules:

  • Put labels in columns1-5.

  • Put statement bodies in columns 7-72.

  • Begin comments with an exclamation mark in anycolumn except column 6.

  • Indicate all continuations with an ampersand character (&) in column 73 of the line to be continued and an ampersand character in column 6 of the continuing line.

  • Do not insert blanks in tokens.

  • Separate adjacent names and keywords with a space.

Free source form

In free source form, the source line is not divided into fields of predefined width, as in the fixed form. This makes entering text at an interactive terminal more convenient.

Source lines

Freeform lines can contain from 0 to 132 characters. The +extend_source option extends the line to column 254. This is described in the HP Fortran Programmer’s Guide. Several statements can appear on a single source line, separated by semicolons. A single Fortran 90 statement can extend over more than one source line, as described below in “Statement continuation”.

Multiple statements may appear on the same line, separated by a semicolon (;).

Statement labels

Statement labels are not required to be in columns 1-5, but must be separated from the statement 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-4 “Keywords allowing optional spacing”, however, the space is optional. The keyword following END can be: BLOCK DATA, DO, FILE, FUNCTION, IF, INTERFACE, MAP, MODULE, PROGRAM, SELECT, SUBROUTINE, STRUCTURE, TYPE, UNION, or WHERE.

    Table 2-4 Keywords allowing optional spacing

    BLOCK DATA

    GO TO

    DOUBLE PRECISION

    IN OUT

    ELSE IF

    SELECT CASE

    END keyword

     

  • 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.

Consider the spaces (designated by b) in the following statement:

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

The two spaces after IF are valid and are equivalent to one space. No spaces are required before or after .EQ., because there is no ambiguity. However, the three spaces in the character constant are significant.

In the next example

IF(MbARY.bGE.MIKE) ...        ! Faulty in free source form

the spaces are invalid in free source form but valid in fixed source form.

Comments

An exclamation mark (!) indicates the beginning of a comment in free source form, except where it appears in a character context. The compiler considers the rest of the line following the exclamation mark as part of the comment. Embedding a comment inside program text within a single source line is not allowed, but it can follow program text on a source line. A 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 ampersand character (&) to each source line except the last. The ampersand must not be within a character constant.

A statement can occupy up to 40 source lines. As an extension, HP Fortran increases this limit to 100 source lines. The END statement cannot be split by means of a continuation line. Comments are not statements and cannot be continued.

The text of the source statement in a continuation line is assumed to resume from column 1. However, if the first nonblank symbol in the line is an ampersand, the text resumes from the first column after the ampersand.

Consider the following two statements:

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

The second statement declares the integer variable, mean_value. Any spaces appearing in the variable name as a result of the continuation would be invalid. This is the reason for the ampersand character in the continuation line. (Alternatively, value could have been positioned at column 1.) Using the ampersand character to split lexical tokens and character constants across source lines is permitted, but not recommended.

Fixed source form

Statements or parts of statements must be written between character columns 7 and 72. Any text following column 72 is ignored. The +[no]extend_source option extends the statement to column 254. Columns 1-6 are reserved for special use.

NOTE: Programs that depend on the compiler’s ignoring any characters after column 72 will not compile correctly with the +extend_source option.

Multiple statements may appear on the same line, separated by a semicolon (;).

Spaces

Spaces are not significant except within a character context. For example, the two statements

RETURN
R E T U R N

are equivalent, but

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

are not.

Source lines

There are three types of lines in fixed source form:

  • Initial line

  • Continuation line

  • Comment line

The following sections describe each type of source lines.

Initial line

An initial line has the following form:

  • Columns 1 to 5 may contain a statement label.

  • Column 6 contains a space or the digit zero.

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

Continuation line

A continuation line has the following form:

  • Columns 1 to 5 are blank.

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

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

The Standard specifies that a statement must not have more than 19 continuation lines. As an extension to the Standard, HP Fortran allows as many as 99 continuation lines.

Comment line

Comment lines may be included in a program. Comment lines do not affect compilation in any way, but usually include explanatory notes. The letter C, or c , or an asterisk (*) in column 1 of a line, designates that line as a comment line; the comment text is written in columns 1 to 72. The compiler treats a line containing only blank characters in columns 1 to 72 as a comment line. In addition, a line is considered to be a comment when there is an exclamation mark (!) in column 1 or in any column except column 6.

The following are HP extensions to the comment:

  • A line with D or d in column 1 is by default treated as a comment. The +dlines option causes the compiler to treat such lines as statements to be compiled. This extension to the comment—called debugging lines—is useful for including PRINT statements that are to be compiled during the debugging stage to display the program state.

  • A line with a pound sign (#) character in column 1 is treated as a comment. This extension allows compilation of source files that have been preprocessed with the C preprocessor (cpp).

  • HP Fortran allows tab formatting. That is, a tab character may be entered in the first column of a line to skip past the statement label columns. If the character following the tab character is a digit, this digit is assumed to be in column 6, the continuation indicator column. Any other character following the tab character is assumed to be in column 7, the start of a new statement. A tab character in any other column of a line is treated as a space.

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