-
[ Pobierz całość w formacie PDF ]
Rules for Data Typing
The name determines the type; that is, the name of a datum or function
determines its data type, explicitly or implicitly, according to the following
rules of data typing;
" A symbolic name of a constant, variable, array, or function has only one data
type for each program unit, except for generic functions.
" If you explicitly list a name in a type statement, then that determines the
data type.
" If you do not explicitly list a name in a type statement, then the first letter of
the name determines the data type implicitly.
" The default implicit typing rule is that if the first letter of the name is I, J,
K, L, M, or N, then the data type is integer, otherwise it is real.
" You can change the default-implied types by using the IMPLICIT
statement, even to the extent of turning off all implicit typing with the
IMPLICIT NONE statement. You can also turn off all implicit typing by
specifying the u compiler flag on the command line; this is equivalent to
beginning each program unit with the IMPLICIT NONE statement.
Array Elements
An array element has the same type as the array name.
Functions
Each intrinsic function has a specified type. An intrinsic function does not
require an explicit type statement, but that is allowed. A generic function does
not have a predetermined type; the type is determined by the type of the
arguments, as shown in Chapter , Intrinsic Functions.
14 FORTRAN 77 Reference Manual
2
An external function can have its type specified in any of the following ways:
" Explicitly by putting its name in a type statement
" Explicitly in its FUNCTION statement, by preceding the word FUNCTION
with the name of a data type
" Implicitly by its name, as with variables
Example: Explicitly by putting its name in a type statement:
FUNCTION F ( X )
INTEGER F, X
F = X + 1
RETURN
END
Example: Explicitly in its FUNCTION statement:
INTEGER FUNCTION F ( X )
INTEGER X
F = X + 1
RETURN
END
Example: Implicitly by its name, as with variables:
FUNCTION NXT ( X )
INTEGER X
NXT = X + 1
RETURN
END
Implicit typing can affect the type of a function, either by default implicit
typing or by an IMPLICIT statement. You must make the data type of the
function be the same within the function subprogram as it is in the calling
program unit. FORTRAN 77 does no type checking between program units.
Data Types and Data Items 15
2
Properties of Data Types
This section describes the data types, what each is for, the way storage is
allocated for each of them, and the alignment of the different types. Storage
and alignment are always given in bytes. Values that can fit into a single byte
are byte-aligned.
BYTE
The BYTE data type provides a data type that uses only one byte of storage. It
is a logical data type, and has the synonym, LOGICAL*1.
A variable of type BYTE can hold any of the following:
" One character
" An integer between -128 and 127
" The logical values, .TRUE. or .FALSE.
If it is interpreted as a logical value, a value of 0 represents.FALSE., and any
other value is interpreted as .TRUE.
f77 allows the BYTE type as an array index, just as it allows the REAL type,
but it does not allow BYTE as a DO loop index (where it allows only INTEGER,
REAL, and DOUBLE PRECISION). Wherever FORTRAN 77 makes an explicit
check for INTEGER, it does not allow BYTE.
Examples:
BYTE Bit3 / 8 /, C1 / 'W' /,
& Counter / 0 /, Switch / .FALSE. /
A BYTE item occupies 1 byte of storage, and is aligned on 1-byte boundaries.
CHARACTER
The character data type, CHARACTER, which has the synonym, CHARACTER*1,
holds one character.
The character is enclosed in apostrophes (') or quotes ("). Allowing quotes
(") is nonstandard; if you compile with the xl option, quotes mean something
else, and you must use apostrophes to enclose a string.
16 FORTRAN 77 Reference Manual
2
The data of type CHARACTER is always unsigned.
A CHARACTER item occupies 1 byte (8 bits) of storage.
A CHARACTER item is aligned on 1-byte boundaries.
CHARACTER*n
The character string data type,CHARACTER*n, where n> 0, holds a string of n
characters.
A CHARACTER*n data type occupies n bytes of storage.
A CHARACTER*n variable is aligned on 1-byte boundaries.
Every character string constant is aligned on 2-byte boundaries. If it does not
appear in a DATA statement, it is followed by a null character to ease
communication with C routines.
COMPLEX
A complex datum is an approximation of a complex number. The complex data
type, COMPLEX, which usually has the synonym COMPLEX*8, is a pair of
REAL*4 values that represent a complex number. The first element represents
the real part and the second represents the imaginary part.
The usual default size for a COMPLEX item (no size specified) is 8. If the r8
compiler option is set, then the default size is 16; otherwise, it is 8.
COMPLEX is aligned on 4-byte boundaries, except if compiled on a Sun-4 or
SPARC computer with the f option, in which case it is aligned on 8-byte
boundaries.
COMPLEX*8
The complex data type COMPLEX*8 is a synonym for COMPLEX, except that it
always has a size of 8 bytes, independent of any compiler options.
Data Types and Data Items 17
2
COMPLEX*16 (Double Complex)
The complex data type COMPLEX*16 is a synonym for DOUBLE COMPLEX,
except that it always has a size of 16 bytes, independent of any compiler
options.
COMPLEX*32(Quad Complex)
(SPARC only) The complex data type COMPLEX*32 is a quadruple-precision
complex. It is a pair of REAL*16 elements, where each has a sign bit, a 15-bit
exponent, and a 112-bit fraction. These REAL*16 elements in f77 conform to
the IEEE standard.
The size for COMPLEX*32 is 32 bytes.
COMPLEX*32 is aligned on 4-byte boundaries, except if compiled on a Sun-4 or
SPARC computer with the f option, in which case it is aligned on 8-byte
boundaries.
DOUBLE COMPLEX
The complex data type, DOUBLE COMPLEX, which usually has the synonym,
COMPLEX*16, is a pair ofDOUBLEPRECISION (REAL*8) values that represents [ Pobierz całość w formacie PDF ] - zanotowane.pl
- doc.pisz.pl
- pdf.pisz.pl
- matkadziecka.xlx.pl