Every HPF element and expression has a data type. The data type of an element may be implicit in its definition or explicitly attached to the element in a declaration statement. This chapter describes the HPF data types and constants that pghpf supports.
Fortran provides two types of data types, intrinsic data types and derived data types. Types provided by the language are intrinsic types. Types specified by the programmer and built from the intrinsic data types are called derived types.
The following are several examples using a KIND specification:
INTEGER (SHORT) :: L REAL (HIGH) B REAL (KIND=HIGH) XVAR, YVARThese examples require that the programmer use a PARAMETER statement to define the kinds:
INTEGER, PARAMETER:: SHORT =1 INTEGER HIGH PARAMETER (HIGH=8)Table 2-2 shows several examples of KINDs that a system could support.
Table 2-1 Fortran Intrinsic Data Types
Data Type Value INTEGER An integer number. REAL
DOUBLE A real number.
A double precision PRECISION floating point number, real number, taking up two numeric storage units and whose precision is greater than REAL. LOGICAL A value which can be either TRUE or FALSE. COMPLEX A pair of real numbers used in complex arithmetic. Fortran provides two precisions for COMPLEX numbers. CHARACTER A string consisting of one or more printable characters.
Table 2-2 Data Types Kind Parameters (examples)
Type Kind Size INTEGER SHORT 1 byte INTEGER LONG 2 bytes REAL HIGH 8 bytes
Table 2-3 Data Type Extensions
Type Meaning Size LOGICAL*1 Small LOGICAL 1 byte LOGICAL*2 Short LOGICAL 2 bytes LOGICAL*4 LOGICAL 4 bytes BYTE Small INTEGER 1 byte INTEGER*1 Same as BYTE 1 byte INTEGER*2 Short INTEGER 2 bytes INTEGER*4 INTEGER 4 bytes REAL*4 REAL 4 bytes REAL*8 DOUBLE PRECISION 8 bytes COMPLEX*8 COMPLEX 8 bytes COMPLEX*16 DOUBLE COMPLEX 16 bytesThe BYTE type is treated as a signed one-byte integer and is equivalent to LOGICAL*1.
Assignment of a value too big for the data type to which it is assigned is an undefined operation.
A specifier is allowed after a CHARACTER function name even if the CHARACTER type word has a specifier. For example:
CHARACTER*4 FUNCTION C*8 (VAR1)The function size specification C*8 overrides the CHARACTER*4 specification. Logical data items can be used with any operation where a similar sized integer data item is permissible and vice versa. The logical data item is treated as an integer or the integer data item is treated as a logical of the same size and no type conversion is performed.
Floating point data items of type REAL or DOUBLE PRECISION may be used as array subscripts, in computed GOTOs, in array bounds and in alternate returns, pghpf converts the floating point number to an integer.
The data type of the result of an arithmetic expression corresponds to the type of its data. The type of an expression is determined by the rank of its elements. Table 2-4 shows the ranks of the various data types, from lowest to highest.
Table 2-4 Data Type Ranks
Data Type Rank LOGICAL 1 (lowest) INTEGER*2 2 INTEGER*4 3 REAL*4 4 REAL*8 (Double precision) 5 COMPLEX*8 (Complex) 6 COMPLEX*16 (Double complex) 7 (highest)The data type of a value produced by an operation on two arithmetic elements of different data types is the data type of the highest-ranked element in the operation. The exception to this rule is that an operation involving a COMPLEX*8 element and a REAL*8 element produces a COMPLEX*16 result. In this operation, the COMPLEX*8 element is converted to a COMPLEX*16 element, which consists of two REAL*8 elements, before the operation is performed.
The type of a logical expression is always a LOGICAL*4 result.
The pghpf Fortran compiler supports decimal (INTEGER and REAL), unsigned binary, octal, hexadecimal and Hollerith constants. The use of character constants in a numeric context, for example, in the right-hand side of an arithmetic assignment statement, is supported. These constants assume a data type that conforms to the context in which they appear.
[s]d1d2...dn [ _ kind-parameter ]where s is an optional sign and di is a digit in the range 0 to 9. The optional _kind- parameter specifies a supported kind. The value of an integer constant must be within the range for the specified kind.
Below are several examples of integer constants.
+2 -36 437 -36_SHORT
E+digits [_ kind-parameter ] Edigit [_ kind-parameter ] E-digits [_ kind-parameter ]where digits is the scaling factor, the power of ten, to be applied to the unscaled constant. The first two forms above are equivalent, that is, a scaling factor without a sign is assumed to be positive. Table 2-5 shows several real constants.
Table 2-5 Example of Real Constants
Constant Value 1.0 unscaled single precision constant 1. unscaled single precision constant -.003 signed unscaled single precision constant -.003_LOW signed unscaled constant with kind LOW. -1.0 signed unscaled single precision constant 6.1E2_LOW is equivalent to 610.0 with kind LOW +2.3E3_HIGH is equivalent to 2300.0 with kind HIGH 6.1E2 is equivalent to 610.0 +2.3E3 is equivalent to 2300.0 -3.5E-1 is equivalent to -0.35
D+digits Ddigit D-digits
Table 2-6 Double Precision Constants
Constant Value 6.1D2 is equivalent to 610.0 +2.3D3 is equivalent to 2300.0 -3.5D-1 is equivalent to -0.35 +4D4 is equivalent to 40000.
(18,-4)
(3.5,-3.5)
(6.1E2,+2.3E3)
.TRUE. [ _ kind-parameter ] .FALSE.[ _ kind-parameter ]The logical constants .TRUE. and .FALSE. are by default defined to be four-byte values -1 and 0 respectively. A logical expression is defined to be .TRUE. if its least significant bit is 1 and .FALSE. otherwise[*] . Below are several examples:
.TRUE.The abbreviations T and F can be used in place of .TRUE. and .FALSE. in data initialization statements and in NAMELIST input.
.FALSE.
.TRUE._BIT
A character constant is one of:
[ kind-parameter_ ] "[characters]" [ kind-parameter_ ] '[characters]'Below are several examples of character constants.
'abc' 'abc ' 'ab''c'A zero length character constant is written as '' or "".
"Test Word" GREEK_"uupi"
If a character constant is used in a numeric context, for example as the expression on the right side of an arithmetic assignment statement, it is treated as a Hollerith constant. The rules for typing and sizing character constants used in a numeric context are outlined later in the description of Hollerith constants.
! Declare a structure to define a person derived typeA derived type statement definition is called a derived-type statement (the statements between TYPE PERSON and END TYPE PERSON in the previous example. The definition of a variable of the new type is called a TYPE statement (CUSTOMER in the previous example); note the use of parenthesis in the TYPE statement.
TYPE PERSON
INTEGER ID
LOGICAL LIVING
CHARACTER(LEN=20) FIRST, LAST, MIDDLE
INTEGER AGE
END TYPE PERSON TYPE (PERSON) CUSTOMER(10)
The % character accesses the components of a derived type. For example:
CUSTOMER(1) % ID = 11308
A = B + 6Fortran arrays may be passed with unspecified shapes to subroutines and functions, and sections of arrays may be used and passed as well. Arrays of derived type data types are also valid. In addition, allocatable arrays may be created with deferred shapes (actual dimensions are determined when the array is allocated while the program is running).
Fortran supports binary, octal and hexadecimal constants in DATA statements. The form of a binary constant is:
B'b1b2...bn' B"b1b2...bn"where b i is either 0 or 1.
The form of an octal constant is:
O'c1c2...cn' O"c1c2...cn"where c i is in the range 0 through 7.
The form of a hexadecimal constant is:
Z'a1a2...an' Z"a1a2...an"where ai is in the range 0 through 9 or a letter in the range A through F or a through f (case mixing is allowed).
nHc1c2...cnwhere n specifies the positive number of characters in the constant and cannot exceed 2000 characters. A Hollerith constant is stored as a byte string with four characters per 32-bit word. Hollerith constants are untyped arrays of INTEGER*4. The last word of the array is padded on the right with blanks if necessary. Hollerith constants cannot assume a character data type and cannot be used where a character value is expected. The data type of a Hollerith constant used in a numeric expression is determined by the following rules: