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

DATA

» 

Technical documentation

Complete book in PDF
» Feedback
Content starts here

 » Table of Contents

 » Glossary

 » Index

Initializes program variables.

Syntax

DATA var-list1 / val-list1 / [[,]var-list2 / val-list2 /]...
var-list

is a comma-separated list of entities, including the following:

  • A variable name

  • An array name

  • An array triplet section; for example:

    points(1:10:2)
  • An array element reference; for example:

    scores(0)
  • A substring name; for example:

    name(1:10)
  • An implied-DO loop; for example:

    ((matrix(i,j),i=0,5),j=5,10)
  • An object of a derived type

  • A component of a derived-type object

The following cannot appear in var-list:

  • Pointer-based variables

  • Records and record field references. However, you can initialize a record’s fields in the record’s structure definition. See RECORD (extension)”.

  • Automatic objects, including automatic character strings

  • Dummy arguments

  • Allocatable arrays: that is, arrays declared with a specified rank, but no specified bounds within each dimension

  • The result variable of a function

  • Objects made available by use or host association

  • Procedure names

val-list

is a list of constant values, separated by commas. Each constant in the list represents a value to be assigned to the corresponding variable in var-list. A constant value can be optionally repeated by preceding the constant with a repetition factor. The syntax of a repeated constant is:

r*val

where r is a positive integer specifying the number of times that val, the constant value, is to be specified.

Description

The DATA statement initializes variables local to a program unit before the program unit begins execution. Initialization occurs as follows:

The var-list is expanded to form a sequence of scalar variables, and the val-list is expanded to form a sequence of scalar constants. The number of items in each expanded sequence must be the same, and there must be a one-to-one correspondence between the items in the two expanded lists. The variables in the expanded sequence of var-list are initialized on the basis of the correspondence.

If var-list contains an array name, the expanded sequence of constants must contain a constant for every element in the array.

A zero-sized array or an implied-DO list with an iteration count of zero in var-list contributes no variables to the expanded sequence of variables. However, a zero-length character variable does contribute a variable to the list.

If a constant is of any numeric or logical type, the corresponding variable can be of any numeric type. If an object is of derived type, the corresponding constant must be of the same type. If the type of the constant does not agree with the type of the variable, type conversion is performed, as described in Table 4-5 “Conversion of variable=expression.

Variables can be initialized with binary, octal, or hexadecimal constants.

A variable or array element must not appear in a DATA statement more than once. If two variables share the same storage space through an EQUIVALENCE statement, only one can appear in a DATA statement. If a substring of a character variable or other array element appears in a DATA statement, no overlapping substring (including the entire variable or array element) can appear in any DATA statement.

The length of a character constant and the declared length of its corresponding character variable need not be the same. If the constant is shorter than the variable, blank characters are placed in the remaining positions. If the constant is longer than the variable, the constant is truncated from the right until it is the same length as the variable

If a subscripted array element appears in var-list, then the subscript must be a specification expression.

DATA statements can be interspersed among executable statements. However, they initialize prior to runtime and, therefore, cannot be used as executable assignment statements.

Fortran 90 extensions

A variable of type other than integer may be initialized with a binary, octal, or hexadecimal constant. The data type for a constant is determined from the type of the corresponding variable. The size (in bytes) of the variable determines how many digits of the octal or hexadecimal constant are used. If the constant lacks enough digits, the value is padded on the left with zeros. If the constant has too many digits, it is truncated on the left.

An integer, binary, octal, or hexadecimal constant can initialize a character variable of length one, as long as the value of the constant is in the range 0 to 255.

Examples

The following DATA statement initializes integer, logical, and character variables:

INTEGER i
LOGICAL done
CHARACTER(LEN=5) prompt
DATA i, done, prompt/10, .FALSE., 'Next?'/

The next DATA statement specifies a repetition factor of 3 to assign the value of 2 to all three elements of array i:

INTEGER, DIMENSION(3) :: i
DATA i/3*2/

The next DATA statement uses two nested implied-DO loops to assign the literal value X to each element of an array of 50 elements, k(10,5):

CHARACTER, DIMENSION(10,5) :: k
DATA ((k(i,j),i=1,10),j=1,5)/50*'X'/

Related statements

BYTE, CHARACTER, COMPLEX, DOUBLE COMPLEX, DOUBLE PRECISION, INTEGER, LOGICAL, and REAL

Related concepts

For related information, see the following:

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