• Aucun résultat trouvé

5. 1 Data Types

Dans le document FORTRAN-a6 USER'S GUIDE (Page 35-41)

Fortran-86 supports the following data types: integer, floating-point, logical, and character. Floating-point data types include the following: REAL, DOUBLE PRECISION, COMPLEX, COMPLEX* 16, and TEMPREAL. A symbolic name representing a constant, variable, array, or function indicates data type.

You can specify the type of a named constant, variable, array, external function, or statement function with a type statement. In the absence of a specific declaration, the Fortran default typing convention takes effect. According to this convention, the first letter of the name indicates the particular type. A first letter of I, J, K, L, M, or N indicates type INTEGER; any other letter or an underscore indicates type REAL.

An IMPLICIT statement can change this convention (see Section 5.2).

Type statements can also specify data length or array dimension information. You cannot specify the type of a name explicitly more than once in a program unit.

PROGRAM, SUBROUTINE, and BLOCK DATA names cannot appear in type statements.

In Fortran, there are four levels at which data lengths can be set: compiler default, the STORAGE control, the IMPLICIT statement, and type specification statements.

If you do not specifically declare any data lengths, the following compiler defaults the STORAGE control and the compiler defaults for the given class of names.

If you specify a length in a type statement, it overrides the IMPLICIT statement, STORAGE control, and the compiler default for the given names.

5-1

Data and SlPecification Statements

5-2

5. 1. 1 Integer Data

An item of integer data always comprises the exact representation of an integer value.

The value can be positive, negative, or zero. An item of integer data requires one one-byte, two-one-byte, or four-byte numeric storage unit, depending on the default or explicit length specification for the constant, variable, or function. Table 5-1 provides the value ranges for integer data.

5 . 1 . 1 . 1 Integer Constants

The forms of an unnamed integer constant are as follows:

[sign] dig/et [dig/et]. ..

or

[ sign] I dig/et [dig/et] ... base where

sign dig/et base

is the optional plus (

+ )

or minus ( - ) sign.

is one of the 10 digits (0 through 9) or one of six letters (A through F).

is a base specifier that is one of the letters D, B, 0, Q, or H.

The base specifier indicates to the compiler what base the integer constant has. The letter D indicates a decimal number, B indicates a binary number, 0 or Q indicates an octal number, and H indicates a hexadecimal number.

If the base specifier is D, indicating a decimal number, each diglet must be one of the digits 0 through 9. By default, an integer without a base specifier integer is a decimal number.

If the base specifier is B, indicating a binary number, each diglet must be one of the digits 0 or 1.

If the base specifier is either 0 or Q, indicating an octal number, each diglet must be one of the digits 0 through 7.

If the base specifier is H, indicating a hexadecimal number, each diglet must be one of the digits 0 through 9 and the letters A through F. The first diglet must be one of the digits 0 through 9.

Fortran-86 gives a storage length equivalent to INTEGER *4 to the results of some integer constant expressions. An integer constant in a constant list of a DATA state-ment is given a length that matches the length of the corresponding data item. Other integer constants will be allocated to the smallest unit capable of holding their value, up to a maximum of four bytes. An exception to this rule occurs when an integer constant is used as an actual argument. In this case, the constant is assigned the default length (see Section 11.4.19, Storage Control).

Table 5-1. Value Ranges of INTEGER Data

Type and Length Value

INTEGER*1 -128 TO +127

INTEGER*2 -32,768 TO +32,767

INTEGER*4 -2,147,483,648 TO +2,147,483,647

Fortran-86

Fortran-86 Data and Specification Statements

A value that exceeds the range of presentable values for the particular type of data is undefined.

5. 1 .1 .2 INTEGER Type Statement

An INTEGER type statement declares names to be of type INTEGER. Its syntax is as follows:

The length specification immediately following the keyword INTEGER applies to each item in the statement not having its own length specification. A length specifi-cation immediately following an item is for that item only. For an array, the length applies to each array element. If no length is specified, the compiler assigns a length (see Sections 5.2, "IMPLICIT Statement" and 11.4.19, "STORAGE Control").

5. 1.2 Floating-Point: Data

An item of floating-point data represents a processor approximation to the value of a floating-point number. Floating-point data values can pe positive, negative, or zero.

The internal representation, the precision, and the range of floating-point values conforms to the floating-point conventions established by the IEEE Proposed Standard for Binary Floating-Point Arithmetic, Draft 8.0. For more information on

floating-point arithmetic. see the iAPX 86,88 User's Manual, order number 210201.

Fortran-86 supports the following types of floating-point data: REAL, DOUBLE PRECISION, TEMPREAL, COMPLEX, and COMPLEX*16. REAL data is stored in one or two four-byte numeric storage units in a sequence depending on the explicit or implicit length specification. DOUBLE PRECISION data is stored in two four-byte numeric storage units and TEMPREAL data in 10 four-bytes. COMPLEX data is stored in two or four four-byte storage units .. The first half stores the real part and the second half stores th(~ imaginary part.

Note that the internal representation of the REAL *8 data type is the same as that of the DOUBLE PRECISION data type.

5-3

Data and Specification Statements

The compiler interprets a floating-point constant as a decimal number.

There are three floating-point exponent forms that correspond to the floating-point data types. The syntax is as follows:

The internal representation of the REAL*8 data type is the same as that of DOUBLE PRECISION. Therefore, you must write REAL *8 constants with the D exponent.

The compiler will allocate any constant with the E exponent only one four-byte numeric storage unit. The exponential form of COMPLEX data is based on its component elements. A complex constant is represented by an ordered pair of REAL, INTEGER, or DOUBLE PRECISION constants, separated by a comma, enclosed in parenthesis.

Table 5-2 shows the approximate ranges for floating-point data.

5 . 1 .2 . 2 REAL Type Statement

A REAL type statement declares names to be of type REAL. Its syntax is as follows:

REA L [* len]name[ I name] ...

Table 5-2. Value Ranges for Floating-Point Data

Type Value

REAL I 1.2*10**( - 38) I TO 13.4*1 0**{38) I DOUBLE PRECISION I 3.4*10**( - 308) I TO I 1.8*10**(308) I TEMPREAL 13.4*10**(-4932) I TO 11.2*10**(4932) I

COMPLEX *See note

Fortran-86 Data and Specification Statements

where len name

where var

array array ( d) len

is one of the numbers 4 or 8.

has the following form:

v8lr[

*

len]

or

array [ (d)][

*

len]

is the name of a real constant, variable, function, or dummy procedure.

is an array name.

is an array declarator (see Section 5.4.1, "DIMEN-SION Statement").

is the length in bytes of the real variable or each real array element. The value len must be 4 or 8.

The length specification immediately following the keyword REAL applies to each item in the statement not having its own length specification. A length specification immediately following an item is for that item only. For an array, the length applies to each array element. If no length is specified, the compiler assumes the default length of four bytes, or the default length specified by the IMPLICIT statement (see Section 5.2).

5.1.2.3 DOUBLE PRECISION Type Statement

The DOUBLE PRECISION type statement declares names to be of type DOUBLE PRECISION. Its syntax is as follows:

DO U B L E PRE CIS ION name [ I name] ...

where

name is a constant name, variable name, function name, dummy procedure name, array name, or array declarator (see Section 5.4.1, "DIMENSION Statement"). The compiler assigns a length of two four-byte numeric storage units to each name.

5 . 1 .2 .4 TElVlPREAIJ Type Statement

The TEMPREAL type statement declares names to be of type TEMPREAL. Its syntax is as follows:

T E M PRE A L name [ I name] ...

where

name is a constant name, variable name, function name, dummy procedure name, array name, or array declarator (see Section 5.4.1, "DIMENSION Statement"). The compiler assigns a length of one 10-byte numeric storage unit to each name.

5-5

Data and Specification Statements

5-6

5.1.2.5 COMPLEX and COMPLEX*16 Type Statement

The COMPLEX and COMPLEX*16 type statement declares names to be of type COMPLEX, and has the following syntax:

COM P LEX [*Ien] J name [*Ien] J name [* len] J . . .

where name

where v a a(d) len

5. 1.3 Logical Data

is one of the forms:

v [* len]

or a (d) [* len]

represents a variable name, function name, or dummy procedure.

is an array name.

is an array declarator.

is the storage unit length. Len may be 8 or 16 for complex data. Len may also be an integer constant expression that evaluates to one of the above values (8 or 16), enclosed in parenthesis. By default, the compiler assigns two or four four-byte storage units to each name.

Logical data can assume only the values true or false. Logical data may have one, two, or four-byte numeric storage units, depending on the explicit length specification or the implicit length ror a LOGICAL variable or function (see Sections 5.2,

"IMPLICIT Statement" and 1l.4.19, "STORAGE Control"). Note that only the first byte of a two or four-byte data item is actually used.

5 . 1 .3 . 1 Logical Constants

Table 5-3 shows the form and acceptable values of logical constants.

5.1.3.2 LOGICAL Type Statement

The LOGICAL type statement declares names to be of type LOGICAL. Its syntax is as follows:

LOG I C A L[*len] name [ J name]. ..

Table 5-3. Value Ranges of LOGICAL Data

Type and Length Value

LOGICAL*1 .TRUE. or .FALSE.

LOGICAL*2 .TRUE. or .FALSE.

LOGICAL*4 .TRUE. or .FALSE.

Fortran-86

Fortran-86 Data and Specification Statements

where len name

where var array array ( d) len

is one of the numbers 1, 2, or 4.

has the following form:

v~!r[

*

len]

or

array [ (d)][

*

len]

is the name of a logical constant, variable, function, or dummy procedure.

is an array name.

is an array declarator (see Section 5.4.1, "DIMEN-SION Statement").

is the length in bytes of the logical variable or each logical array element. The value len must be 1, 2, or 4.

The length specification immediately following the keyword LOGICAL applies to each item in the statement not having its own length specification. A length specifi-cation immediately following an item applies to that item only. For an array, the length applies to each array element. If no length is specified, the compiler assumes the default length (see Sections 5.2, "IMPLICIT Statement", and 11.4.19,

"STORAGE Control").

5. 1.4 Character Oa1ta

Character data are strings of ASCII characters. Each character in the string has a character position numb(~red consecutively from left to right beginning with 1. The blank character is valid and significant in character data.

5 . 1 . 4 . 1 Character Constants

A character constant has the following form:

'CHARACTERS'

The apostrophe ( ') is not part of the character constant, but must be entered to delineate the constant. Two consecutive apostrophes (n) represent a single apostrophe within the string. For example:

IIMURPHYIlS LAW'

The length of a character string is the number of characters in the string. Each pair of consecutive apostrophes counts as one character. The length of a character constant must be greater than zero.

Dans le document FORTRAN-a6 USER'S GUIDE (Page 35-41)