Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP Fortran Compiler for HP-UX: HP Fortran Programmer's Reference > Chapter 10 HP Fortran statements

TYPE (declaration)

» 

Technical documentation

Complete book in PDF
» Feedback
Content starts here

 » Table of Contents

 » Glossary

 » Index

Declares a variable of derived type.

Syntax

TYPE (type-name) [[, attrib-list] ::] entity-list
type-name

is the name of a previously defined derived type.

attrib-list

is a comma-separated list of one or more of the following attributes:

Table 10-53 Title not available (TYPE (declaration))

ALLOCATABLE

INTRINSIC

PRIVATE

DIMENSION

OPTIONAL

PUBLIC

EXTERNAL

PARAMETER

SAVE

INTENT

POINTER

TARGET

 

If attrib-list is present, it must be followed by the double colon. For information about individual attributes, see the corresponding statement in this chapter.

entity-list

is a list of entities, separated by commas. Each entity takes the form:

name [(array-spec)] [= initialization-expr]

where:

name

is the name of a variable or function

array-spec

is a comma-separated list of dimension bounds

initialization-expr

is a structure constructor

initialization-expr

is present

entity-list

must be preceded by the double colon.

Description

The TYPE declaration statement specifies the type and attributes of derived-type objects. A derived-type object may be an array, which may be deferred shape (pointer or allocatable), assumed shape (dummy argument), or assumed size (dummy argument).

Assignment is intrinsically defined for each derived type but may be redefined by the user. Operators appropriate to a derived type may be defined by procedures with the appropriate interfaces.

When a derived-type object is used as a procedure argument, the types of the associated actual and dummy arguments must be the same. For sequence derived types different physical type definitions may be used for the actual and dummy arguments, as long as both type definitions specify identical type names, components, and component order. For nonsequenced types the same physical type definition must be used, typically accessed via host or use association, for both the actual and dummy arguments.

Examples

! Weather is a simple derived type with two
! character components and two integer components.
TYPE Weather
CHARACTER(LEN=32) Place
INTEGER High_temp, Low_temp
CHARACTER(LEN=16) Conditions
END TYPE Weather

TYPE (Weather) July(num_ws, 31)
! A two-dimensional Weather array for July
July(:,:) % Low_temp = -40
! Initialize all low temps in July
TYPE Polar
! Polar is a derived type with two real components that cannot be
! directly accessed in Polar objects outside the module
PRIVATE
REAL rho, theta
END TYPE Polar

! Point is a derived type with three components, one of which is
! itself of derived type
TYPE Point
REAL x, y
TYPE (Polar) p
END TYPE Point

TYPE (Polar) r, q(500)
! Two variables of type Polar
TYPE (Point) a, b, t(100,100)
! Three variables of type Point
b = Point(0.,0.,Polar(0.,0.))
! Use of nested structure constructors.

Related statements

INTERFACE, PRIVATE, PUBLIC, SEQUENCE, and TYPE (definition)

Related concepts

For information about derived types, see “Derived types”.

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© Hewlett-Packard Development Company, L.P.