[an error occurred while processing this directive]

HP OpenVMS Systems Documentation

Content starts here

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:

  • For fixed form: Any character (except a zero or blank) in column 6 of a source line
  • For tab form: Any digit (except zero) after the first tab

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:

  • On the general rules for all source forms, see Section 2.3.
  • On statement separators (;) in all forms, see Section 2.3.
  • On compiler options, see the HP Fortran for OpenVMS User Manual.
  • On the OPTIONS statement, see Section 13.3.
  • On statement labels, see Section 2.3.
  • On obsolescent features in Fortran 95, see Appendix A.

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:

  • On the general rules for all source forms, see Section 2.3.
  • On the general rules for fixed and tab source forms, see Section 2.3.2.

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:

  • On the general rules for all source forms, see Section 2.3.
  • On the general rules for fixed and tab source forms, see Section 2.3.2.

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:

  • A name
    The names of the intrinsic data types are predefined, while the names of derived types are defined in derived-type definitions. Data objects (constants, variables, or parts of constants or variables) are declared using the name of the data type.
  • A set of associated values
    Each data type has a set of valid values. Integer and real data types have a range of valid values. Complex and derived types have sets of values that are combinations of the values of their individual components.
  • A way to represent constant values for the data type
    A constant is a data object with a fixed value that cannot be changed during program execution. The value of a constant can be a numeric value, a logical value, or a character string.
    A constant that does not have a name is a literal constant. A literal constant must be of intrinsic type and it cannot be array-valued.
    A constant that has a name is a named constant. A named constant can be of any type, including derived type, and it can be array-valued. A named constant has the PARAMETER attribute and is specified in a type declaration statement or PARAMETER statement.
  • A set of operations to manipulate and interpret these values
    The data type of a variable determines the operations that can be used to manipulate it. Besides intrinsic operators and operations, you can also define operators and operations.

This chapter contains information on the following topics:

For More Information:

  • On type declaration statements, see Section 5.1.
  • On valid operations for data types, see Section 4.1.
  • On defined operations, see Section 4.1.5.
  • On ranges for numeric literal constants, see the HP Fortran for OpenVMS User Manual.
  • On named constants, see Section 5.14.
  • On the PARAMETER attribute and statement, see Section 5.14.

3.2 Intrinsic Data Types

HP Fortran provides the following intrinsic data types:

  • INTEGER (see Section 3.2.1)
    There are four kind parameters for data of type integer:
    • INTEGER([KIND=]1) or INTEGER*1
    • INTEGER([KIND=]2) or INTEGER*2
    • INTEGER([KIND=]4) or INTEGER*4
    • INTEGER([KIND=]8) or INTEGER*8
  • REAL (see Section 3.2.2)
    There are three kind parameters for data of type real:
    • REAL([KIND=]4) or REAL*4
    • REAL([KIND=]8) or REAL*8
    • REAL([KIND=]16) or REAL*16
  • DOUBLE PRECISION (see Section 3.2.2)
    No kind parameter is permitted for data declared with type DOUBLE PRECISION. This data type is the same as REAL([KIND=]8).
  • COMPLEX (see Section 3.2.3)
    There are three kind parameters for data of type complex:
    • COMPLEX([KIND=]4) or COMPLEX*8
    • COMPLEX([KIND=]8) or COMPLEX*16
    • COMPLEX([KIND=]16) or COMPLEX*32
  • DOUBLE COMPLEX (see Section 3.2.3)
    No kind parameter is permitted for data declared with type DOUBLE COMPLEX. This data type is the same as COMPLEX([KIND=]8).
  • LOGICAL (see Section 3.2.4)
    There are four kind parameters for data of type logical:
    • LOGICAL([KIND=]1) or LOGICAL*1
    • LOGICAL([KIND=]2) or LOGICAL*2
    • LOGICAL([KIND=]4) or LOGICAL*4
    • LOGICAL([KIND=]8) or LOGICAL*8
  • CHARACTER (see Section 3.2.5)
    There is one kind parameter for data of type character: CHARACTER([KIND=]1).
  • BYTE
    This is a 1-byte value; the data type is equivalent to INTEGER([KIND=]1).

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:

  • On declaration statements for intrinsic data types, see Sections 5.1.1 and 5.1.2.
  • On operations for intrinsic data types, see Section 4.1.
  • On the KIND intrinsic function, see Section 9.4.79.
  • On storage requirements for intrinsic data types, see Table 15-2.
  • On type declaration statements, see Section 5.1.

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:

  • If the integer constant is within the default integer kind range, the kind is default integer.
  • If the integer constant is outside the default integer kind range, the kind of the integer constant is the smallest integer kind which holds the constant.

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:

  • On integer constants used in expressions, see Section 4.1.1.
  • On the ranges for integer types and kinds, see the HP Fortran for OpenVMS User Manual.


Previous Next Contents Index