| United States-English |
|
|
|
![]() |
HP Fortran 90 Programmer's Reference: HP Series 700/800 Computers > Chapter 2 Language elementsSource program forms |
|
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). 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:
are equivalent, but:
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:
An initial line has the following form:
A continuation line has the following form:
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 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. 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. 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. 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 are not required to be in columns 1-5, but must be separated from the statement proper by at least one space. Spaces are significant:
Spaces are denoted here (and throughout this manual where it is necessary to stress their presence) by b.
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.
Faulty: the space is invalid in MbARY, and the space is invalid in .bGE.. (This example would be valid in the fixed form.) 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. 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 "&". Consider the following two statements:
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. 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:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||