 |
» |
|
|
 |
The
general form of a type declaration statement is : type-spec [[ ,attribute-spec] ... :: ] entity-list |
DOUBLE PRECISION[kind-selector] CHARACTER
[char-selector] DOUBLE COMPLEX
(HP extension)
BYTE
is equivalent to INTEGER (KIND=1).
DOUBLE PRECISION
is equivalent to REAL (KIND=8),
and DOUBLE COMPLEX
is equivalent to COMPLEX (KIND=8),
except when the +autodbl
option is invoked. When +autodbl
is used, entities declared as DOUBLE PRECISION
will be doubled in size, but entities declared with REAL (KIND=8)will
remain as declared. - kind-selector
is ([KIND=]scalar-int-init-expr) |
- scalar-int-init-expr
is a scalar integer initialization expression that
must evaluate to one of the kind parameters available (see Table 3-1 “ Types and kind parameters ”). - char-selector
see CHARACTER
in Chapter 10 for details. - type-name
is the name of a derived type. - attribute-spec
is one or more compatible items from the following: Chapter 10 contains a matrix of attribute compatibility.
- access-spec
is one of : - array-spec
is a list of array bounds. Chapter 4 describes
the formats. - intent-spec
is one of : - entity
is one of: variable-name [(array-spec)] [* character-length] |
[= initialization-expression] |
function-name[(array-spec )] [* character-length] |
Note that when there is an initialization-expression
in the entity there must also be a ::
separator in the statement. Examples of type declarations |  |
Below are examples of type declaration statements,
some of which include data initialization components. ! Default, KIND=4, integers i j k. |
! Using optional separator. |
INTEGER(KIND=8) :: i=2**40 |
! An 8-byte initialized integer. |
INTEGER(8),DIMENSION(10) :: i |
! 10 element array of 8-byte integers. |
REAL, DIMENSION(2,2):: a = & |
RESHAPE((/1.,2.,3.,4./),(/2,2/)) |
! Using an array constructor for initialization. |
COMPLEX z=(1.0,2.0) ! FAULTY |
! Syntax error - no :: present. |
! One character (default length). |
! A 10-byte character string. |
CHARACTER(*),PARAMETER :: title='Ftn 90 MANUAL' |
! Length can be * for a named constant. |
! title is a 13-byte character string. |
! If the statement is in a subprogram, |
! n must be known at entry, otherwise |
! c assumes the length of the actual argument. |
TYPE(node):: list_element |
! A single entity, of derived type node. |
TYPE(coord) :: origin = coord(0.0,0.0) |
! Declaration and initialization of a |
Alternative form of intrinsic type spec declarationAs an extension, HP Fortran 90 allows, for
noncharacter types, the type-spec to
be given in the form: where type is an
intrinsic type excluding CHARACTER,
and length is the number of bytes of
storage required, as in Table 3-1 “ Types and kind parameters ”.
Alternatively, *length
may be placed after the entity name. If the entity is an array with
an array-spec following it, *length
may also be positioned after the array-spec. Example are all equivalent to the following preferred notation: REAL(8), DIMENSION(10) :: r8 |
Except for COMPLEX, length
is the same as the equivalent kind parameter; for COMPLEX,the
kind parameter is the kind parameter of the real or imaginary part
and so: COMPLEX*8
is equivalent to COMPLEX(KIND=4). COMPLEX*16 is
equivalent to COMPLEX(KIND=8). Alternative form of initialization within declarationHP Fortran 90
permits the use of slashes delimiting the data values rather than
the equal sign introducing the data item, although it is recommended
that this format is not used. The :: separator
must not be used and array constructors and structure constructors
cannot be used. Arrays may be initialized by defining a list of
values that will be sequence associated with the elements of the
array (the DATA
statement, which permits the use of implied-DO
loops may be more appropriate). The following examples use the slash form of initialization: REAL a(2,2)/1.1,2.1,1.2,2.2/ ! a(i,j)=i.j |
HP Fortran 90 provides
compile-line options that increase the default sizes of integer,
logical, real, and complex items. The +autodbl
and +autodbl4
options are described in Chapter 13. Intrinsic inquiry functions |  |
Two intrinsic functions, SELECTED_INT_KIND
and SELECTED_REAL_KIND,
are provided to determine the most appropriate kind parameter to
use for a given range and precision. These functions can be used
to significantly enhance the portability of programs. The value
of the kind parameter can be set to the result returned by one of
these functions. Full descriptions of the intrinsic functions are
given in Chapter 11. SELECTED_INT_KIND
has one argument which specifies the range required. For example: PARAMETER(intkind=SELECTED_INT_KIND(11)) |
will set the parameter intkind
to a value of 8, as the function will return the kind parameter
with the smallest storage requirement that can contain integers
with a magnitude of 1011. Integer variables
can then be declared using the value of intkind
thus: INTEGER(KIND=intkind) :: i, j, k |
SELECTED_REAL_KIND
has two arguments corresponding to the range and precision required.
For example: PARAMETER(rlkind=SELECTED_REAL_KIND(P=10,R=99)) |
returns a value of 8, supporting at least 10 digits of precision
for values with magnitude of at least 1099.
Declaring all REAL
entities with REAL(rlkind)
enables easy modification if it becomes necessary to change the
range or precision. Attributes |  |
The attributes that
may be included in a type declaration are individually described
in Chapter 10, with further references from there to appropriate
sections of the manual. A one-line summary of the purpose of each
attribute is given here. - ALLOCATABLE
Storage for the array is to be explicitly allocated
during execution. - DIMENSION(array-spec)
Declares an array. - EXTERNAL
Defines a subprogram or block data to be in another
program unit. - INTENT(intent-spec)
Defines the mode of use of a dummy argument. - INTRINSIC
Allows the use of a specific intrinsic name as an
actual argument. - OPTIONAL
Declares the presence of an actual argument as optional. - PARAMETER
Defines named constants. - POINTER
Declares the entity to be a pointer. - PRIVATE
Inhibits visibility outside a module. - PUBLIC
Provides visibility outside a module. - SAVE
Ensures the entity retains its value between calls
of a procedure. - TARGET
Enables the entity to be the target of a pointer.
All the above attributes can also be specified by using separate
statements, although an attribute may not be specified more than
once for an entity. Note that in HP Fortran 90 there are two
POINTER statements
with differing syntax. One supports the standard Fortran 90
definition and the other supports Cray-style pointers. The following additional attributes are HP Fortran 90
extensions and can only be specified using separate statements: - AUTOMATIC
Entity does not retain its value between procedure
calls. - STATIC
Entity retains its value between procedure calls. - VOLATILE
Provides data sharing between asynchronous processes.
An attribute compatibility table is given at the start of
Chapter 10. Further information and examples can be found in the relevant
entries in Chapter 10.
|