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

DECODE (extension)

» 

Technical documentation

Complete book in PDF
» Feedback
Content starts here

 » Table of Contents

 » Glossary

 » Index

Inputs formatted data from internal storage.

Syntax

DECODE (count, format, unit, io-specifier-list) [in-list]
count

is an integer expression that specifies the number of characters (bytes) to translate from character format to internal (binary) format. cnt must precede format.

format

specifies the format specification for formatting the data. format can be one of the following:

  • The label of a FORMAT statement containing the format specification.

  • An integer variable that has been assigned the label of a FORMAT statement.

  • An embedded format specification.

format must be the second of the parenthesized items, immediately following count. Note that the keyword FMT= is not used.

unit

is the internal storage designator. It must be a scalar variable or array name. Assumed-size and adjustable-size arrays are not permitted. Note that char-var-name is not a unit number and that the keyword UNIT= is not used.

unit must be the third of the parenthesized items, immediately following format.

io-specifier-list

is a comma-separated list of I/O specifiers. Note that the unit and format specifiers are required; the other I/O specifiers are optional. The following I/O specifiers can appear in io-specifier-list:

ERR=stmt-label

specifies the label of the executable statement to which control passes if an error occurs during statement execution.

IOSTAT=integer-variable

returns the I/O status after the statement executes. If the statement successfully executes, integer-variable is set to zero. If an end-of-file record is encountered without an error condition, it is set to a negative integer. If an error occurs, integer-variable is set to a positive integer that indicates which error occurred.

in-list

is a comma-separated list of data items for input. The data items can include expressions and implied-DO lists.

Description

The DECODE statement is an HP extension that is provided for compatibility with other versions of Fortran. The internal-I/O capabilities of the standard READ statement provide similar functionality and should be used to ensure portability.

The DECODE statement translates formatted character data into its binary (internal) representation.

Examples

The following example program illustrates the DECODE statement:

PROGRAM decode_example
CHARACTER(LEN=20) :: buf
INTEGER i, j, k
buf = 'XX1234 45 -12XXXXXX'
DECODE (15,'(2X,3I4,1X)', buf) i, j, k
! The equivalent READ statement is:
! READ (buf, '(2X,3I4,1X)') i, j, k
PRINT *, i, j, k
END PROGRAM decode_example

When compiled and executed, this program produces the following output:

 1234 45 -12

Related statements

ENCODE and READ

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.