HP Fortran for OpenVMS
Language Reference Manual


Previous Contents Index

2.3.2 Fixed and Tab Source Forms

In Fortran 95, fixed source form is identified as obsolescent.

In fixed and tab source forms, there are restrictions on where a statement can appear within a line.

By default, a statement can extend to character position 72. In this case, any text following position 72 is ignored and no warning message is printed. You can specify a compiler option to extend source lines to character position 132.

Except in a character context, blanks are not significant and can be used freely throughout the program for maximum legibility.

Some Fortran compilers use blanks to pad short source lines out to 72 characters. By default, HP Fortran does not. If portability is a concern, you can use the concatenation operator to prevent source lines from being padded by other Fortran compilers (see the example in "Continuation Indicator" below) or you can force short source lines to be padded by using a compiler option.

Comment Indicator

In fixed and tab source forms, the exclamation point character (!) indicates a comment if it is within a source line. (It must not appear in column 6 of a fixed form line; that column is reserved for a continuation indicator.)

The letter C (or c), an asterisk (*), or an exclamation point (!) indicates a comment line when it appears in column 1 of a source line.

Continuation Indicator

In fixed and tab source forms, a continuation line is indicated by one of the following:

The compiler considers the characters following the continuation indicator to be part of the previous line. Although Fortran 95/90 permits up to 19 continuation lines in a fixed-form program, HP Fortran allows up to 511 continuation lines.

If a zero or blank is used as a continuation indicator, the compiler considers the line to be an initial line of a Fortran statement.

The statement label field of a continuation line must be blank, except in the case of a debugging statement.

When long character or Hollerith constants are continued across lines, portability problems can occur. Use the concatenation operator to avoid such problems. For example:


      PRINT *, 'This is a very long character constant '// 
     +         'which is safely continued across lines' 

Use this same method when initializing data with long character or Hollerith constants. For example:


      CHARACTER*(*) LONG_CONST                              
      PARAMETER (LONG_CONST = 'This is a very long '//      
     + 'character constant which is safely continued '//    
     + 'across lines')                                      
      CHARACTER*100 LONG_VAL                                
      DATA LONG_VAL /LONG_CONST/                            

Hollerith constants must be converted to character constants before using the concatenation method of line continuation.

Debugging Statement Indicator

In fixed and tab source forms, the statement label field can contain a statement label, a comment indicator, or a debugging statement indicator.

The letter D indicates a debugging statement when it appears in column 1 of a source line. The initial line of the debugging statement can contain a statement label in the remaining columns of the statement label field.

If a debugging statement is continued onto more than one line, every continuation line must begin with a D and a continuation indicator.

By default, the compiler treats debugging statements as comments. However, you can specify a compiler option to force the compiler to treat debugging statements as source text to be compiled.

For More Information:

2.3.2.1 Fixed-Format Lines

In fixed source form, a source line has columns divided into fields for statement labels, continuation indicators, statement text, and sequence numbers. Each column represents a single character.

The column positions for each field follow:

Field Column
Statement label 1 through 5
Continuation indicator 6
Statement 7 through 72 (or 132 with a compiler option)
Sequence number 73 through 80

By default, a sequence number or other identifying information can appear in columns 73 through 80 of any fixed-format line in a HP Fortran program. The compiler ignores the characters in this field.

If you extend the statement field to position 132, the sequence number field does not exist.

Note

If you use the sequence number field, do not use tabs anywhere in the source line, or the compiler may interpret the sequence numbers as part of the statement field in your program.

For More Information:

2.3.2.2 Tab-Format Lines

In tab source form, you can specify a statement label field, a continuation indicator field, and a statement field, but not a sequence number field.

Figure 2-2 shows equivalent source lines coded with tab and fixed source form.

Figure 2-2 Line Formatting Example


The statement label field precedes the first tab character. The continuation indicator field and statement field follow the first tab character.

The continuation indicator is any nonzero digit. The statement field can contain any Fortran statement. A Fortran statement cannot start with a digit.

If a statement is continued, a continuation indicator must be the first character (following the first tab) on the continuation line.

Many text editors and terminals advance the terminal print carriage to a predefined print position when you press the [Tab] key. However, the HP Fortran compiler does not interpret the tab character in this way. It treats the tab character in a statement field the same way it treats a blank character. In the source listing that the compiler produces, the tab causes the character that follows to be printed at the next tab stop (usually located at columns 9, 17, 25, 33, and so on).

Note

If you use the sequence number field, do not use tabs anywhere in the source line, or the compiler may interpret the sequence numbers as part of the statement field in your program.

For More Information:

2.3.3 Source Code Useable for All Source Forms

To write source code that is useable for all source forms (free, fixed, or tab), follow these rules:
Blanks Treat as significant (see Section 2.3.1).
Statement labels Place in column positions 1 through 5 (or before the first tab character).
Statements Start in column position 7 (or after the first tab character).
Comment indicator Use only !. Place anywhere except in column position 6 (or immediately after the first tab character).
Continuation indicator Use only &. Place in column position 73 of the initial line and each continuation line, and in column 6 of each continuation line (no tab character can precede the ampersand in column 6).

The following example is valid for all source forms:


Column: 
 
12345678...                                                            73 
_________________________________________________________________________ 
 
! Define the user function MY_SIN 
 
      DOUBLE PRECISION FUNCTION MY_SIN(X) 
        MY_SIN = X - X**3/FACTOR(3) + X**5/FACTOR(5)                    & 
     &          - X**7/FACTOR(7) 
      CONTAINS 
        INTEGER FUNCTION FACTOR(N) 
         FACTOR = 1 
         DO 10 I = N, 1, -1 
  10     FACTOR = FACTOR * I 
        END FUNCTION FACTOR 
      END FUNCTION MY_SIN 


Chapter 3
Data Types, Constants, and Variables

This chapter describes:

3.1 Overview

Each constant, variable, array, expression, or function reference in a Fortran statement has a data type. The data type of these items can be inherent in their construction, implied by convention, or explicitly declared.

Each data type has the following properties:

This chapter contains information on the following topics:

For More Information:

3.2 Intrinsic Data Types

HP Fortran provides the following intrinsic data types:

The intrinsic function KIND can be used to determine the kind type parameter of a representation method.

For more portable programs, you should not use the forms INTEGER([KIND=]n) or REAL([KIND=]n). You should instead define a PARAMETER constant using the SELECTED_INT_KIND or SELECTED_REAL_KIND function, whichever is appropriate. For example, the following statements define a PARAMETER constant for an INTEGER kind that has 9 digits:


INTEGER, PARAMETER :: MY_INT_KIND = SELECTED_INT_KIND(9) 
  ... 
INTEGER(MY_INT_KIND) :: J 
  ... 

Note that the syntax separator :: is used in type declaration statements.

The following sections describe the intrinsic data types and forms for literal constants for each type.

For More Information:

3.2.1 Integer Data Types

Integer data types can be specified as follows:

  • INTEGER
  • INTEGER([KIND=]n)
  • INTEGER*n

n

Is kind 1, 2, 4, or 8.

If a kind parameter is specified, the integer has the kind specified. If a kind parameter is not specified, integer constants are interpreted as follows:

Integer Constants

An integer constant is a whole number with no decimal point. It can have a leading sign and is interpreted as a decimal number.

Integer constants take the following form:

[s]n[n...][ _k]

s

Is a sign; required if negative (--), optional if positive (+).

n

Is a decimal digit (0 through 9). Any leading zeros are ignored.

k

Is the optional kind parameter: 1 for INTEGER(1), 2 for INTEGER(2), 4 for INTEGER(4), or 8 for INTEGER(8). It must be preceded by an underscore (_).

An unsigned constant is assumed to be nonnegative.

Integers are expressed in decimal values (base 10) by default. To specify a constant that is not in base 10, use the following syntax:

[s][[base] #]nnn...

s

Is an optional plus (+) or minus (--) sign.

base

Is any constant from 2 through 36.

If base is omitted but # is specified, the integer is interpreted in base 16. If both base and # are omitted, the integer is interpreted in base 10.

For bases 11 through 36, the letters A through Z represent numbers greater than 9. For example, for base 36, A represents 10, B represents 11, C represents 12, and so on, through Z, which represents 35. The case of the letters is not significant.

Examples

The following examples show valid and invalid integer (base 10) constants:
Valid  
0  
-127  
+32123  
47_2  
Invalid Explanation
9999999999999999999 Number too large.
3.14 Decimal point not allowed; this is a valid
REAL constant.
32,767 Comma not allowed.
33_3 3 is not a valid kind for integers.

The following integers (most of which are not base 10) are all assigned a value equal to 3994575 decimal:


I     = 2#1111001111001111001111 
m     = 7#45644664 
J     = +8#17171717 
K     = #3CF3CF 
n     = +17#2DE110 
L     = 3994575 
index = 36#2DM8F 

You can use integer constants to assign values to data. The following table shows assignments to different data and lists the integer and hexadecimal values in the data:
Fortran
Assignment
Integer Value
in the Data
Hexadecimal Value
in the Data
LOGICAL(1) X
INTEGER(1) X
   
X = --128 --128 Z ' 80 '
X = 127 127 Z ' 7F '
X = 255 --1 Z ' FF '
LOGICAL(2) X
INTEGER(2) X
   
X = 255 255 Z ' FF '
X = --32768 --32768 Z ' 8000 '
X = 32767 32767 Z ' 7FFF '
X = 65535 --1 Z ' FFFF '

For More Information:


Previous Next Contents Index