• Aucun résultat trouvé

CHARACTER TYPE

Dans le document CRAY® COMPUTER SYSTEMS (Page 108-113)

DATA TYPES 3

3.7 CHARACTER TYPE

A character value or character string consists of one or more characters, as listed in appendix A. See 5.2 concerning character expressions and character assignment statements. Machine representation is shown in G.5.

A character constant is written as a sequence of characters preceded and followed by a delimiter, which can be an apostrophe or quotation mark.

The delimiter can appear as a character within the string if it appears twice in succession; the double character is interpreted as a single character. Blanks in a character string are significant. Examples:

• 'ABC' or "ABC" represents ABC.

, , , , or .. , .. represents'

,

....

, represents "".

Each character within a string has a position that is numbered ordinally from the first character. These positions are used in specifying

character substrings (see 3.7.2).

The length of a character constant is the number of characters between its delimiters (from 1 to 1316), with each pair of consecutive delimiters counted as a single character.

A variable or user-specified function of type character is declared with its length by the CHARACTER type statement. The bit length of a character dummy argument must be less than or equal to the length of the

corresponding actual argument (see 3.7.3). A character value must have at least 1 character, and, unless further restricted by machine memory, fewer than 8,388,608 (223) characters on the CRAY-2 system or fewer than

2,147,483,648 (2 31 ) characters on other Cray systems.

When all characters of a character entity become defined, the character entity becomes defined.

The ANSI Fortran Standard does not provide for the use of quotation marks as delimiters, and does not specify a maximum length for a character value.

3.7.1 CHARACTER TYPE STATEMENT

The CHARACTER statement declares a symbolic name to be of type character and shows the length of each character entity declared.

CHARACTER [*len[,]]name[*len][,name[*len]] ..•

len

name

Length specifier (number of characters): an unsigned, nonzero integer constant or a positive, nonzero integer constant expression enclosed in parentheses. len can

follow one name or can follow the word CHARACTER to apply to all names lacking length specifiers. If len does not

follow CHARACTER, it defaults to 1. len must be less than 223 on CRAY-2 systems and 231 on other Cray systems. It can also be in the form (*); see 3.7.1.1.

Variable name, symbolic name of a constant, function name, dummy procedure name, array name, or array declarator (see 4.3.5).

Examples:

(1)

(2)

CHARACTER*5 W*2,X,Y*7,Z

The above declares character variables X and Z of length 5, W of length 2, and Y of length 7.

CHARACTER ARR(3,5)*7,X

The above declares a 3-by-5 array ARR, each of whose elements contains seven characters, and character variable X of length 1.

3.7.1.1 Asterisk specification

len can be specified as (*) if name is the name of an external function, dummy argument, or character constant. The asterisk specification is treated as follows:

• If name is the name of a FUNCTION or an ENTRY statement in the same subprogram, the length is obtained from the calling program unit. See 3.7.1.2.

• If name is a dummy argument, the dummy argument assumes the length of the associated actual argument (see 3.7.3 concerning character ·arguments).

• If name is a character constant with a symbolic name, the constant will assume the length of its corresponding constant expression defined later in a PARAMETER statement.

Example:

CHARACTER DUMARG1*(*)

This statement declares a dummy argument with the asterisk length specification.

3.7.1.2 Character function declaration

When you use a character function, the function reference and function value must agree not only in type (see 2.4.1.1) but also in length. Use CHARACTER*(*) in a function subprogram when the length of the subprogram's result variable is to be determined by the length of the function

refere.nce in the calling program unit. The length of a dummy argument can be declared in the same manner, so that it has the same length as the associated actual argument.

Example:

In the calling program unit:

CHARACTER*15 LOWRCASE, UPTITLE, TITLE Fnct reference declared TITLE

=

LOWRCASE (UPTITLE)

In the called function subprogram LOWRCASE:

• The length of result value LOWRCASE can be declared in the following ways:

CHARACTER*(*) FUNCTION LOWRCASE (STRING) FUNCTION LOWRCASE(STRING)

CHARACTER*(*) LOWRCASE

CHARACTER*15 FUNCTION LOWRCASE (STRING) FUNCTION LOWRCASE(STRING)

CHARACTER*15 LOWRCASE

I

• In each case just shown, dummy variable STRING can be declared within the subprogram in the following ways:

CHARACTER*(*) STRING CHARACTER*15 STRING

If a returned character value is longer than the function reference, the rightmost characters are truncated. If the returned value is shorter than the reference, the value is left-justified and blank-filled.

3.7.2 CHARACTER SUBSTRINGS

A character substring consists of one or more contiguous characters within a character variable or character array element (see 4.3 and 4.3.5). A substring name takes the following form:

cvname ([first]: [last])

cvname Name of a character variable, character array element, or character array section. See the restriction in the following paragraph.

([first]:[last])

Substring designator. first and last are integer

expressions designating the beginning and ending character positions of the substring. The minimum and default value of first is 1; the maximum and default value of last is the last position.

Examples:

Substring Designates Characters

STRINGA(6:9) 6 through 9 of variable STRINGA STRINGB(4: ) 4 through end of variable STRINGB

STRINGC(2,6)(1:3) 1 though 3 of array element STRINGC(2,6) STRINGD(5,4)( :7) 1 through 7 of array element STRINGD(5,4)

Substring notation cannot be applied to an unqualified array name; that is, a substring designator must follow either an array element name or an array section name. Examples:

CHAR(5) refers to array element 5.

CHAR(1:5) refers to elements 1 through 5.

CHAR(1:5){1:10) refers to elements 1 through 5, positions 1-10.

3.7.3 ARGUMENTS OF TYPE CHARACTER

Actual arguments of type character can be character constants, the names of character variables or array elements, substrings, functions, or (in external procedures) character arrays. An actual argument associated with a character dummy argument must be of type character, with a length

exceeding or equaling that of the dummy argument.

The preceding requirement for type agreement does not apply to character constants; as actual arguments these can be associated not only with character variables or arrays, but also, interpreted as Hollerith

constants, with integer or real variables or arrays. See 5.2.3 and E.1.

If a function subprogram name is of type character, each entry name in the function subprogram must be of type character; the function name and all entry names must have the same declared length, whether it is an integer or (*), denoting adjustable length.

If a dummy argument of type character is an array name, the above restriction on length is for the entire array and not for each array element. The length of a dummy array element can differ from the length of an associated actual array, element, or element substring; but the dummy array must not extend beyond the end of the associated actual array.

If length len of a dummy argument of type character is less than the length of an associated actual argument, the leftmost len characters of the actual argument are associated with the dummy argument; that is, the rightmost characters are not part of the dummy argument.

When an actual argument is a character substring, the argument's length is the substring's length. Substring expressions in a substring name are evaluated immediately preceding argument association; the expression values remain constant as long as argument association continues.

If an actual argument is the concatenation of two or more operands, the argument's length is the sum of the operands' lengths. A character dummy argument whose length is specified as (*) must not appear as an operand for concatenation (see 5.2), except in a character assignment statement.

Dans le document CRAY® COMPUTER SYSTEMS (Page 108-113)