WRITE Statement

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

Syntax

Sequential

Formatted:

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

Formatted - List-Directed:

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

Formatted - Namelist:

WRITE (eunit, nml-group [, asynchronous] [, id] [, pos] [, iostat] [, err])

Unformatted:

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

Direct-Access

Formatted:

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

Unformatted:

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

Internal

WRITE (iunit, format [, iostat] [ , err]) [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'.

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.

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.

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. Optionally 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.

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

See Also