| United States-English |
|
|
|
![]() |
HP Fortran Compiler for HP-UX: HP Fortran Programmer's Reference > Chapter 2 Language
elementsSource format of program file |
|
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:
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. 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 are not required to be in columns 1-5, but must be separated from the statement by at least one space.
Consider the spaces (designated by b) in the following statement:
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
the spaces are invalid in free source form but valid in fixed source form. 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. 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:
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. 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.
Multiple statements may appear on the same line, separated by a semicolon (;). Spaces are not significant except within a character context. For example, the two statements
are equivalent, but
are not. There are three types of lines in fixed source form:
The following sections describe each type of source lines. A continuation line has the following form:
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 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:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||