Intel® Fortran Compiler Classic and Intel® Fortran Compiler Developer Guide and Reference

ID 767251
Date 9/08/2022
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

ENCODE

Statement: Translates data from internal (binary) form to character form. It is comparable to using internal files in formatted sequential WRITE statements.

ENCODE (c,f,b[, IOSTAT=i-var] [, ERR=label]) [io-list]

c

Is a scalar integer expression. It is the number of characters to be translated to internal form.

f

Is a format identifier. An error occurs if more than one record is specified.

b

Is a scalar or array reference. If b is an array reference, its elements are processed in the order of subscript progression.

b contains the characters to be translated to internal form.

i-var

Is a scalar integer variable that is defined as a positive integer if an error occurs and as zero if no error occurs (see I/O Status Specifier).

label

Is the label of an executable statement that receives control if an error occurs.

io-list

Is an I/O list. An I/O list is either an implied-DO list or a simple list of variables (except for assumed-size arrays). The list contains the data to be translated to character form.

The interaction between the format specifier and the I/O list is the same as for a formatted I/O statement.

The number of characters that the ENCODE statement can translate depends on the data type of b. For example, an INTEGER(2) array can contain two characters per element, so that the maximum number of characters is twice the number of elements in that array.

The maximum number of characters a character variable or character array element can contain is the length of the character variable or character array element.

The maximum number of characters a character array can contain is the length of each element multiplied by the number of elements.

Example

Consider the following:

     DIMENSION K(3)
     CHARACTER*12 A,B
     DATA A/'123456789012'/
     DECODE(12,100,A) K
100  FORMAT(3I4)
     ENCODE(12,100,B) K(3), K(2), K(1)

The DECODE statement stores the 12 characters into array K:

K(1) = 1234
K(2) = 5678
K(3) = 9012

The ENCODE statement translates the values K(3), K(2), and K(1) to character form and stores the characters in the character variable B.:

B = '901256781234'

See Also