char

Date:

10-12-2011

NAME

CHAR, ACHAR, ICHAR, IACHAR - Perform conversion and positioning functions

SYNOPSIS

INTEGER i, kind, iresult
CHARACTER c, cresult

cresult = CHAR([I=]i [,[KIND=]kind])

ACHAR([I=]i [,[KIND=]kind])

iresult = ICHAR([C=]c [,[KIND=]kind])

iresult = IACHAR ([C=]c [[,KIND=]kind])

IMPLEMENTATION

Cray Linux Environment (CLE)

STANDARDS

Fortran

DESCRIPTION

CHAR and ICHAR are inverse functions. CHAR converts an integer or Boolean argument to a character specified by the ASCII collating sequence. ICHAR converts a character argument to an integer based on the character position in the collating sequence. CHAR and ICHAR assign the appropriate type to Boolean arguments without shifting or manipulating the bit patterns they represent. For example, CHAR(i) returns the ith character in the collating sequence.

ACHAR returns the character in a specified position of the ASCII collating sequence.

IACHAR returns the position of a character in the ASCII collating sequence.

These intrinsic functions accept one or more of the following arguments:

i

For CHAR and ICHAR, must be of type integer or Boolean. If of type integer, i must be in the range 0 <= i <= 255.

  • For ACHAR, must be of type integer.

c

Must be of type character and of length 1.

kind

(CHAR and IACHAR only) The kind argument determines the kind type of the return result.

  • (IACHAR only) If this argument is not specified, the return result is of type default integer.

  • This argument must be a scalar integer initialization expression.

These are elemental functions. The names of these intrinsics cannot be passed as arguments.

RETURN VALUES

CHAR

CHAR returns a character of length one. If the kind parameter is present, the kind type parameter is that specified by kind. Otherwise the kind type parameter is that of the default character type. The result is the character in position i of the ASCII collating sequence associated with the specified kind type parameter.

ACHAR

ACHAR returns a character of length 1. If i has a value in the range 0 <= i <= 127, the result is the character in position i of the ASCII collating sequence. ACHAR (IACHAR (c)) has the value c for any character c capable of representation.

If the kind parameter is present, the kind type parameter is that specified by kind. Otherwise the kind type parameter is that of the default character type.

ICHAR

For ICHAR, the result is the position c in the collating sequence associated with the kind type parameter of c and is in the range 0 <= ICHAR(c) <= 255. For any characters C and D capable of being represented, C .LE. D is true if and only if ICHAR (C) .LE. ICHAR(D) is true and C .EQ. D is true if and only if ICHAR(C) .EQ. ICHAR(D) is true.

If the kind parameter is present, the kind type parameter is that specified by kind. Otherwise the kind type parameter is that of the default character type.

IACHAR

If c is in the collating sequence defined by the codes specified in ISO 646:1983 (International Reference Version), the result is the position of c in that sequence and satisfies the inequality 0 <= IACHAR (c) <= 127. The results are consistent with the LGE, LGT, LLE, and LLT lexical comparison functions. For example, if LLE(C,D) is true, IACHAR(C) .LE. IACHAR(D) is true when C and D are any two ASCII characters.

If the kind parameter is present, the kind type parameter is that specified by kind. Otherwise the kind type parameter is that of the default character type.

EXAMPLES

IACHAR(‘X’) yields the value 88.

ACHAR(88) yields ‘X’.