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

WRITE Statement

Statement: Transfers output data to external sequential, direct-access, or internal records.

Sequential

Formatted:

WRITE (eunit, format [, advance] [, asynchronous] [, decimal] [, id] [, pos] [, round] [, sign] [, iostat] [ , err] [, [iomsg])[io-list]

Formatted - List-Directed:

WRITE (eunit, * [, asynchronous] [, decimal] [, delim] [, id] [, pos] [, round] [, sign] [, iostat] [, err] [, iomsg])[io-list]

Formatted - Namelist:

WRITE (eunit, nml-group [, asynchronous] [, decimal] [, delim] [, id] [, pos] [, round] [, sign] [, iostat] [, err] [, iomsg])

Unformatted:

WRITE (eunit [, asynchronous] [, id] [, pos] [, iostat] [, err] [, iomsg])[io-list]

Direct-Access

Formatted:

WRITE (eunit, format, rec [, asynchronous] [, decimal] [, delim] [, id] [, pos] [, round] [, sign] [, iostat] [, err] [, iomsg])[io-list]

Unformatted:

WRITE (eunit, rec [, asynchronous] [, id] [, pos] [, iostat] [ , err] [, iomsg])[io-list]

Internal

WRITE (iunit, format [, nml-group] [, iostat] [ , err] [, iomsg])[io-list]

Internal Namelist

WRITE (iunit, nml-group [, iostat] [ , err] [, iomsg])[io-list]

eunit

Is an external unit specifier, optionally prefaced by UNIT=. UNIT= is required if eunit is not the first specifier in the list.

format

Is a format specifier. It is optionally prefaced by FMT= if format is the second specifier in the list and the first specifier indicates a logical or internal unit specifier without the optional keyword UNIT=.

advance

Is an advance specifier (ADVANCE=c-expr). If the value of c-expr is 'YES', the statement uses advancing input; if the value is 'NO', the statement uses nonadvancing input. The default value is 'YES'.

asynchronous

Is an asynchronous specifier (ASYNCHRONOUS=i-expr). If the value of i-expr is 'YES', the statement uses asynchronous input; if the value is 'NO', the statement uses synchronous input. The default value is 'NO'.

decimal

Is a decimal mode specifier (DECIMAL=dmode) that evaluates to 'COMMA' or 'POINT'. The default value is 'POINT'.

delim

Is a delimiter specifier (DELIM=del). If the value of del is 'APOSTROPHE', apostrophes delimit character constants. If the value is 'QUOTE', quotes delimit character constants. If the value of del is 'NONE', character constants have no delimiters.

id

Is an id specifier (ID=id-var). If ASYNCHRONOUS='YES' is specified and the operation completes successfully, the id specifier becomes defined with an implementation-dependent value that can be specified in a future WAIT or INQUIRE statement to identify the particular data transfer operation. If an error occurs, the id specifier variable becomes undefined.

pos

Is a pos specifier (POS=p) that indicates a file position in file storage units in a stream file (ACCESS='STREAM'). It can only be specified on a file opened for stream access. If omitted, the stream I/O occurs starting at the next file position after the current file position.

round

Is a rounding specifier (ROUND=rmode) that determines the I/O rounding mode for this WRITE statement. If omitted, the rounding mode is unchanged. Possible values are UP, DOWN, ZERO, NEAREST, COMPATIBLE or PROCESSOR_DEFINED.

sign

Is a plus sign specifier (SIGN=sn). This controls whether optional plus characters appear in formatted numeric output.

iostat

Is the name of a variable to contain the completion status of the I/O operation. Optionally prefaced by IOSTAT=.

err

Are branch specifiers if an error (ERR=label) condition occurs.

iomsg

Is an I/O message specifier (IOMSG=msg-var).

io-list

Is an I/O list: the names of the variables, arrays, array elements, or character substrings from which or to which data will be transferred. Optionally an implied-DO list.

form

Is the nonkeyword form of a format specifier (no FMT=).

*

Is the format specifier indicating list-directed formatting. (It can also be specified as FMT= *.)

nml-group

Is the namelist group specification for namelist I/O. Optionally prefaced by NML=. NML= is required if nml-group is not the second I/O specifier. For more information, see Namelist Specifier.

rec

Is the cell number of a record to be accessed directly. It must be prefaced by REC=.

iunit

Is an internal unit specifier, optionally prefaced by UNIT=. UNIT= is required if iunit is not the first specifier in the list.

It must be a character variable. It must not be an array section with a vector subscript.

If an item in io-list is an expression that calls a function, that function must not execute an I/O statement or the EOF intrinsic function on the same external unit as eunit.

If you specify DECIMAL=, ROUND=, or SIGN= you must also specify FMT= or NML=.

If you specify ID=, you must also specify ASYNCHRONOUS='YES'.

Example
 ! write to file
 open(1,FILE='test.dat')
 write (1, '(A20)') namedef
 ! write with FORMAT statement
 WRITE (*, 10) (n, SQRT(FLOAT(n)), FLOAT(n)**(1.0/3.0), n = 1, 100)
 10 FORMAT (I5, F8.4, F8.5)

The following shows another example:

WRITE(6,'("Expected ",F12.6)') 2.0